1 Introduction

Binary images (or bitmaps) appear in various contexts, not only image processing. One can perceive a 2-dimensional bitmap image as a finite collection of squares (black pixels) aligned with respect to a fixed grid in , and indexed in both directions by the integers. A generalization to may be called an m-dimensional binary image. For example, a 3-dimensional binary image corresponds to a collection of voxels that represent a 3-dimensional object embedded in . This definition of an m-dimensional bitmap does not limit the area of applications to image processing alone. For example, a rectangular lattice in is often used for numerical simulations of PDEs or simply for approximating bounded sets in , e.g., an outer bound for a set of solutions to some equation.

Cohomology and homology groups are well known topological invariants that can be used to describe or classify the rough shape defined by an m-dimensional bitmap. There exist theory and software that allow one to efficiently computate these invariants. For example, the monograph [11] and the CHomP [2] and CAPD [3] software projects contain algorithms aimed specifically at efficient homology computation of m-dimensional bitmaps described in terms of full cubical sets and cubical complexes (see Sect. 2 for precise definitions of these terms).

Cohomological operations, such as the cup product, provide higher-order algebraic topological invariants than (co)homology groups alone. This is especially important for bitmaps of dimension higher than 3, where the natural human intuition may easily fail. One way to compute the operations effectively is to use an approach to homology computation known as “effective homology” [20, 21]. In this approach, instead of reducing the topological information to a minimal linear system that describes the degree of connectivity of the objects, one computes an algebraic skeleton, further called an algebraic-topological model (or an AT model for short), for representing these objects. In particular, an AT model contains homomorphisms that allow to instantly obtain representative cycles for each homology generator, and to efficiently compute, for an arbitrary cycle, the combination of the corresponding homology generators. We refer to [9] for an explanation of the philosophy behind this approach, and to [17] for an application in the context of cubical sets.

Steenrod squares [23] are cohomology operations which, roughly speaking, enhance the cohomology ring structure and thus help discriminating between topologically different spaces which still might have isomorphic cohomology rings. Steenrod squares, as well as any cohomology operations, are by definition natural: They are compatible with the induced homomorphisms, and thus can discriminate between non-homotopic maps. Moreover, due to the naturality, Steenrod squares can provide tests and sometimes even complete characterization for problems in homotopy theory. The primary example of such and also an important motivation for our work is the topological extension problem (for maps into a sphere): Can a given map \(A\rightarrow S^d\) to a sphere \(S^d\) be extended to a given super-complex X of A? Here the Steenrod squares yield stronger test than the one obtained by plain cohomology and this test is complete if \(\dim X\le d+2\). In fact, this has been the original motivation for Steenrod to introduce his squares, which has been a major breakthrough in homotopy theory of the end of the first half of the twentieth century.

We are interested in the extension problem mainly because another computational problem – called robust satisfiability – reduces to it [5]. In that problem, given a continuous function and a value \(r>0\), one has to decide whether every with \(\Vert g-f\Vert _\infty \le r\) has a root. In plain words, we ask for solvability of the system of equations \(f(x)=0\) under uncertainty about the function f quantified by the value of r. Robust satisfiability and the topological extension problem are essentially computationally equivalent [5]. In particular, theoretical complexity study of the extension problem [1] shows that robust satisfiability is decidable in polynomial time when \(\dim X\le 2n-3\) or \(n=1,2\), and undecidable when \(\dim X\ge 2n-2\) and n is odd. (In the remaining cases of n even and arbitrary dimension of X, the problem is decidable [25].) More practical point of view and an actual implementation is presented in [15] where the Steenrod squares are used in the context of cubical complexes.

Determining cohomological operations at the level of cochains allows one to use an AT model to compute them effectively. The idea is to take the cocycles corresponding to cohomology generators, apply the operation to them, and to determine the combination of the cohomology generators that defines the cohomology class represented by the resulting cocycle; see [8] for an in-depth description of this approach. In particular, the simplicial formula provided implicitly in the first Steenrod’s paper on the topic [23] (see also [7] for an alternative approach), computes the Steenrod squares at the level of representing simplicial cocycles. This yields an effective method for computing the Steenrod squares on the level of cohomology of simplicial complexes, if combined with the computation of an AT model. Unfortunately, decomposing a cubical set into a simplicial complex deleteriously affects the efficiency of such an approach. A direct cubical approach was proposed in [17] for the cup product in cohomology (see also [12]), and implemented in the ChainCon software package [16].

