The Cubical Cohomology Ring: An Algorithmic Approach

A cohomology ring algorithm in a dimension-independent framework of combinatorial cubical complexes is developed with the aim of applying it to the topological analysis of high-dimensional data. This approach is convenient in the cup-product computation and motivated, among others, by interpreting pixels or voxels in digital images as cubes. The S-complex theory and so called co-reductions are adopted to build a cohomology ring algorithm speeding up the algebraic computations.


Introduction
In the past two decades, homology and cohomology theory have gained vivid attention outside of the mathematics community prompted by modern applications in sciences and engineering.The development of a computational approach to these theories is motivated, among others, by problems in dynamical systems [18], material science [5,8], electromagnetism [9,14], geometric modeling [10], image understanding and digital image processing [1,3,12,16,22].Conversely, that development is enabled by progress in computer science.Although algebraic topology arose from applications and has been thought of as a computable tool since its early stage, practical implementations had to wait until the modern generation of powerful computers due to the complexity of the operations involved, especially in high-dimensional problems.
Until recently, progress has mainly been achieved in the computation of homology.The software libraries CHomP [4] and RedHom [24] provide systematic approach to computing homology of topological spaces in arbitrary dimension.There are also implementations of homology algorithms for some specialized tasks as, in particular, GAP [11] and Dionysus [19].The abundance of various homology algorithms and implementations is, at least in part, a consequence of the fact that the optimization techniques depend crucially on the type of input as well as the data structure chosen to represent it.Simplicial complexes constitute a common and historically well justified method to represent topological spaces.However, in many applications, in particular in rigorous numerics of dynamical systems and in all types of raster graphics a union of unit cubes in a cubical lattice provides the most natural way to represent sets.This leads to the concepts of a cubical set, a combinatorial cubical complex and cubical homology as introduced in [15].These concepts should not be confused neither with the singular cubical homology [17] nor with the notion of cubical set in the homotopy theory or algebra [2].The cubical set in the sense of [15] may look as a very restrictive one from the point of view of the general theory but it is sufficiently broad in the context of applications and, most importantly, its rigidness allows for bitmap representations which are extremely efficient due to the natural optimization of processors to perform operation on bitmaps.In this paper, we shall work in the framework of [15] but extending the material on cubical homology to the dual cochain groups.
Cohomology theory, not less important than homology from the point of view of applications, but intrinsically more difficult, had to wait longer for computer implementations.Whenever a mathematical model made it possible as, for example, in the case of orientable manifolds, duality has been used to avoid explicitly working with cohomology.However, among features distinguishing cohomology from homology is the cup product, which renders a ring structure on cohomology.The cup product is a difficult concept, which has been more challenging to make explicit enough for computer programs than homology or cohomology groups.Some significant applicationoriented work on computing the cohomology ring of simplicial complexes has been done by Real et al. [13].
The notion of the singular cubical homology and cohomology and a cubical cup product formula were first introduced in 1951 by Serre [25,Chap. 2].However, we wish to emphasize that this pioneering approach is far from the combinatorial and application-driven spirit of our work; for three main reasons: of all, singular cubes are defined as equivalence classes of all continuous functions from the standard cube [0, 1] d to a given topological space.Secondly, because Serre, in his original work, does not directly derive algebraic properties of the singular cubical cohomology ring by arguments within his theory: he only refers to the isomorphism between singular and simplicial (co)homology.Finally, because Serre's result on this topic is hidden as part of a highly theoretical work addressed to readers with a deep background in pure mathematics and beyond the reach of most of the computer engineering community for instance.This is why authors working on applications of cohomology to 3D digital images e.g.[12,13] in the framework of 3D cellular cubical complexes tend to derive the needed cubical formulas from the simplicial theory rather than from Serre's work.Our philosophy is based on the observation that the combinatorial cubical complexes presented in [15] are a more friendly framework than the simplicial or singular setting, to directly derive explicit formulas, such as, for instance, the cup product formula, and to implement them in dimension-independent algorithms.
Let us recall the general definition of the cup product used in the standard literature on homological algebra [23].

Definition 1.1
The cup product : H p (X) × H q (X) → H p+q (X) is defined on cohomology classes of cocycles z p and z q as follows: where [z p ] × [z q ] is the cohomology cross product and diag * is the homomorphism induced by the diagonal map diag : X → X × X given by diag(x) := (x, x).
An algorithm for cup product based on formula (1) would require an implementation of cross product and diag * homomorphism which is troublesome and would lead to an inefficient algorithm.The main goal of this paper is to provide an explicit formula for computing the cup product in the setting of cubical sets.As we will prove in Theorem 2.24 the computation of the cup product of two generating elementary cubes in dimension d reduces coordinate-wise to dimension one and the respective formula in dimension one, given by Theorem 2.20 is straightforward to implement.
Such an elementary and easy to implement formula is possible, because in the context of cubical sets the cochain cross product is simply the dual of the cubical product The concept of cross product is much easier and more natural in the context of cubical sets than for simplical or singular complexes, because the cartesian product of generating cubes is again a generating cube.This is not true for simplices.These considerations lead to Definition 2.16 of the cubical cup product in Sect.2.3.
In order to obtain Theorem 2.24, we need to derive an explicit formula for a chain map diag # : C(X) → C(X × X) induced by the diagonal map.Actually, this task is more complex than it may seem at the first glance and Sect.2.2 is devoted mainly to the related constructions.
Note that the choice of a chain map is not unique, thus the correctness of the definition and the properties of the cup product are achieved at the cohomology level.These properties are discussed in Sect.2.3.We end the section with an example illustrating the use of the explicit, coordinate-wise formula.
Cubical sets arising from large data sets which are present in applications are built of a huge number of generating elementary cubes.In order to benefit from the established formula in this context, one needs reduction algorithms which render the computation efficient.Thus the second goal of this paper, reached in Sect.3, is to show that the techniques of S-reductions of S-complexes successfully developed in [20,21] with the purpose of computing homology of large cubical complexes may be adapted to computing the cohomology ring of a cubical set.The terminology of S-complexes, S-reduction pairs, the coreduction algorithm and the concept of homology models are reviewed and adapted for cohomology.We finish the paper with Sect.3.5, where computations via S-reductions are carried out and compared on two explicit examples of a still quite simple nature.
The implementation of the methods presented in this paper as well as numerical experiments are in progress.In particular, the method of S-reductions for cohomology groups has been implemented in the Ph.D. thesis of P. Dłotko [6] and numerical experiments indicate the same efficiency of the implementation for cohomology groups as in the case of homology groups.

Cubical Cohomology Groups
Recall from [15, Chap.2] that X ⊂ R d is a cubical set if it is a finite union of elementary cubes number of non-degenerate intervals in its product expression and the embedding number emb Q is d.The set of all elementary cubes in R d is denoted by K(R d ) and those of dimension k by K k (R d ).Those which are contained in X are denoted by K(X), respectively, K k (X).
The group C k (R d ) of cubical k-chains is the free abelian group generated by K k (R d ), its canonical basis.For k < 0 and k > d, we set C k (R d ) := 0. In the sequel, we identify the geometric elementary cube Q with the elementary cubical chain defined by We recall that the cubical cross product is defined on the canonical basis elements P ∈ K n p and Q ∈ K m q as the cartesian product P × Q and extended on all pairs of chains (c, c ) by bilinearity.In [15], this operation is called cubical product and denoted by c c in order to distinguish it from the cartesian product but we abandon this notation here to emphasize its equivalence to the cross product in homological algebra.
Given any k ∈ Z, the cubical boundary map for some a ∈ Z.In the first case, ∂ 0 Q = 0.In the second case, we put For d > 1 decompose Q as Q = I × P , where emb I = 1 and emb P = d − 1, and put where p = dim I and q = dim P .The pair We refer to [15,Chap. 2] for the properties of the cubical cross product and cubical boundary maps, in particular for this one: As a consequence of the above formula, the cubical cross product induces an isomorphism of chain complexes (for the definition of the tensor product of chain complexes see e.g.[23,Chap. 7]).For any c, d ∈ C p (R d ), the notation c, d is used for the scalar product defined on the elements P , Q of the canonical basis K p by The support |c| of c is the union of all Q ∈ K p such that c, Q = 0. Given a cubical set X ⊂ R d , the cubical chain complex of X denoted by C(X) is the restriction of C(R d ) to the chains c whose support is contained in X.We refer to [15] for the properties of cubical chain complexes and for the computation of their homology.
Definition 2.2 Let X ⊂ R d be a cubical set.The cubical cochain complex (C * (X), δ) is defined as follows.For any k ∈ Z, the k-dimensional cochain group Note that C k (X) is the free abelian group generated by the dual canonical basis {Q |Q ∈ K k (X)} where The notation Q , for the dual of Q, is aimed to be distinct from H * for the cohomology functor.
The kth cohomology group of X is the quotient group Definition 2. 4 The cubical cross product of cochains c p ∈ C p (X) and c q ∈ C q (Y ) is a cochain in C p+q (X × Y ) defined on any elementary cube R × S ∈ K p+q (X × Y ), where R ∈ K(X) and S ∈ K(Y ), as follows: We easily check the following.