The purpose of our paper is to establish a formula for the Steenrod square operations directly at the level of cubical chains. We emphasize the fact that our result is not based upon the formula provided by Real [19] for the case of simplicial sets; rather, we develop a direct cubical formula, following Steenrod’s original approach [23]; the correctness of this formula follows from the axiomatic approach to Steenrod squares, as explained at the beginning of Sect. 3. An implementation of this formula is programmed in C++ and put within the ChainCon software framework [16], and serves the purpose of proof-of-concept and benchmarking.

2 Topological Preliminaries

Cubical Complexes. An (abstract) cubical complex X is a family of sets \(X=(X_0,X_1,\ldots )\) equipped with face operators

$$\begin{aligned} \partial _i^s:X_n\rightarrow X_{n-1}\text { for each } i \in \{1, \ldots , n\}\text { and } s\in \{+,-\} \end{aligned}$$

satisfying the relation

$$\begin{aligned} \partial _i^s\partial _j^t = \partial _j^t \partial _{i+1}^s \text { for }i\ge j\text { and }s,t\in \{+,-\}. \end{aligned}$$
(1)

The elements of each \(X_n\) are called n-cubes and the face operators \(\partial ^\pm _i\) can be thought of as an abstract counterpart of obtaining a facet of the cube \([-1,1]^n\) by fixing the ith coordinate to \(\pm 1\), that is,

$$\begin{aligned} \partial _i^\pm [-1,1]^n = [-1,1]^{i-1}\times \{\pm 1\}\times [-1,1]^{n-i}\,. \end{aligned}$$

The simplest example is indeed the cubical complex \(I^m\) where each set of n-cubes \(I^m_n\) consists of all n-faces of the geometric cube \([-1,1]^m\) and the face operators are defined in the obvious sense. An important example will be cubical complexes derived from cubical sets as explained below.

A cubical map \(f:X\rightarrow Y\) from a cubical complex X to a cubical complex Y is a family of maps \(f_n:X_n\rightarrow Y_n\) that commute with all the face operators.

Cubical Sets. We follow the terminology and notation based upon [11, 14].

Let m be a positive integer. An elementary cube is the cartesian product of m intervals of length 1 (the non-degenerate case) or 0 (the degenerate case) with integer coordinates; formally:

$$ [a_1,b_1] \times \cdots \times [a_m,b_m], $$

where , and either \(b_i = a_i + 1\), or \(a_i = b_i\) (and then \([a_i,b_i]\) denotes the singleton \(\{a_i\}\)). If all the intervals in this product are non-degenerate then the elementary cube is called a full cube.

A set is called a cubical set if it is a finite union of elementary cubes; Note that cubical sets are obviously compact ENRs. The cubical set A is called a full cubical set if it is a finite union of full cubes. For example, an m-dimensional binary image (or a bitmap) can be perceived as a full cubical set in for the purpose of topological analysis.

Since the face of an elementary cube is also an elementary cube, sets of elementary cubes yield a natural cubical complex structure. The homological properties of this cubical complex agree with the (singular) homology of the corresponding cubical set.

Cubical Chain Complexes. To each cubical complex X and an Abelian group G we assign a cubical chain complex

$$\begin{aligned} \ldots \mathop {\rightarrow }\limits ^{d_3}C_2(X;G)\mathop {\rightarrow }\limits ^{d_2} C_1(X;G) \mathop {\rightarrow }\limits ^{d_1} C_0(X;G), \end{aligned}$$

where each \(C_n(X;G)\) is the group of formal sums \(\sum _{\sigma \in X_n} g_\sigma \cdot \sigma \) with coefficients in G and each boundary operator \(d_n\) is the homomorphism defined by

$$\begin{aligned} d_n(g\cdot \sigma ) = \sum _{i=1}^n (-1)^i (g\cdot \partial _i^+\sigma - g\cdot \partial _i^- \sigma ). \end{aligned}$$

At Models. Let us recall the notion of an AT model, which helps us to compute Steenrod squares effectively at the cohomology level using the formula defined at the level of cochains.