Proposition 2.5
The cross product of cochains is a bilinear map.Moreover, for P ∈ K p (X), Q ∈ K q (Y ), P ×Q = (P ×Q) .
Algebraic properties of the cubical product on cubical chains derived in [15, Sect.2.2] readily extend to the cross product on cochains, in particular the following.Proposition 2.6 If c p × c q ∈ C p+q (X), then δ c p ×c q = δc p ×c q + (−1) p c p × δc q .

Constructing Chain Maps
The most important step towards an explicit formula for the cup product is the construction of a homology chain map diag # : C(X) → C(X × X) induced by the diagonal map diag : X → X × X given by diag(x) := (x, x).This is done using the construction presented in [15,Chap. 6].We briefly outline that construction.
Given an elementary cube Q is Q with all its proper faces removed.Given cubical sets X and Y , a multivalued cubical map F : X − → → Y is a map from X to the set of subsets of Y such that The Chain Selector Theorem [15,Theorem 6.22] affirms that, if such a map is lower semicontinuous and has non-empty acyclic values (that is, H * (F (x)) = 0 for all x ∈ X), then it admits a chain selector, that is, a chain map ϕ : C(X) → C(Y ) with the properties Any two such chain selectors are chain homotopic [15,Theorem 6.25], so they give rise to the same map in homology.If a continuous map f : X → Y admits an acyclicvalued representation, that is, a lower semicontinuous cubical map F with the property f (x) ∈ F (x), the homology map of any chain selector ϕ of F is the map H * (f ) induced in homology by f [15,Proposition 6.56].The idea behind this construction is illustrated in Fig. 1.
In general, computing a map induced in homology may be hard, because an acyclic-valued representation may not always exist and one has to apply a process of rescaling [15,Sect. 6.4.2].However, for the purpose of this paper, we do not need Fig. 1 The graph of a continuous map f on an interval (displayed by a smooth curve), its representation F (displayed by shaded rectangles), and a symbolic display of a chain selector: The circles indicate pairs of vertices while the line segments connecting them can be used to localize, on the ordinate, the images of the corresponding edges under the chain map ϕ 1 rescaling, because all considered maps admit the acyclic-valued minimal representations.Recall from [15, Proposition 6.33 and Definition 6.34] that the minimal representation of a continuous map f : X → Y is a lower semicontinuous cubical map F : X − → → Y defined by where, given any set A ⊂ X, the closed hull ch(A) is the smallest cubical set containing A. In the case A = {x}, the set ch({x}) is an elementary cube denoted, for short, by ch(x).In the case of our diagonal map diag : X → X × X, its minimal representation Diag : X − → → (X × X) is given by Given chain maps ϕ : where the right-hand side is the cubical cross product of chains defined in Sect.2.1.

Lemma 2.7
Let X 1 , X 2 , Y 1 , Y 2 be cubical sets and let f : continuous maps which admit acyclic-valued representations F , G. Let ϕ and ψ be the chain selectors of F and, respectively, G.
Proof The statement in (a) is straightforward because the product of acyclic sets is acyclic.To prove (b), we show first that ϕ ⊗ ψ is a chain map.Given any It remains to check the chain selector conditions (6.12), (6.13) in [15,Theorem 6.22].First, we have Finally, for any vertex The following statement easily follows from the definitions.
Proposition 2.8 Let X 1 ⊂ R n and X 2 ⊂ R d−n be the images of a cubical set X ⊂ R d under its projections onto, respectively, the first n and the complementary d Theorem 2.9 Let X, Y be cubical sets and let λ : X × Y → Y × X be the transpose given by λ(x, y) := (y, x).
Then λ # is a chain selector of Λ.
Proof The statement (a) is a simple check of the definitions.For (b), the conditions (6.12), (6.13) in [15,Theorem 6.22] follow immediately from the definitions, so it remains to check that λ # is a chain map, that is, it commutes with the boundary map.
On the one hand, we have On the other hand, we have From Proposition 2.8 and Theorem 2.9 we derive the following corollary.
Here are dual statements of Theorem 2.9 and Corollary 2.10 for cochains.
Corollary 2.11 Let λ : X × Y → Y × X be the transpose defined in Theorem 2.9.
If dim P = p or dim Q = q, then both sides vanish.
Corollary 2.12 Let τ : be the permutation discussed in Corollary 2.10.The map induced by τ # is given on products of duals of ) by the formula Let X ⊂ R d be a cubical set.We proceed to the construction of a homologyrepresentative chain map diag # : C(X) → C(X × X) induced by the diagonal map.It is straightforward to see that the diagonal map admits an acyclic-valued representation Diag : X − → → (X × X) given by Diag(x) The construction of a chain selector proceeds by induction on d = emb X.
Fig. 2 Illustration of two choices of chain maps induced by the diagonal map in dimension one.The path "up and right" shows the one defined in (7), while the path "right and up" shows the one in ( 8) For k / ∈ {0, 1}, we must have diag k = 0.The formula (7) is illustrated in Fig. 2. In order to show that our formula defines a chain map we are looking for, we need to make two observations.Lemma 2.13 Let emb X = 1.The map diag # defined by ( 6) and ( 7) is a chain selector for Diag.
Proof The conditions [15, Theorem 6.22, (6.12), (6.13)] follow immediately from the definitions, so it remains to check that diag # is a chain map.Since ∂ 0 = 0 and On the other hand, leads to a different chain selector of Diag and a different definition of a cup product on cochains.Note that the two choices are homologous since These ideas are shown in Fig. 2.

Induction
Step Suppose that diag # is defined for cubical sets of embedding numbers n = 1, . . ., d −1 and let us construct it for a cubical set X of the embedding number d.
where τ : R 2d → R 2d is the permutation of coordinates which transposes the (d +1)st coordinate with the preceding d − 1 coordinates.The formula for the chain maps induced by τ is provided by Corollary 2.10.Consider the images X 1 ⊂ R and X 2 ⊂ R d−1 of X under its projections of, respectively, the first and the complementary d − 1 coordinates in R d .Let diag X 1 and diag X 2 be the diagonal maps defined, respectively, on X 1 and X 2 .Then the diagonal map on X is the composition where j is the inclusion map discussed in Proposition 2.8.Note that τ takes values in defined by the formula where ) is defined by formula (5), and Proof We first check that the composition of the minimal representations of the maps involved in formula (9) and described in the series of preceding lemmas produces formula (4) for Diag.This implies, in particular, that the composition has acyclic values contained in X × X.Let x = (x 1 , x 2 ) ∈ X, with x i ∈ X i , and have ch(y) ⊂ Q and the equality holds when y ∈ We have and the inclusion becomes equality when y ∈ • Q.Thus, by Lemma 2.7(a), we have the inclusion and the two sets are equal when y ∈ • Q.From this, we get Using Corollary 2.10 and arguing as above, we get Hence the map Diag is equal to T • Diag X 1 × Diag X 2 • J with the range restricted to the image X × X.It follows that the composition of the corresponding chain selectors has the image in C(X × X).Finally, it follows from [15,Corollary 6.31] that this composition is a chain selector for Diag.

The Cubical Cup Product
Definition 2. 16 Let X be a cubical set.The cubical cup product of cochains c p and c q is defined by the formula In particular, for Q ∈ K p+q (X) The distributive law for the cup product on cochains follows immediately from Definition 2.16, the linearity of diag p+q , and the distributive law for the cross product.The proof of the associativity law and the identification of the unit element will be easier once we have established an explicit formula for the cup product.Definition 2.16 is also suitable for proving the boundary properties, and the graded commutative law: Theorem 2.17 (Boundary Properties of the Cup Product) (a) δ(c p c q ) = δc p c q + (−1) p c p δc q .(b) If z p ∈ Z p (X) and z q ∈ Z q (X), then z p z q ∈ Z p+q (X).(c) If x p , y p ∈ Z p (X), x p − y p ∈ B p (X), and z q ∈ Z q (X), then x p z q − y p z q ∈ B p+q (X) and z q x p − z q y p ∈ B p+q (X).
(b) is an immediate consequence of (a).(c) Let x p − y p = δw.It follows from (a) that x p − y p z q = δw z q = δ w z q because δz q = 0. Hence x p z q − y p z q ∈ B p+q (X).The second equation follows by the same argument.
The property (a) in Theorem 2.17 is the analogy of the boundary property of the cubical cross product defined in [15, Sect.2.2].The property (b) asserts that the cup product sends cocycles to cocycles, and by (c) that it does not depend on a representative of a cohomology class.Thus, we get the definition: Definition 2. 18 The cup product : H p (X) × H q (X) → H p+q (X) is defined on cohomology classes of cocycles as follows: The distributive law (12) extends easily to cohomology classes.The following property holds only for cohomology classes.Theorem 2.19 (Graded Commutative Law) If z p and z q are cocycles, then z q z p = (−1) pq z p z q .
Proof Let λ be the transpose defined in Theorem 2.9, applied for X = Y .Let Q ∈ K(X).On the one hand, we have z p z q , Q = z p ×z q , diag p+q (Q) .
We can now derive an explicit formula, suitable for computations, for the cubical cup product on cochains.By the distributive law (12), it is sufficient to present a formula for generators P ∈ K p (X) and Q ∈ K q (X).The formula is developed recursively with respect to d = emb X and presented in three stages, the first one for the case d = 1, the second one for the recursion step, and the last one is the final recursion-free coordinate-wise formula.