A chain map between two chain complexes is a homomorphism that commutes with the boundary operator. A chain contraction from a chain complex \(C_*\) to another chain complex \(C'_*\) is a triple \((\pi , \iota , \phi )\) of chain maps \(\pi :C_* \rightarrow C'_*\) (projection), \(\iota :C'_* \rightarrow C_*\) (inclusion) and \(\phi :C_* \rightarrow C_{* + 1}\) (chain homotopy) that satisfy the following conditions: (a) \(\mathrm{{Id}}_{C} - \iota \pi = \partial \phi + \phi \partial \); (b) \(\pi \iota = \mathrm{{Id}}_{C'}\); (c) \(\pi \phi = 0\); (d) \(\phi \iota = 0\); (e) \(\phi \phi = 0\). See e.g. [4, §12] for the motivation of this definition, and [8, p. 86] for comments on the terminology and applications. Note that the existence of a chain contraction from \(C_*\) to \(C'_*\) implies the fact that the homology and cohomology modules of both chain complexes are isomorphic.

An algebraic topological model (introduced in [6]), or an AT model for short, of a cubical complex K, is a chain contraction from \(C_* (K)\) to some free chain complex \(M_*\) with null differential. Note that \(M_*\) is isomorphic to the homology module of K. In particular, an AT model of K exists if \(H_* (K)\) has no torsion. In what follows, we work with coefficients in , so this condition is satisfied.

We use an AT model for representing the homology of K in the following way. The image of each element of \(M_*\) by the inclusion \(\iota \) is a cycle that represents the corresponding homology class. Additionally, the image of each cycle in \(C_* (K)\) by the projection map \(\pi \) is the homology class that contains the cycle. In this way, the homomorphisms \(\iota \) and \(\pi \) are used to go back and forth between homology generators and the corresponding cycles in \(C_* (K)\).

3 The Cubical Formulas for the Steenrod Operations

We follow the general scheme of many standard textbooks and sources addressing Steenrod operations such as [10, 24], but the particular notation is very close to [18]. The (non-algorithmic) construction there is based on the existence of chain maps for \(k=0,1,\ldots \) satisfying the following: \(D_*^0\) is a diagonal approximationFootnote 1 and, all the chain maps \(D^k_*\) satisfy the relation

$$\begin{aligned} D^k_*-TD^k_* = (d\otimes d)_{} D^{k+1}_* + D^{k+1}_{*}d_{}, \end{aligned}$$
(2)

where is defined as follows: \(T(\sigma \otimes \tau )=\tau \otimes \sigma \). Each chain map \(D^k_*\) is called the k th higher diagonal approximation.

Definition 1

([18, pp. 186,187]). The Steenrod square is induced by the composition

where \(\varDelta (z):=z\otimes z\) is the diagonal map.

Our goal here is to give formulas for the chain maps \(D^k_*\) in the special case when X is a cubical complex – see Definition 2 and Theorem 3 below.

There is a subtle difference between our definition above and the definition provided in [18]: The chain maps \(D^k_*\) are defined in [18] for chain complexes with integral coefficients. Indeed, their existence can be proved in this stronger sense; however, for the definition of the Steenrod operations alone the “modulo 2” version is only relevant. The proof of [18, Theorem 3.60] gives a chain homotopy between any two choices of higher diagonal approximations (no matter whether over ). Thus the higher diagonal approximations over necessarily lead to the identical cohomology operations – Steenrod squares.

Definition 2

For given integers \(n,k\ge 0\), let us define the set

$$\mathcal F_n^k:=\{(A,B)\mid A,B\subseteq [n],A\cap B=\emptyset \text { and }|A|+|B| = n-k\}.$$

Let X be a cubical complex. We define the homomorphisms of degree k by the formula

$$ D^k_n(\sigma ):=\sum _{(A,B)\in \mathcal F_n^k}\partial ^{-*}_A\sigma \otimes \partial ^{*}_B\sigma \,, $$

where for \(A=\{a_1<a_2<\ldots <a_p\}\) and \(B=\{b_1<b_2<\ldots < b_q\}\) we define \(\partial ^{-*}_A=\partial ^{-s(a_1)}_{a_1}\ldots \partial ^{ -s(a_p)}_{a_p}\) and \(\partial ^*_B=\partial ^{s(b_1) }_{b_1} \ldots \partial ^{s (b_q)}_{b_q}\) where

$$ s(x)= (-1)^{|[x]\setminus (A\cup B)|}\,. $$

Theorem 3

The homomorphisms \(D^k_n\) defined above satisfy relation (2).

Proof

Over , relation (2) is equivalent to

$$\begin{aligned} D^k_n+TD^k_n + D^{k+1}_{n-1}d_n = (d\otimes d)_{n+k+1} D^{k+1}_n\,. \end{aligned}$$
(3)

The right-hand side of (3) evaluates on a given generator as follows (we will denote \(1\cdot \sigma \) simply by \(\sigma \)):

where the operator \(\partial _{B,j}^{*,s}\) is equal to \(\partial _B^{*}\) with \(\partial _j^s\) inserted at the correct position (that is, \(\partial _{B,j}^{*,s} = \partial _ {b1}^{s(b_1)}\ldots \partial _{b_r}^{s(b_r)}\partial _j^s \partial _{b_{r+1}}^{s( b_{r+1})} \ldots \partial _{b_q}^{s(b_q)}\) for \(b_r<j<b_{r+1}\) and \(s(x) = (-1)^{|[x]\setminus (A\cup B)|}\)) and similarly for \(\partial _{A,j}^{-*,s}\). This equality follows by applying relation (1). Each term of the sum above can be rewritten into one of the following forms according to whether the face operator \(\partial _j^\pm \) is present on both sides of the tensor product:

  1. 1.

    When the face operator \(\partial _j^\pm \) is present on both sides of the tensor product, each term can be rewritten in one of the two types according to whether the signs of the operators \(\partial _j^\pm \) on the left and on the right agree or not, explicitly

    $$ \partial _{A'}^{-*} \partial _j^{t} \sigma \otimes \partial _{B'}^* \partial _j^{-t}\sigma \text { and } \partial _{A'}^{-*} \partial _j^{t} \sigma \otimes \partial _{B'}^* \partial _j^{t}\sigma $$

    for unique \((A',B')\in \mathcal F_{n-1}^{k+1}\) and \(t\in \{+,-\}\) determined by AB, j and s. It is not difficult to see that for any fixed \(A',B',t\) and j, the term of the first type appears either twice (when \(t=s(j)\)) or never (when \(t\ne s(j)\)). In the second type, the term appears exactly once (either \(\partial _{A'}^{-*} \partial _j^{t}=\partial _A^*\) or \(\partial _{B'}^*\partial _j^t = \partial _B^*\) for some A and B).

  2. 2.

    When the face operator \(\partial _j^\pm \) is present on one side of the tensor product only, we set up the following labeling:

    • \(\partial _{A,j}^{-*,s}\sigma \otimes \partial _B^{*}\sigma \) will be called an \((A\cup \{j\},B,j,-)\)-term when \(s=s(j) = (-1)^{|[j]\setminus (A\cup B)|}\).

    • \(\partial _{A,j}^{-*,s}\sigma \otimes \partial _B^{*}\sigma \) will be called an \((A\cup \{j\},B,j,+)\)-term when \(s=-s(j)\).

    • \(\partial _A^{-*}\sigma \otimes \partial _{B, j}^{*,s}\sigma \) will be called an \((A,B\cup \{j\},j,+)\)-term when \(s=s(j)\).

    • \(\partial _A^{-*}\sigma \otimes \partial _{B, j}^{*,s}\sigma \) will be called an \((A,B\cup \{j\},j,-)\)-term when \(s=-s(j)\).

    It follows that for each \((A',B')\in \mathcal F_n^{k}\), each \(j\in A'\cup B'\), and each sign \(t\in \{+,-\}\), there is exactly one \((A',B',j,t) \)-term in the sum above. We define the following pairing on the set of all such \((A',B',j,t)\)-terms: We pair each \((A',B',j,+)\)-term with the \((A',B',j',-)\)-term for \(j'=\min \big ((A\cup B)\setminus [j]\big )\) when the minimum exists.Footnote 2 Note that the paired terms are equal. The unpaired

    • \((A',B',j,+)\)-terms for \(j=\max (A'\cup B')\) and

    • \((A', B',j,-)\)-terms for \(j=\min (A'\cup B')\) are equal to

    • \(\partial _{A'}^{-*}\sigma \otimes \partial _{B'}^*\sigma \) and

    • \(\partial _{A'}^{*}\sigma \otimes \partial _{B'}^{-*}\sigma \),

    respectively.

Summing up what has been said above, the right-hand side of (3) equals to

$$\sum _{(A',B')\in \mathcal F_n^k} \partial ^{-*}_{A'}\sigma \otimes \partial ^{*}_{B'}\sigma + \partial ^{*}_{A'}\sigma \otimes \partial ^{-*}_{B'}\sigma \ \ + \sum _{(A',B')\in \mathcal F_{n-1}^{k+1}}\sum _{\begin{array}{c} j\in [n]\\ t\in \{+,-\} \end{array}} \partial _{A'}^{-*} \partial _j^{t} \sigma \otimes \partial _ {B'}^*\partial _j^{t}\sigma \,,$$

which is exactly the left-hand side of (3).   \(\square \)

Corollary 4

Definition 2 yields an explicit cubical formula for the Steenrod squares as follows:

(4)

4 The Algorithm, Software, and Examples

Algorithm for Computing Steenrod Squares. In order to compute all the nontrivial Steenrod squares in a cubical complex K, we first compute an AT model of K, using the algorithm provided in [17]. The AT model consists of a finitely generated free chain complex \(M_*\) with null differential, and a chain contraction \((\pi , \iota , \phi )\) from \(C_* (K)\) to \(M_*\). In particular, \(M_*\) is represented by a finite collection \({\mathcal M}_*\) of its generators. In this algorithm, for a chain \(z \in C_n (K)\), its dual cochain is denoted as \(z^n\).

figure a

Software Implementation. The software publicly available at [16] under the GNU General Public License is written in the C++ programming language using the technique of generic programming. In particular, the type of cells in a cellular complex is a template parameter, so the same software applies to simplicial and cubical complexes alike, provided that the cell-specific operations (like the boundary) have been defined. In addition to a programming library that is accessible from within a program written in C++ and is the most efficient way of using this software, there are a few command-line programs provided that read definitions of cellular complexes saved in human-readable text files, and output the results in text format to the console. These programs thus constitute an easy to use interface to the main features of the software. Simplicial and cubical cells are defined, and several algorithms are implemented, including the computation of an AT model, the cohomology ring, and the Steenrod squares. The main program written especially for this paper is called ssqcub, and computes the Steenrod squares of a cubical complex. Additional programs that may be used for comparison and for gathering additional information, are: ssqsim (computation of Steenrod squares for simplicial complexes), ssqcubs (computation of Steenrod squares for cubical complexes using simplicial subdivision), cringcub (computation of the cohomology ring for cubical complexes), and cringsim (computation of the cohomology ring for simplicial complexes). We refer to the website [16] and instructions provided there for further information.

Approximations of Sample Manifolds. Given a finite set that roughly approximates a bounded set whose homological information we would like to demonstrate, we approximate it by means of a full cubical set A as follows. For each point \(x = (x_1, \ldots , x_n) \in X\), we take the point , where \(a_i := \lfloor x_i \rfloor \) is the largest integer that does not exceed \(x_i\), and is effectively computed by truncating the coordinates of x down to the nearest integers. Then we take the union of all the full cubes whose minimal vertices are given in this way. More precisely:

$$ A := \bigcup \left\{ \big [\lfloor x_1 \rfloor , \lfloor x_1 \rfloor +1\big ] \times \cdots \times \big [\lfloor x_n \rfloor , \lfloor x_n \rfloor + 1\big ] : x \in X\right\} . $$

In order to reduce a full cubical set A to a cubical set which has the same homological properties, we apply the reduction techniques introduced in [14], which include removal of full cubes at the boundary of the set, and then a sequence of free face collapses. The examples of full cubical sets and (general) cubical sets discussed in this section are available at [16], and were obtained as described above, with the application of the reductions. In particular, the inclusion \(A' \rightarrow A\) induces an isomorphism in (co)homology.

The parametrization given by \((\alpha , \beta ) \mapsto (R \cos \alpha + r \cos \alpha \cos \tfrac{\alpha }{2} \cos \beta , R \sin \alpha + r \sin \alpha \cos \tfrac{\alpha }{2} \cos \beta , r \sin \tfrac{\alpha }{2} \cos \beta , r \sin \beta )\), with \(R = 4\), \(r = 2\), and \(\alpha , \beta \in [0, 2 \pi ]\), was used for the Klein bottle embedded in , and the parametrizations provided in [13] were used for embedded in and for embedded in (the third coordinate in both original formulas was dropped).

Table 1. A list of sample cubical sets that approximate selected manifolds with nontrivial Steenrod squares.

Sample Computation of the Steenrod Squares. We consider three representative examples which exhibit nontrivial Steenrod squares, in addition to the obvious \(\mathrm{Sq}^0 \cong {\text {id}}\). A summary of these examples is gathered in Table 1. The cohomology over (in terms of Betti numbers) and the nontrivial cup products, as well as the nontrivial Steenrod squares are listed in Table 2.

Table 2. The nontrivial cup products and the nontrivial Steenrod squares. Cohomology generators are denoted by consecutive alphabetic letters for each dimension (e.g., a for dimension 0, e for dimension 4) with appended indices starting from 1 within each dimension separately.

Using Simplicial Subdivision. In the previous approach for the computation of the Steenrod squares of digital images [7, 8], one would have to first compute a simplicial subdivision of a cubical set, and then compute the simplicial Steenrod squares, e.g., using the efficient formulas provided in [7]. This approach is considerably less efficient than using the direct cubical formula, especially in higher dimensions, where it takes a considerable number of simplices to fill a full cube. For example, our approximation of Klein bottle consisting of 111 full cubes of dimension 4 (see Table 1) yields a simplicial complex with 27, 404 simplices, as opposed to the cubical complex containing 5, 724 cubical cells. The 38 full cubes of dimension 5 that approximate yield 76, 475 simplicial cells and 7, 113 cubical cells, respectively. Obviously, the high numbers of simplicial cells detrimentally affect the computation speed (which is not linear!), and the memory usage as well.

Computation for the Suspension. For each of the sample cubical sets, we construct a cubical counterpart of its suspension, as follows. Given a cubical set , let B be a contractible cubical set in such that \(A \subset B\). For example, if \([m_i, M_i]\) is the range of the i-th coordinate of all the points in A then the cartesian product \(\varPi _{i=1}^{m} [m_i, M_i]\) is a cubical set that contains A and is obviously contractible. Then we take

$$ S^c (A) := (A \times [0, 1]) \cup (B \times \{0, 1\}). $$

It is immediate to see that \(S^c (A)\) is homotopically equivalent to the suspension of A, defined as

$$ S (A) := (A \times [0, 1]) / \{(x_1,0) \sim (x_2,0) \text { and } (x_1,1) \sim (x_2,1) \text { for all } x_1, x_2 \in A\}. $$

As expected, computations show that the nontrivial Steenrod squares remain in the suspension, although are shifted by one dimension (see Table 3), but the nontrivial cup products disappear in the suspension (and are thus not shown in the table).

Table 3. Nontrivial Steenrod squares for suspensions. Cohomology generators are denoted by consecutive alphabetic letters for each dimension (e.g., a for dimension 0, e for dimension 4) with appended indices starting from 1 within each dimension separately.

Time Complexity. Provided that an AT model of a chain complex has been already computed, computing all the Steenrod squares involves the computation of the inclusion map on selected homology generators, applying the formulas for the Steenrod squares at the level of chains, and checking if specific homology generators appear in the projections of faces that appear in the formula. Let s denote the number of cells in the chain complex, let g be the number of homology generators. An upper bound for the number of how many times (4) is applied is at most \(O (g^2)\). Assume the dimension is fixed, and then (4) evaluates in constant time times the cost of checking the projections, which is at most O (g). Since the chains are not longer than O (s), the overall pessimistic time complexity of the computation of all the Steenrod squares is \(O (g^3 s^2)\). Note that the time complexity of computing an AT model is \(O (s^3)\), and in typical applications the numbers of homology generators are very small; therefore, the cost of computing Steenrod squares is neglibigle if computation of complete homological information of a cubical complex is taken into consideration.