Theorem 2.20 Let X be a cubical set in R and let
In particular, P Q is either zero, or a dual of an elementary interval.
We reach the conclusion by expressing the values in terms of elementary intervals [a] = 0, we see that the graded commutative law in Theorem 2.19 does not hold for the cup product on the level of chain complexes.
Theorem 2. 22 Let emb X = d > 1, and suppose that the formula for is given for cochains on cubical sets of embedding numbers n = 1, . . ., d − 1.Consider the decomposition of elementary cubes Q 2 be computed using the induction hypothesis.Then , where emb R 1 = 1 and emb R 2 = d − 1.Let p = dim R 1 and q = dim R 2 .Note that p + q = k.By Lemma 2.15 we get Since π k is a projection, its dual map π k is an injection which extends any element of C (X × X) as zero on elementary cubes in K By Proposition 2.8, Corollary 2.12 and Lemma 2.7, we get with a non-trivial value assumed if and only if |x| = R 1 and |y| = R 2 .However, R ∈ K(X) and the conclusion follows.
The following example illustrates the need for considering the alternative |x×y| / ∈ K(X) in the formula for P Q in Theorem 2.22.

Example 2.23 Let
However, if X = P ∪ Q, we get P Q = 0.
We now pass to a coordinate-wise formula.Let P and Q be as in Theorem 2.22.Consider their decompositions to products of intervals in R: We get the following.

Theorem 2.24 Let d = emb(X) > 1. With the above notation for elementary cubes
provided the right-hand side is supported in X, and P Q = 0 otherwise.
Proof We derive the formula from Theorem 2.22 by induction on the embedding number d > 1.
Let d > 2. We apply Theorem 2.22 with P 1 = I 1 , P 2 = P 1 , Q 1 = J 1 , and Note that the support of the cross product on the right-hand side of ( 14) is the cartesian product of the supports of the terms: Therefore, the support of the right-hand side of ( 14) is non-empty and contained in X if and only if one of x × y in Theorem 2.22 is non-empty and contained in X.If this is not the case, both formulas give the cochain 0. Assume the non-trivial case.Then the support of P 1 Q 1 is non-empty and contained in X 2 .By induction hypothesis, where Let X be a cubical set embedded in R d .We define the weight of a cochain c p in X by By bilinearity, the computation of c p c q for two cochains c p , c q in X reduces to finding w(c p )w(c q ) cup products of generating elementary cubes.Since it follows easily from Theorem 2.24 that the cost of finding the cup product of two generating elementary cubes is O(d 2 ), we obtain the following.

Corollary 2.25
The computational complexity of evaluating c p c q is O(d 2 mn) where m is the weight of c p and n is the weight of c q .
Example 2.26 We illustrate the cup-product formula for the cubical torus 2 is the boundary of the square.Since it is hard to draw pictures in R 4 , we parameterize Γ 1 by the interval [0, 4] with identified endpoints 0 ∼ 4, which permits visualizing T as the square [0, 4] 2 with pairs of identified boundary edges, as shown in Fig. 3.
Consider the cocycle x 1 generated by the sum of four solid line vertical edges with [2,3] at the second coordinate, and y 1 by the sum of solid line horizontal edges with [1,2] at the first coordinate.Only the edges of the parametric square [1, 2] × [2, 3] may contribute to non-zero terms of x 1 y 1 .Thus, using Theorem 2.20 and Theorem 2.24, The cohomology classes of cochains x 1 and y 1 generate H 1 (T ), and where We are now ready to prove the remaining ring properties for the cubical cup product.
Theorem 2.27 Let X be a cubical set.The cup product on cubical cochains is associative, that is, The cochain given by 1 C 0 (X) := V ∈K 0 (X) V is the unit element, that is, A fortiori, these formulas are valid for cohomology classes.
Proof By the distributive law (12), it is sufficient to work with generators P ∈ K p (X), Q ∈ K q (X), and R ∈ K r (X).Let d = emb(X).
The unit element property easily follows from Theorem 2.20 in the case d = 1 and from Theorem 2.24 in the case d > 1.
We prove the associativity by induction on d.When d = 1, a routine verification of the formula in Theorem 2.20 shows that (P Q ) R = 0 if and only if there exists a ∈ Z such that the triple (P , Q, R) takes one of the forms In the first case (P Q ) R = [a] and in the remaining cases it is [a, a + 1].The same is verified for P (Q R ).Let now d > 1 and suppose the conclusion is true for the embedding numbers smaller than d.
where the first component of each elementary cube is in R and the second one in R d−1 .Using Theorem 2.20 and Theorem 2.22, we prove that where provided the displayed cross product is non-trivial and supported in X, and it is 0 otherwise.Indeed, assume the non-trivial case.The first application of Theorem 2.22 gives By Theorem 2.20, Let S = S 1 × S 2 .By hypothesis, S ∈ K(X).Hence (17) can be written as Another application of Theorem 2.22 gives We obtain (15) by combining (18) with (19) and passing (−1) γ inside the cross product term containing S 2 .Analogously, where with the same condition on the support.By the induction hypothesis, the expressions inside the square brackets in equations ( 15) and ( 20) are equal.In particular their supports are equal, so we may assume that both supports are non-empty and contained in X.It remains to show that (−1) α = (−1) β .By Definition 2.16, hence the conclusion follows.By Definition 2.18, the last statement on extension to the cohomology classes is obvious.
The algebraic properties listed in (12), Theorem 2.27 and in Theorem 2.19 are referred to as the graded ring properties.Thus we arrived at the key definition: Definition 2.28 Let X be a cubical set.The cubical cohomology ring of X is the graded abelian group H (X) with the graded multiplication given by the cup product.
It is known that the ring structure introduced in Definition 2.28 may be used to distinguish non homeomorphic spaces even if their homology and cohomology groups are isomorphic.This is shown in the example presented in Sect.3.5.

Remark 2.29
All what we have done until now can be extended to chain complexes C(X; R) := C(X) ⊗ R with coefficients in a ring with unity R, which are graded modules over R.This gives rise to the cohomology ring H * (X; R).We have initially chosen coefficients in Z for the sake of clarity and, in particular, to avoid confusion between two rings, R and the graded cohomology ring.However, we introduce ring coefficients in the next section because, for computational purposes, it is often convenient to choose coefficients in the finite field R = Z p , p a prime number.Field coefficients are sufficient in many practical applications.

Computing Cohomology
The aim of this section is to show that the techniques of S-reductions of S-complexes developed in [20,21] in order to construct efficient algorithms computing homology of cubical complexes may be easily adapted to provide algorithms computing the cohomology ring of a cubical set.

S-Complexes
Let R be a ring with unity and let S be a finite set.Denote by R(S) the free module over R generated by S. Let (S q ) q∈Z be a gradation of S such that S q = ∅ for all q < 0. Then (R(S q )) q∈Z is a gradation of the module R(S) in the category of modules over the ring R. For every element s ∈ S, the unique number q such that s ∈ S q is called the dimension of s and denoted by dim s.We use the notation •, • : R(S) × R(S) → R for the inner product which is defined on generators by t, s = 1 for t = s, 0 otherwise, and extended bilinearly to R(S) × R(S).
We recall (see [20,21]) that a pair (S, κ), where κ : S × S → R is a map such that κ(s, t) = 0 unless dim s = dim t + 1, is called an S-complex, if the pair (R(S), ∂ κ ) is a free chain complex with base S and the boundary map ∂ κ : R(S) → R(S) is defined on generators s ∈ S by The homology of an S-complex (S, κ) is the homology of the associated chain complex (R(S), ∂ κ ), denoted H (S, κ) or simply H (S). The elements of R(S) are called chains.
Any cubical set X ⊂ R d discussed in Sect. 2 defines an S-complex (S, κ), where S = K(X) is the set of all elementary cubes of X and κ(Q, P ) := ∂Q, P , ∂ the cubical boundary map.Its chain complex (R(S), ∂ κ ) is equal to C(X; R) = C(X)⊗R, the cubical chain complex of X with coefficients in R.
Let R (S) := Hom(R(S), R) be the group of cochains.The coboundary map defined as the dual δ κ := (∂ κ ) satisfies for duals of generators t ∈ S.Moreover, for any pair of a chain c ∈ R(S q ) and a cochain d ∈ R (S q−1 ) we have The cohomology of the cochain complex (Hom(R(S), R), δ κ ) is called the cohomology of the S-complex and denoted H * (S).
In the following, we will drop the superscript κ in ∂ κ and δ κ whenever κ is clear from the context.
The technique of S-reductions consists of replacing the original set of generators S by a subset S ⊂ S, and the original coincidence index κ by the restriction κ := κ| S ×S .This has to be done in such a way that (S , κ ) is still an S-complex, and the (co)homology does not change.A subset K ⊂ K is an S-subcomplex of the S-complex K if (K , κ ), with κ := κ| K ×K , the restriction of κ to K × K , is itself an S-complex, i.e. if (R[K ], ∂ κ ) is a chain complex.Note that the concept of an S-subcomplex is not the same as the chain subcomplex (see [7,Example 1]).
Two important special cases of S-subcomplexes are the closed and open subset of an S-complex.In order to define these concepts we introduce the following notation for any subset A ⊂ S: Therefore, there is a well defined restriction Similarly, if K is open in K, then there is a well defined quotient complex (R[K]/R[K \ K ], ∂ ) with the boundary map ∂ taken as the respective quotient map of ∂ κ .From the computational point of view it is worth to observe that the quotient complex is isomorphic to the S-complex (K , δ κ ) where K = K \ K and κ = κ |K ×K (cf.[20]).
The following theorem is a straightforward extension of Theorem 3.4 in [20] to cohomology.Theorem 3.1 Let (S, κ) be an S-complex over the ring R, S ⊂ S a closed subset and S := S \ S the associated open subset.Then we have the following long exact sequence of homology modules: and the following long exact sequence of cohomology modules: in which ι * : H q (S ) → H q (S) and ι * : H q (S) → H q (S ) are induced by the inclusion ι : R(S ) → R(S), whereas π * : H q (S) → H q (S ) and π * : H q (S ) → H q (S) are induced by the projection π : R(S) → R(S ).

S-Reduction Pairs and the Coreduction Algorithm
Let (S, κ) be an S-complex.A pair (a, b) of elements of S is called an S-reduction pair if κ(b, a) is invertible and either cbd S a = {b} or bd S b = {a}.In the first case the S-reduction pair is referred to as an elementary reduction pair and in the other case as an elementary coreduction pair.
Arguing as in the proof of [20,Theorem 4.1] we obtain the following theorem.[20,Algorithm 6.1].The same algorithm without any changes may be used to speed up computation of cohomology modules.The algorithm consists of performing as many S-reductions as possible before applying the general Smith diagonalization algorithm to the reduced S-complex in order to compute the homology or cohomology module.To make it useful, one needs to find as many S-reduction pairs as feasible.In the case of simplicial complexes and cubical complexes it is straightforward to provide examples which admit elementary reduction pairs, but elementary coreduction pairs are not possible right away.However, it is easy to observe that by removing a vertex one obtains an open subcomplex which admits elementary coreduction pairs.Moreover, the homology of this subcomplex coincides with the reduced homology of the original complex and the cohomology of this complex coincides with the reduced cohomology of the original complex.Therefore, not only elementary reduction pairs, but also elementary coreduction pairs are useful when computing the homology or cohomology of simplicial or cubical complexes.
If the reduced S-complex is small when compared to the original S-complex then the coreduction algorithm is fast, because the reduction process is linear whereas the Smith diagonalization algorithm is supercubical.In fact, numerical experiments indicate that elementary coreduction pairs provide essentially deeper reductions than the elementary reduction pairs, and the speed up is essential.For details we refer the reader to [20,Sect. 5].

Homology Models
The Smith diagonalization algorithm applied to the reduced S-complex enables computing the cohomology module of the original S-complex up to isomorphism.In order to compute the cohomology ring of a cubical set it is not sufficient to have the cohomology generators in a reduced S-complex.It is necessary to construct the cohomology generators in the original cubical set.
Since mutually inverse chain equivalences induce isomorphisms in cohomology, we get the following corollary.As we already mentioned, the coreduction algorithm consists of performing a sequence of reductions.A reduction sequence of an S-complex (S, κ) is a sequence of pairs ω = {(a i , b i )} i=1,2,...,n in S such that (a i , b i ) is a reduction pair in (S i−1 , κ i−1 ), where the S-complexes (S i , κ i ) are defined recursively by taking We then use the notation S ω for the last chain complex in the sequence of S-complexes {S i } i=1,2,...,n and call this S-complex the ω-reduction of S. A homology model of S is an ω reduction S ω together with the chain equivalences.
In order to discuss the benefits of constructing a homology model of an S-complex S let us define first the weight of S by w(S) := max max(card bd s, card cbd s) | s ∈ S .
The construction of a homology model of an S-complex S may be performed in time O(w(S) card S) (see [20,Theorem 6.2]).In particular, in the case of cubical sets of fixed embedding dimension the homology model construction takes linear time.When the ω-reduction of S is small relative to S, one can profit from the homology model whenever homology generators and/or a decomposition of a homology class on the generators are needed.To construct the generators of H (S) one constructs the generators of H (S ω ) and transports them to H (S) via the map ι ω , i.e. computes their image in ι ω .The computational complexity of this computation is O(w(S) card S) (see [21,Theorem 3.1]).To decompose a homology class in H (S) one transports the class via the map ψ ω to H (S ω ) and finds the decomposition there.See [21,Sect. 3.1] for details.

Homology Models for Cohomology
Precisely the same method may be used to speed up the construction of the cohomology generators in H * (S) and the same complexity analysis applies to this case.One only uses the dual (ι ω ) of ι ω to transport the cochains in the S-complex to its ω reduction and the dual (ψ ω ) of ψ ω to transport the cochains in the ω-reduction back to the original S-complex.However, the transport requires an analogue of Theorem 3.4 for the duals ψ and ι .For this it is convenient to make the following convention.If T is an S-subcomplex of the S-complex S and t is a generator in T then dual of t in T is the restriction to T of the dual of t in S. Since the dual of t in S is always zero on S \ T , it is convenient to identify both duals and denote them by the same symbol t .Using this convention and the setting of Theorem 3.4 we have the following theorem.

Theorem 3.6
The duals of the chain maps ψ and ι are given by Proof It is enough to verify the formulas on generators.Let t ∈ S and let c ∈ R(S).
Surprisingly, there are even more benefits from the homology model for cohomology computations than for homology computations.This is because of the following theorem.
Theorem 3.7 Assume ω is a reduction sequence of an S-complex consisting only of elementary coreduction pairs.Then (ψ ω ) is an inclusion R S ω → R (S), that is, (ψ ω ) (c) = c for any c ∈ R (S ω ).
Proof If (a, b) is an elementary coreduction pair, then bd b = {a}.Since a ∈ S = S \ {a, b}, we have b , δc = ∂b, c = 0 for any c ∈ R( S).Therefore, (ψ (a,b) ) (c) = c for any c ∈ R ( S).Since the reduction sequence ω consists only of elementary coreduction pairs, the conclusion follows.
Note the following consequence.In the case of a reduction sequence ω consisting only of elementary coreduction pairs there is no need to transport the cohomology generators from the ω-reduction back to the original S-complex.The cohomology generators constructed in the ω-reduction are the cohomology generators in the original S-complex.This is particularly useful for computing the ring structure of a cubical set X, because we can apply formula (14) directly to the cohomology generators in the ω-reduction.

Computational Example
Observe that the set is a cubical subset of R 3 homeomorphic to S 2 ∨ S 1 ∨ S 1 (see Fig. 4 top left).The coreduction algorithm (see Sect. Equations ( 26) and (27) show that the cohomology rings of X and T are different.In this simple case, it is possible to make the necessary computations by hand.However, one may have two cubical sets homeomorphic respectively to X and T whose representations consist of millions of cubes.Such cubical sets often result from rigorous numerics of dynamical systems, data or image analysis.The benefits from computing the ring structure via the cohomology model is evident.This is visible even in the case of a simple rescaling (for the definition of rescaling see [15,Sect. 6.4.2]) of the cubical sets in our two examples (see Fig. 5).

Lemma 2 . 15
the composition of maps on the right-hand side of (9) takes values in X × X.Let d = emb X > 1. Assume that the chain selector diag # of Diag is defined for cubical sets of embedding numbers less than d.Consider the chain map

Fig. 3 y 1 By
Fig.3 The graphical representation of the cubical torus discussed in Example 2.26.The solid line vertical edges carry the cocycle x 1 and the horizontal ones the cocycle y 1 .The shaded square carries x 1 y 1

Corollary 3 . 5
If (S, κ), is an S-complex over the ring R and (a, b) is an S-reduction pair in S, then the isomorphisms pointed out in Corollary 3.3 are induced by the chain maps defined in(22) and(23) for homology and their duals for cohomology.

Fig. 5
Fig. 5 Rescaled wedge of the sphere and two circles from Fig. 4 (top left) and the result of a coreduction (top right).Rescaled cubical torus (bottom left) and the result of a coreduction (bottom right) , Z , where Hom(−, Z) is the functor assigning to any abelian group G the group of all homomorphisms from G to Z, called the dual of G. Elements of C k (X) are called cochains and denoted either by c k , d k or by c , d , if we do not need to specify their dimension k.The value of a cochain c k on a chain d k is denoted by c k , d k .
Theorem 3.2 Assume S is an S-complex and (a, b) is an S-reduction pair in S. If (a, b) is an elementary reduction pair then {a, b} is open in S. If (a, b) is an elementary coreduction pair then {a, b} is closed in S.Moreover, in both cases {a, b} is an S-subcomplex of S and H * ({a, b}) = H * ({a, b}) = 0.If (a, b) is an S-reduction pair in an S-complex S, then the homology modules H (S) and H (S \ {a, b}) as well as the cohomology modules H * (S) and H * (S \ {a, b}) are isomorphic.Corollary 3.3 lies at the heart of the coreduction homology algorithm presented in