Modular Counting CSP: Reductions and Algorithms
Abstract
The Constraint Satisfaction Problem (CSP) is ubiquitous in various areas of mathematics and computer science. Many of its variations have been studied including the Counting CSP, where the goal is to find the number of solutions to a CSP instance. The complexity of finding the exact number of solutions of a CSP is well understood (Bulatov, 2013, and Dyer and Richerby, 2013) and the focus has shifted to other variations of the Counting CSP such as counting the number of solutions modulo an integer. This problem has attracted considerable attention recently. In the case of CSPs based on undirected graphs Bulatov and Kazeminia (STOC 2022) obtained a complexity classification for the problem of counting solutions modulo for arbitrary prime . In this paper we report on the progress made towards a similar classification for the general CSP, not necessarily based on graphs.
We identify several features that make the general case very different from the graph case such as a stronger form of rigidity and the structure of automorphisms of powers of relational structures. We provide a solution algorithm in the case that works under some additional conditions and prove the hardness of the problem under some assumptions about automorphisms of the powers of the relational structure. We also reduce the general CSP to the case that only uses binary relations satisfying strong additional conditions.
1 Introduction
Counting problems in general have been intensively studied since the pioneering work by Valiant [39, 38]. One of the most interesting and well studied problems in this area is the Counting Constraint Satisfaction Problem (), which provides a generic framework for a wide variety of counting combinatorial problems that arise frequently in multiple disciplines such as logic, graph theory, and artificial intelligence. The counting also allows for generalizations including weighted CSPs and partition functions [3, 10] that yield connections with areas such as statistical physics, see, e.g. [33, 37]. While the complexity of exact counting solutions of a is now well-understood [16, 5, 17, 15], modular counting such as finding the parity of the number of solutions remains widely open.
Homomorphisms and the Constraint Satisfaction Problem. The most convenient way to introduce CSPs is through homomorphisms of relational structures. A relational signature is a collection of relational symbols each of which is assigned a positive integer, the arity of the symbol. A relational structure with signature is a set and an interpretation of each , where is a relation or a predicate on whose arity equals that of . The set is said to be the base set or the universe of . We will use the same letter for the base set as for the structure, only in the regular font. A structure with signature is often called a -structure. Structures with the same signature are called similar.
Let be similar structures with signature . A homomorphism from to is a mapping such that for any , say, of arity , if is true for , then is also true. The set of all homomorphisms from to is denoted . The cardinality of is denoted by . A homomorphism is an isomorphism if it is bijective and the inverse mapping is a homomorphism from to . A homomorphism of a structure to itself is called an endomorphism, and an isomorphism to itself is called an automorphism.
Following Feder and Vardi [21], in a , the goal is, given similar relational structure , to decide whether there is a homomorphism from to . The restricted problem in which is fixed and only is given as an input is denoted by . The complexity of such problems is well understood [6, 40].
Counting CSP. In the (exact) Counting the goal is to find the number of homomorphisms from a structure to a similar structure . Restricted versions of the Counting CSP can be introduced in the same way as for the decision one. In the counting version of denoted the goal is to find for a given structure .
The complexity class the Counting belongs to is #P, the class of problems of counting accepting paths of polynomial time nondeterministic Turing machines. There are several ways to define reductions between counting problems, but the most widely used ones are parsimonious reductions and Turing reductions. A parsimonious reduction from a counting problem to a counting problem is an algorithm that, given an instance of produces (in polynomial time) an instance of such that the answers to and are equal. A Turing reduction is a polynomial time algorithm that solves using as an oracle. Completeness in #P is then defined in the standard way. This paper and all the papers we cite predominantly use Turing reductions.
A complexity classification of counting s of the form was obtained by Bulatov [5] and was further improved and simplified by Dyer and Richerby [17]. Bulatov’s proof makes heavy use of techniques of universal algebra. Dyer and Richerby’s proof, on the other hand, uses combinatorial and structural properties of relational structures. The more general version of the counting CSP, the weighted CSP, has also been thoroughly studied. Cai and Chen [13] obtained a complexity classification for weighted CSP, where each homomorphism has a complex weight. One of the main features of counting with complex weights is the phenomenon of cancellation, when complex weights of homomorphisms cancel each other rather than add up. This, of course, never happens in exact unweighted counting problems, but is frequently encountered in modular counting.
Modular Counting. Another natural variation of counting problems is counting modulo some integer. In this paper we consider the problem of computing the number of solutions of a modulo a prime number . If a relational structure is fixed, this problem is denoted . More precisely, in the objective is, given a relational structure , to find the number of homomorphisms from to modulo .
There are several complexity classes related to modular counting. The more established type of classes is P, the class of problems of deciding whether the number of accepting paths of a polynomial time nondeterministic Turing machine is not divisible by , [14, 30]. In particular, if then P is the class P. However, problems of counting accepting paths naturally belong to classes of the form P, introduced by Faben in [19] that contain problems of counting accepting paths modulo . The standard notion of reduction is again Turing reduction. Faben in [19] studied the basic properties of such classes, in particular, he identified several P-complete problems.
In the case of the , the research has mostly been focused on graph homomorphisms. The only exceptions we are aware of are a result of Faben [19], who characterized the complexity of counting the solutions of a Generalized Satisfiability problem modulo an integer, and a generalization of [19] to problems with weights by Guo et al. [26]. The study of modular counting of graph homomorphisms has been much more vibrant.
Before discussing the existing results on modular counting and the results of this study, we need to mention some features of the automorphism group of a relational structure. The automorphisms of form a group with respect to composition denoted . The order of an automorphism is the smallest number such that is the identity permutation. An element is a fixed point of if . The set of all fixed points of is denoted by .
A systematic study of counting homomorphisms in graphs was initiated by Faben and Jerrum in [19]. They observed that the automorphism group , particularly the automorphisms of order , plays a crucial role in the complexity of the problem . This insight extends to relational structures, as discussed in [12]. Specifically, for a homomorphism from a relational structure to , composing with an automorphism from yields another homomorphism from to . Thus, any automorphism of acts on the set of all homomorphisms from to . If contains an automorphism of order , the size of the orbit of is divisible by unless . In this case, the range of lies within the set of fixed points of , making this orbit contribute modulo to the total homomorphism count from to . This observation motivates the following construction: let denote the substructure of induced by . We denote by the existence of a such that is isomorphic to . Furthermore, we write if there exist structures such that is isomorphic to , is isomorphic to , and .
Relational structures without order automorphisms will be called -rigid.
Lemma 1.1 ([12, 20]).
Let be a relational structure and a prime. Then
(a) Up to an isomorphism there exists a unique -rigid structure such that .
(b) For any relational structure it holds that
By Lemma 1.1 it suffices to determine the complexity of for -rigid structures .
The existing results on modular counting. As we mentioned before, the research in modular counting s has mostly been aimed at counting graph homomorphisms. The complexity of the problem of counting homomorphism to a fixed graph modulo a prime number has received significant attention in the last ten years. Faben and Jerrum in [20] posed a conjecture that up to order automorphism reduction the complexity of this problem is the same as that for exact counting. More precisely, they conjectured that is solvable in polynomial time if and only if is. By the result of Dyer and Greenhill [16] is solvable in polynomial time if and only if every connected component of is a complete graph with all loops present or a complete bipartite graph. Therefore, proving that if a -rigid does not satisfy these conditions then is -hard suffices to confirm the conjecture of Faben and Jerrum. Over several years the hardness of was established for various graph classes [20, 27, 24, 25, 34, 22, 36]. Finally, it was proved for arbitrary graphs by Bulatov and Kazeminia [12].
Theorem 1.2 ([12]).
For any prime and any graph the problem is solvable in polynomial time if and only if is solvable in polynomial time. Otherwise it is P-complete.
Our Results. In this paper we begin a systematic study of the problem for general relational structures . Note that to the best of our knowledge, it is the first paper attempting at such a general modular counting problem. The ultimate goal is to obtain a complexity classification similar to Theorem 1.2 for arbitrary relational structures. The contribution of the paper is twofold. First, we analyse the existing techniques and their applicability to the general case. We conclude that few of them work. More specifically, Theorem 1.2 asserts that the complexity of modular counting for -rigid graphs is the same as of exact counting. We, however, suggest a relational structure, a digraph , that is -rigid, its exact counting problem is hard, but modular counting is easy, see Section 5. Another important ingredient of the proof of Theorem 1.2 is a structural theorem on automorphisms of products of graphs [29]. No such result exists for products of relational structures. Moreover, in Section 8.1 we suggest an example (again, a digraph) showing that nothing similar to such a structural result can be true. Some of the standard techniques in counting CSPs involve properties of relations and relational structures such as rectangularity, permutability, balancedness, the presence of a Mal’tsev polymorphism. In the case of exact counting these concepts are closely related to each other and make efficient algorithms possible. Unfortunately, these concepts are of little help for modular counting. We introduce their modular equivalents, but then a series of examples show that no tight connections are possible in this case, see Section 6. This makes algorithm design very difficult.
On the positive side, we obtain some results to somewhat remedy the situation. The first step is to convert the problem into a richer framework of multi-sorted relational structures and CSPs. The main idea is, given a CSP instance , to try to identify the possible images of each vertex of , and then treat vertices with different ranges as having different types and map them to different disjoint domains. In Section 5 we call this process refinement and propose two types of refinement, one is based on local propagation techniques, and the other on solving the decision version of the problem. The main benefit of using multi-sorted structures and CSPs is the richer structure of their automorphisms. This often allows stronger reductions than single-sorted structures do. In particular, if the digraph mentioned above is subjected to this process, it results in a multi-sorted structure that is no longer -rigid, the corresponding reduced structure is very simple and can easily be solved. We are not aware of any examples of a structure whose multi-sorted refinement is -rigid, but that would give rise to an easy modular counting problem.
In the next line of research we follow the approach of [12] to expand the relational structure by adding relations to that are primitive positive (pp-)definable in , that is, relations that can be derived from the relations of using equality, conjunction and existential quantifiers. However, expanding the general relational structure by pp-definable relations does not work as well as for graphs. To overcome this obstacle, we introduce a new form of expansion which uses -modular quantifiers instead of regular existential quantifiers. The semantics of a -modular quantifier is ”there are non-zero modulo values of a variable” rather than ”there exists at least one value of a variable” as the regular existential quantifier asserts. Every relational structure is associated with a relational clone that consists of all relations pp-definable in . The new concept gives rise to new definitions of pp-formulas and relational clones. If regular existential quantifiers in pp-formulas are replaced with -modular quantifiers, we obtain -modular primitive positive formulas (-mpp-formulas, for short). Then, similar to pp-definitions, a relation is said to be -mpp-definable in a structure if there is a -mpp-formula in expressing . The -modular clone associated with is the set of all relations -mpp-definable in . We show in Theorem 4.3 (see also Theorem 2.5) that, similar to the result of Bulatov and Dalmau [8], expanding a structure by a -mpp-definable relation does not change the complexity of the problem .
Theorem 1.3.
Let be a prime number and a -rigid relational structure. If is -mpp-definable in , then is polynomial time reducible to .
In the remaining part of the paper we identify a number of conditions under which it is possible to design an algorithm or to prove the hardness of the problem. One such case is when satisfies both 2-rectangularity and the usual strong rectangularity conditions (or, equivalently, has a Mal’tsev polymorphism). It starts with applying the known techniques [7, 17] to find a concise representation or a frame of the set of solutions of a given CSP. However, such a representation cannot be used directly to find the parity of the number of solutions. The algorithm performs multiple recomputations of the frame to exclude the parts that produce an even number of solutions. Unfortunately, this algorithm does not generalize to larger even under very strong assumptions, because the structure of finite fields start playing a role.
While studying the structure of automorphisms of products of relational structures such as may be a difficult problem, in Section 9 we make a step forward by reducing the class of structures for which such structural results are required. More precisely, for any relational structure we construct its binarization whose relations are binary and rectangular. This makes such structures somewhat closer to graphs and the hope is that it will be easier to study the structure of than itself. We prove that and share many important properties.
Theorem 1.4.
Let be a relational structure. Then is strongly rectangular (-strongly rectangular, -rigid, has a Mal’tsev polymorphism) if and only if is strongly rectangular (-strongly rectangular, -rigid, has a Mal’tsev polymorphism).
In Section 8 we explore what implications of a structural results about can be. We show that assuming certain such a result has similar consequences as those in the case of graphs, they may be sufficient to prove the hardness of .
We provide a more detailed overview of the main results in Section 3.
2 Preliminaries
Let denote the set . Let be the Cartesian product of the set with itself times and the Cartesian product of sets . We denote the members of and using bold font, , . The -th element of is denoted by or .
For we use to denote ; and for we use to denote . For by we denote the number of assignments such that . (Note that the order of elements in and and might differ, hence we slightly abuse the notation here.) We denote the number of assignments mod by . Moreover, denotes the set . Often, we treat relations as predicates .
2.1 Multi-Sorted sets and relational structures.
We begin with introducing multi-sorted or typed sets. Let be a collection of sets. We will assume that the sets are disjoint. The cardinality of a multi-sorted set equals . A mapping between two multi-sorted sets and is defined as a collection of mappings , where , that is, maps elements of the sort in to elements of the sort in . A mapping from to is injective (bijective), if for all , is injective (bijective).
A multi-sorted relational signature over a set of types is a collection of relational symbols, a symbol is assigned a positive integer , the arity of the symbol, and a tuple , the type of the symbol. A multi-sorted relational structure with signature is a multi-sorted set and an interpretation of each , where is a relation or a predicate on and is called the type of . The multi-sorted structure is finite if and are finite. All structures in this paper are finite. The set is said to be the base set or the universe of . For the base set we will use the same letter as for the structure, only in the regular font. Multi-sorted structures with the same signature and type are called similar.
Let be similar multi-sorted structures with signature . A homomorphism from to is a collection of mappings , , from to such that for any with type , if is true for , then is true as well. The set of all homomorphisms from to is denoted . The cardinality of is denoted by . For a multi-sorted structure , the corresponding counting CSP, , is the problem of computing for a given structure . A homomorphism is an isomorphism if it is bijective and the inverse mapping is a homomorphism from to . If and are isomorphic, we write . A homomorphism of a structure to itself is called an endomorphism, and an isomorphism to itself is called an automorphism. As is easily seen, automorphisms of a structure form a group denoted .
The direct product of multi-sorted -structures , denoted is the multi-sorted -structure with the base set , the interpretation of is given by if and only if and . By we will denote the th power of , that is, the direct product of copies of .
Let be a multi-sorted relational structure and an automorphism of . For , we use to denote the set , where . For a prime number we say that has order if is not the identity in and has order in . In other words, each of the ’s is either the identity mapping or has order , and at least one of the ’s is not the identity mapping. Structure is said to be -rigid if it has no automorphism of order . Similar to regular relational structures we can introduce reductions of multi-sorted structures by their automorphisms of order .
A substructure of induced by a collection of sets , where is the relational structure given by , where and is the type of . By we denote the collection of sets of fixed points of the ’s. Let denote the substructure of induced by . We write if there is of order such that is isomorphic to . We also write if there are structures such that is isomorphic to , is isomorphic to , and . Let also be a -rigid structure such that .
Proposition 2.1.
Let be a multi-sorted structure and a prime. Then up to an isomorphism there exists a unique -rigid multi-sorted structure such that .
The proof of Proposition 2.1 follows the same lines as the analogous statement in the single-sorted case, and is moved to Appendix A.
Lemma 2.2.
Let be a multi-sorted relational structure. If is a -automorphism of , then for any ,
Proof.
Let and denote the universes of and respectively. For a similar multi-sorted structure with universe , we show that the number of homomoprhisms which use at least one element of is .
Given any homomorphism , where , consider the homomorphism . This is still a homomorphism which is different from as there is some element such that for all , and so . On the other hand is just , as is a -automorphism. So acts as a permutation of order on the set . Moreover, the orbit of containing a homomorphism that has at least one element from in its range has size . ∎
The following statement is a straightforward implication of Lemma 2.2.
Proposition 2.3.
Let be a multi-sorted relational structure and a prime. Then for any relational structure it holds
We complete this section with a definition of polymorphisms. Let be a relation over a set . A -ary polymorphism of is a mapping such that for any choice of , it holds that (computed component-wise). The mapping is a polymorphism of a (single-sorted) relational structure if it is a polymorphism of each relation . In the multi-sorted case the definitions are a bit more complicated. Let be a multi-sorted relation. Instead of a single mapping we consider a family of mappings , . The family is said to be a polymorphism of if it satisfies the same condition: for any choice of , it holds that , only in this case the mapping is applied in the th coordinate position, . A polymorphism of a multi-sorted structure is again a family such that for each , (or rather its appropriate subfamily) is a polymorphism of . For a complete introduction into polymorphisms the reader is referred to [2].
The following special type of polymorphisms often occurs in the study of counting CSPs. For a set a mapping is said to be a Mal’tsev operation if for any it satisfies the conditions . In the multi-sorted case a family is Mal’tsev, if every is Mal’tsev. A Mal’tsev operation (or a family of operations) that is a polymorphism of a relation or a relational structure is said to be a Mal’tsev polymorphism of or . One of the useful properties of Mal’tsev polymorphisms is that it enforces the rectangularity of relations. A binary relation is rectangular if whenever it also holds that . If has a Mal’tsev polymorphism , it is rectangular. Indeed,
See Section 6 for further details.
2.2 The two views on the CSP
In the Introduction, we defined the CSP as the problem of deciding the existence of a homomorphism between two relational structures. From a technical perspective, however, a more traditional approach is often more useful.
Let be a (finite) set and a set of relations on . Such a set of relations is called a constraint language, and the set is often referred to as the domain.
The Constraint Satisfaction Problem is the combinatorial problem with:
Instance: a pair where is a finite set of variables and is a finite set of constraints. Each constraint is a pair where
-
•
is a tuple of variables from of length , called the constraint scope;
-
•
is an -ary relation, called the constraint relation.
Objective: Decide whether there is a solution of , that is, a mapping such that for each constraint with the tuple belongs to .
In the (modular) counting version of denoted () the objective is to find the number of solutions of instance (modulo ). We will refer to this definition as the standard definition of the CSP.
To relate this definition to the homomorphism definition of the CSP, note that for a -structure the collection of interpretations , , is just a set of relations, that is a constraint language over . Thus, for every relational structure there is an associated constraint language . Conversely, every (finite) constraint language can be converted into a relational structure such that in a straightforward way, although in this case there is much room for the choice of a signature.
It is well known, see e.g. [21] and [2] that the problems and can be easily translated into each other. The same is true for and . The conversion procedure goes as follows. Let be an instance of and is the signature of . Create an instance of by setting , the base set of , and for every and every , include the constraint into . The transformation of instances of to an instance of is the reverse of the procedure above. This transformation is clearly extended to counting CSPs, as well. In this paper we often use the standard definition of the CSP inside proofs assuming that an instance of or is given by variables and constraints.
The definition above can easily be extended to multi-sorted relational structures and languages. If is a multi-sorted relational structure, () asks, given a similar structure , whether there exists a homomorphism of multi-sorted structure to (asks to find the number of such homomorphisms). If is a set of multi-sorted relations, every variable for an instance of is assigned a type and for every constraint , the sequence must match the type of .
2.3 Expansion of relational structures
One of the standard techniques when studying constraint problems is to identify ways to expand the target relational structure or constraint language with additional relations without changing the complexity of the problem.
Let be a relational structure with signature and its expansion by adding a binary relational symbol interpreted as , the equality relation on . The following reduction is straightforward.
Lemma 2.4 ([12]).
For any relational structure and any prime , . Similarly, for a constraint language on the problem is polynomial time reducible to .
A constant relation over a set is a unary relation , . For a relational structure by we denote the expansion of by all the constant relations , . Theorem 2.5 was proved for exact counting in [8], for modular counting of graph homomorphisms in [20, 24, 25], and for general modular counting CSP in [12].
Theorem 2.5 ([12]).
Let be a -rigid -structure. Then is polynomial time reducible to .
For a -rigid constraint language on a set the problem is polynomial time reducible to .
Lemma 2.4 and Theorem 2.5 can be generalized to the multi-sorted case. Let be a multi-sorted structure with signature and its expansion by adding a family of binary relational symbols (one for each type) interpreted as the equality relation on , . A constant relation over a set is a unary relation , (such a predicate can only be applied to variables of type ). For a structure by we denote the expansion of by all the constant relations , .
Theorem 2.6 (see also [12]).
Let be a multi-sorted relational structure and prime.
(1) is Turing reducible to ;
(2) Let be -rigid. Then is Turing reducible to .
Yet another way to expand a relational structure is by primitive positive definable (pp-definable for short) relations. Primitive-positive definitions have played a major role in the study of the CSP. It has been proved in multiple circumstances that expanding a structure with pp-definable relations does not change the complexity of the corresponding CSP. This has been proved for the decision CSP in [31, 11] and the exact Counting CSP [8]. The reader is referred to [2] for details about pp-definitions and their use in the study of the CSP.
Conjunctive definitions are a special case of primitive positive definitions that do not use quantifiers. Let be a structure with signature . A conjunctive formula over variables is a conjunction of atomic formulas of the form , where is an (-ary) symbol and . A -ary predicate is conjunctive definable in if if and only if is true.
Lemma 2.7 ([12]).
Let be a relational structure with signature , be conjunctive definable in , and denote the expansion of by a predicate symbol that is interpreted as the relation in . Then .
Similarly, for a constraint language if a relation is conjunctive definable in , then .
We now extend the concept of primitive-positive definability to the multi-sorted case. Let be a multi-sorted relational structure with the base set . As before primitive positive (pp-) formula in is a first-order formula where is a conjunction of atomic formulas of the form or , , and is a predicate of . However, every variable in is now assigned a type in such a way that for every atomic formula it holds that , and for any atomic formula the sequence matches the type of . We say that pp-defines a predicate if there exists a pp-formula such that
For by we denote the number of assignments to such that is true. We denote the number of such assignments mod by .
While when is a graph it is possible to prove a statement similar to Lemma 2.7 for pp-definable relations [12], we will later see that it is unlikely to be true for general relational structures.
Finally, for a relational structure (single- or multi-sorted) denotes the relational clone of , that is, the set of all relations pp-definable in
3 Overview of the Results
The results of this paper can be grouped in two categories. The results from the first category analyse the methods used to obtain a classification of the complexity of modular counting CSPs over graphs, Theorem 1.2, [12], and the methods used in exact counting [5, 17, 13] trying to evaluate which of them are applicable for modular counting CSPs over general relational structures. Unfortunately, the majority of those methods fail, as we show by constructing a series of counterexamples. The second category comprises a number of results aiming at refining the framework, modifying the existing methods, and proposing new ones in order to overcome those difficulties. We now discuss the results in some detail.
3.1 The Failure
-rigidity. The classification result in Theorem 1.2 asserts that for a -rigid graph is hard whenever the exact counting problem is hard. In Example 5.1 we show that this is no longer the case for general relational structures. Let be a prime number and . A relational structure has the base set and predicates , where is the constant relation and . The structure is -rigid as it contains all the constant relations and every automorphism must preserve them, implying that every element of is a fixed point. By [6, 40] the decision is solvable in polynomial time, while the exact counting problem is P-complete by [8], as it does not have a Mal’tsev polymorphism and is not rectangular (see below). However, if is a structure similar to and there is a homomorphism such that some vertex of is mapped to then, unless is bound by , the mapping that differs from only at by sending it to any is also a homomorphism. Since , this means that the elements can be effectively eliminated from , and the resulting structure is somewhat trivial. Therefore can be solved in polynomial time.
Automorphisms of direct products. Another crucial component of Theorem 1.2 is the structure of automorphisms of direct products of graphs [29]. It essentially asserts that every automorphism of a direct product can be thought of as a composition of a permutation of factors in the product and automorphisms of those factors. In Example 8.2 we show that this breaks down already for digraphs. Indeed, let be a directed graph where with (directed) edge set . This digraph is rigid. However, the automorphism group of , see Figure 1, has a complicated structure. As is easily seen has a large number of automorphisms of order 2 and 3, not all of which have a simple representation mentioned above.
In [12] one of the important applications of the structural theorem for automorphisms of graph products is that it allows one to prove that , where denotes the expansion of by a relation pp-definable in , is polynomial time reducible to (see below). The example above indicates that this result may no longer be true for general relational structures.

Rectangularity, permutability, and Mal’tsev polymorphisms. The key properties of relational structures heavily exploited in [5, 17, 13] to obtain characterizations of the complexity of exact counting are rectangularity, balancedness, and the presence of a Mal’tsev polymorphism.
Recall that a binary relation is said to be rectangular if implies for any . A relation for is rectangular if for every , the relation is rectangular when viewed as a binary relation, a subset of . A relational structure is strongly rectangular if every relation of arity at least 2 is rectangular.
An -by- matrix is said to be a rank-1 block matrix if by permuting rows and columns it can be transformed to a block-diagonal matrix (not necessarily square), where every nonzero diagonal block with has rank at most 1.
Finally, let be a ternary relation,a subset of . We call balanced if the matrix , where such that and is a rank-1 block matrix. A relation of arity is balanced if every representation of as a ternary relation, a subset of , is balanced. A relational structure is called strongly balanced if every relation is balanced.
These three concepts are closely related and proved to be very useful for exact counting. It is well known [28] that strong rectangularity of a relation structure is equivalent to it having a Mal’tsev polymorphism. It is also straightforward that every balanced relation is rectangular. According to [17] is polynomial time solvable if and only if is strongly balanced. However, in order for the solution algorithm to work, it requires a Mal’tsev polymorphism to be applied over and over again to construct a frame, that is, a compact representation of the set of solutions, [5, 17]. As was observed above, pp-definitions do not quite work in the case of modular counting, and we introduce their modular counterparts by introducing modular quantifier (see below). Using modular pp-definitions, we can change the definitions of rectangularity and balancedness accordingly to obtain the properties of strong -rectangularity and -balancedness. These new properties require that every modular-pp-definable relation is rectangular and balanced. Modular-pp-definitions preserve the complexity of modular problems, however, they destroy the connections between the concepts above. In Section 6 we present a series of counterexamples showing that almost all the properties of -rectangularity, -permutability, -balancedness, and having a Mal’tsev polymorphism are independent of each other. While as we prove the first three properties are necessary for the tractability of the problem, the latter one does not follow from them, and therefore neither of -rectangularity, -permutability, -balancedness help to construct a solution algorithm in the same fashion it is done for exact counting.
3.2 Remedies
In the category of positive results we propose several ways to overcome the difficulties outlined in Section 3.1. We hope that these new approaches will lead to a complexity classification of modular counting.
Multi-sorted structures and -rigidity. We start with applying a well-known framework of multi-sorted relational structures to modular counting. While multi-sorted structures is a standard tool in the study of decision CSPs, it usually only used to simplify arguments and streamline algorithms. Here we use this framework in a more fundamental way, to strengthen the main (hypothetical) tractability condition.
Let us consider again the structure introduced in the beginning of Section 3.1 and discover that when considered as a multi-sorted structure is not -rigid, and therefore can be transformed so that the corresponding modular CSP is solvable in polynomial time. The idea is, given an instance of , to use some preprocessing algorithm (such as local propagation or a solution algorithm for the decision CSP) to reduce possible range of vertices from under homomorphisms. We then refine the instance by replacing with a multi-sorted structure in such a way that every possible range of a vertex from becomes a set of a distinct type. Now, since automorphisms of a multi-sorted structure may act differently on different types, the refined structure may have a richer automorphism group. For instance, for the refinement of the sets and have different types, and an automorphism of such a structure may act differently on these sets and no longer has to have as a fixed point when acting on .
We identify several ways how a refinement of a structure or an instance can be constructed and prove that these constructions are parsimonious reductions between modular CSPs. We are not aware of any example of a refined -rigid structure whose complexity differs from that for exact counting.
Modular existential quantifiers. We follow the approach of [12] by expanding the relational structure by adding pp-definable relations, but doing in a manner friendly to modular counting.
We introduce a new form of expansion which is using -modular quantifiers instead of regular existential quantifiers. The semantics of a -modular quantifier is ”there are non-zero modulo values of a variable” rather than ”there exists at least one value of a variable” as the regular existential quantifier asserts. The new concept gives rise to new definitions of pp-formulas. If regular existential quantifiers in pp-formulas are replaced with -modular quantifiers, we obtain -modular primitive positive formulas (-mpp-formulas, for short). The -modular quantifier is denoted , and so -mpp-formulas have the form
Note the more complicated form of the quantifier prefix: modular quantification is not as robust as the regular one and quantifying variables away in groups or one-by-one may change the result. For example, let be a relation on . Then formulas and define sets and , respectively.
Every relational structure is associated with a relational clone that consists of all relations pp-definable in . Then, similar to pp-definitions, a relation is said to be -mpp-definable in a structure if there is a -mpp-formula in expressing . The -modular clone associated with is the set of all relations -mpp-definable in . Similar to the result of Bulatov and Dalmau [8], expanding a structure by a -mpp-definable relation does not change the complexity of the problem .
Theorem 3.1.
Let be a be a -structure with equality, and a prime. Let be a relation that is defined by
then is polynomial time reducible to .
An algorithm for parity. The next two results identify a number of conditions under which it is possible to design an algorithm or to prove the hardness of the problem. One such case is when satisfies both the 2-rectangularity and the usual strong rectangularity conditions (or, equivalently, has a Mal’tsev polymorphism). Note that the case is special and the concepts of 2-rectangularity and 2-balancedness are equivalent as Lemma 6.4 states. This comes very handy, because it allows us to avoid rectangular but not balanced relations that require a completely different approach. Some sense of what it might require can be seen in [18, 13].
The other ingredient that we use to develop the algorithm for determining the parity of solutions for CSP is the use of frames. A frame for a relation is defined as a subset that satisfies two conditions. Firstly, if includes a tuple where the -th component is , then must also include at least one such tuple. Secondly, for , consider a set . We say is -equivalent in if has tuples that agree on their first components and whose -th components form exactly the set . Any set that is -equivalent in must also be -equivalent in , though may have fewer tuples sharing these common prefixes compared to . It is demonstrated in [17] that every -ary relation over such that has Mal’tsev polymorphism, has a compact frame of size at most , despite potentially having up to elements. Additionally, we provide a method for constructing such a frame efficiently and describe how to reconstruct the strongly rectangular relation from any of its frames.
We apply the known techniques [7, 17] to find a concise representation or a frame of the set of solutions of a given CSP. In order to do that we consider the set of solutions of a (decision) CSP instance with variables as an -ary relation . First of all the algorithm finds a frame for using the existing techniques [7].Then it looks for a frame for the relation consisting of the tuples from that have odd number of tuples from . This requires careful filtering of tuples obtained from the original frame. This filtering step is the main novelty brought by our algorithm. The procedure then repeats reducing the arity of ever further. The key property of this procedure is that the parity of equals that of . Once reduced to a unary relation, determining the parity becomes strightforward.
Theorem 3.2.
Let be a 2-rigid, strongly 2-rectangular, and has Mal’tsev polymorphism111Note that the latter condition does not follow from having a Mal’tsev polymorphism, because 2-mpp-definitions do not preserve polymorphisms, as we show in Section 6.. And let be an -ary relation. Then can be solved in time .
Automorphisms of direct products of structures. In Section 8 we explore what implications of a structural result similar to that in [29] that is used in [12] about can be. A rectangularity obstruction is a violation of the rectangularity or -rectangularity property, that is, a (-ary) relation pp- or -mpp-definable in a structure , , and tuples such that , but . A generalized rectangularity obstruction are the relation and sets , such that , , and any form a rectangularity obstruction.
At the first glance, if such an obstruction exists, it should be possible to prove the hardness of . Indeed, can be viewed as a bipartite graph , whose parts of the bipartition are and , and as the rectangularity obstruction shows, this graph is not complete bipartite implying that is #P-complete. However, the hardness of also involves the requirement that is -rigid. -rigidity is achieved by restricting the problem to induced subgraphs of . However, such a subgraph may avoid the (generalized) rectangularity obstruction rendering it useless.
The obstruction , is said to be protected in if, after applying a -reduction to under a sequence of -automorphisms from , for the resulting relation it holds that , . In fact,Theorem 4.2 [12] implies, although implicitly, that any -rigid graph that is not a complete bipartite graph contains a protected rectangularity obstruction. One case of a protected rectangularity obstruction is when it is protected in , that is, survives -reductions of itself. In this case we say that the obstruction is graph-protected.
Proposition 3.3.
Let be a (multi-sorted) relational structure and a prime number. If has a graph protected generalized rectangularity obstruction modulo , is -complete.
We consider a special case of graph-protected generalized rectangularity obstructions, standard hardness gadgets, that have to satisfy the additional condition . It is proved in Section 8.2 that a standard hardness gadget is indeed a graph-protected obstruction.
Standard hardness gadgets provide a fairly limited condition for the hardness of . In fact, it is possible to prove that is -complete whenever has any protected rectangularity obstruction, not necessarily a standard gadget. However, it cannot be done using Theorem 1.2 as a black box, and is outside of the scope of this paper.
Binarization. While studying the structure of for a relational structure and an integer may be a difficult problem, in Section 9 we make a step forward by reducing the class of structures for which such a characterization is required. In particular, we show that it suffices to obtain a characterization for structures with only binary rectangular relations. More precisely, for any relational structure we construct its binarization as follows. The structure is multi-sorted, and the domains are the relations viewed as sets of tuples, thus, has domains. For every pair ( are allowed to be equal) and any , where are the arities of , the structure contains a binary relation . We prove that and share many important properties.
Theorem 3.4.
Let be a relational structure. Then is strongly rectangular (-strongly rectangular, -rigid, has a Mal’tsev polymorphism) if and only if is strongly rectangular (-strongly rectangular, -rigid, has a Mal’tsev polymorphism).
In addition to Theorem 3.4 every relation of is binary and rectangular. This makes such structures somewhat closer to graphs and the hope is that it will be easier to study the structure of than itself.
4 Modular primitive-positive definitions
In this section we modify the concept of pp-definitions in such a way that adding a definable relation does not change the complexity of the modular counting problem. We start with introducing a different type of quantifier. For a prime number the -modular quantifier is interpreted as follows
(1) | ||||
Note that modular quantifiers are not as robust as regular ones, and the result may depend on whether variables are quantified in groups or one by one, as the following example shows. We will allow quantifiers both ways.
Example 4.1.
Let . Then the formula defines the set , since in every step the number of extensions is not divisible by 3. However, the formula results in the set .
A primitive positive formula that uses modular existential quantifiers mod instead of regular ones is call a -modular primitive positive. the relation it defines is said to be -mpp-definable, and the definition itself is called a -mpp-definition. If for the -mpp-definition (1) for all , the -mpp definition is said to be strict. By Proposition 5.6 from [12] if has a -mpp-definition, it has a strict -mpp definition.
Finally, we show that adding -mpp-definable relations also does not change the complexity of a CSP.
Lemma 4.2.
Let be a multi-sorted relational structure with signature , be conjunctive definable in , and denotes the expansion of by the predicate symbol that is interpreted as the relation in . Then .
Proof.
Let be defined by a conjunctive formula
where and for all . We use the standard definition of the CSP. Let be an instance of . If contains a constraint of the form , replace it with constraints . As is easily seen, the resulting instance has exactly the same solutions as . Repeat this procedure while constraints containing remain. The resulting instance has the same solutions as , and is an instance of . ∎
Theorem 4.3.
Let be a be a -structure with equality, and a prime. Let be a relation that is defined by
then is polynomial time reducible to .
Proof.
Without loss of generality we may assume that the -mpp-definition of given in the theorem is strict. We use the standard definition of the CSP.
Take a problem instance of where . Without loss of generality we may assume that , , are the constraints containing . Then the arity of is for .
Let be the problem instance from in which each constraint is replaced with formula where all the variables are different and do not occur in .
For a solution to , as for every , is true, can be extended to a solution of . Since the -mpp-definition of we use is strict, the number of such extensions is equal to . Therefore, the number of solutions of and that of are equal . The result follows. ∎
For a structure the set of all relations pp-definable in is called the relational clone of and denoted by . The set of relations -mpp-definable in is called the modular clone and denoted by .
5 Rigidity
Rigid graphs and rigid structures
Recall that the group of automorphisms of a multi-sorted structure is denoted by . An automorphism has order if every component of has order or is the identity permutation, and at least one of the components has order . Relational structures without order automorphisms are called -rigid. By the result of [12] if is a -rigid graph then is polynomial time if and only if is. The following example shows that it is not the case for relational structures.
Example 5.1.
Fix a prime number and let . A relational structure has the base set and predicates , where is the constant relation and . The structure is obviously -rigid as it contains all the constant relations. By [6, 40] the decision is solvable in polynomial time, while the exact counting problem is P-complete by [8], as it contains an induced subgraph (or subrelation) (or alternatively it does not have a Mal’tsev polymorphism). In fact, structures like play a very important role in proving that having a Mal’tsev polymorphism or avoiding induced subgraphs as above is a necessary condition for the tractability of , see [8]. We now show that can be solved in polynomial time.
We outline the idea of the algorithm here and later will describe a more general algorithm. Let be an instance of . Perform the following three steps:
Step 1. Establish the arc-consistency of . That is, repeat the following procedure until no changes are possible. Pick constraints such that and a tuple . If there is no tuple such that , remove from .
Step 2. For every variable there is now a domain such that, for any with , it holds that . If for some , output 0, as has no solutions in this case. Otherwise remove all the variables from such that . Denote the resulting problem . The number of solutions to equals that of .
Step 3. It is not difficult to see that if for some variable then . Moreover, if is a solution of and , then any mapping such that and , , is also a solution of . For every such variable remove from , as the number of solutions to with is a multiple of . Then repeat Step 2.
Step 4. In the remaining case for every . It is not difficult to see that any mapping from to is a solution of . Therefore, output .
Refining multi-sorted structures
In this subsection we introduce a different concept of rigidity that is stronger than the one used before. In particular, it will explain the tractability of the problem from Example 5.1.
While Lemma 2.2 allows one to reduce CSPs over non--rigid structures, it is sometimes possible to go further and reduce a CSP to one with a richer structure, and a richer set of automorphisms. Let be a multi-sorted relational structure. We say that a structure is a refinement of if it satisfies the following conditions:
-
(a)
, where the ’ are pairwise disjoint,
-
(b)
for every , there is an injective mapping for some ,
-
(c)
for every there is with and , where such that .
Condition (a) is required because the domains of a multi-sorted structure have to be disjoint. Condition (b) basically says that consists of copies of some elements of . Condition (c) amounts to saying that , except it uses copies of the elements of . In the notation of item (c) we use to denote , we use to denote , and for .
It is possible that while is -rigid, its refinement is not and Lemma 2.2 may apply.
Example 5.2 (Continued from Example 5.1).
Consider the structure from Example 5.1. Let for , , and . For convenience we use to denote . The mappings simply erase dashes and stars of elements from . Then for every we introduce relation . For instance, . Also, by construction the only constant relations needed to be introduced are on for . The structure
is a refinement of . Therefore the structure is not -rigid, as the collection of mappings , , defined as follows is an automorphism. The mappings are identity mappings. The mapping is given by , and for . Finally, is the restriction of on (we stars added to the elements of ).
In order to relate refinement structures with reductions between counting problems we introduce two special types of refinement. First of all, we will need an alternative approach to pp-definitions based on homomorphisms, see [21, 35].
Lemma 5.3.
A predicate is pp-definable in a multi-sorted structure containing the equality predicate if and only if there exists a similar structure containing vertices such that for any it holds that if and only if there is a homomorphism from to that maps to , . We will say that defines in .
Let be a multi-sorted relational structure. The Gaifman graph of is the graph , where and if and only if there is and such that for some coordinate positions of . The structure has treewidth if has treewidth .
We say that a refinement of is width definable if for every there is a structure of treewidth at most that defines in . In a similar way, we say that is a definable refinement if for every the set is pp-definable in . Finally, we say that is the full width definable refinement (respectively, full definable refinement) if it satisfies the following conditions.
-
(1)
It is a width definable refinement (respectively, a definable refinement).
-
(2)
For every unary relation definable in by a structure of treewidth at most (respectively, pp-definable unary relation) there is such that .
-
(3)
For every relation obtained from some relation by restricting it to domains definable by structures of width (respectively by pp-definable domains), there is such that .
Since the original domains , , have trivial pp-definitions, they (or rather their copies) are always among the ’s, and copies of the original relations are also among the ’s, although they may be over different, smaller domains than the ’s.
Next, we extend refinements to CSP instances. Let be a refinement of and an instance of . Recall that every variable is assigned a sort . Let be such that for each . The instance is said to be a refinement for of with the sort function if it satisfies the following two conditions
-
(a)
every is assigned the sort ;
-
(b)
for every , , it holds that , , and there is .
The refinement is lossless if for every solution of the mapping is a solution of . Suppose is full pp-definable. The refinement is minimal lossless if it is lossless and for each , is minimal (with respect to inclusion of in the original domain). If is full of treewidth , the definition is bit more complicated. As we saw in Section 2.2, the instance can also be viewed as a structure with vertex set and such that the solutions of are exactly the homomorphisms from to . Then is minimal lossless of width if it is lossless and for every , is minimal with respect to inclusion among unary relations defined by a structure of treewidth with a designated variable and such that there is a homomorphism from to mapping to .
Proposition 5.4.
Let be a multi-sorted relational structure.
(1) Let be the full width definable refinement of . For any instance of , its minimal lossless refinement of width for can be found in polynomial time.
(2) Let be a relational structure containing all the constant relations and such that is solvable in polynomial time, and the full definable refinement of . Then for any instance of , its minimal lossless refinement for can be found in polynomial time.
Proof.
The method we use in the proof of this proposition is, given an instance of , to, first, identify the correct domains for each variable, and then restrict to those domains and assign to each variable the type associated with its domain.
(1) In this case we first run the -consistency algorithm on (for definitions and properties of this algorithm see [21, 35]). This reduction is lossless. Let denote the domain of after establishing -consistency. By the results of [21, 35] every domain is definable by a structure of treewidth at most and is minimal with this property. Therefore, each is a domain of .
(2) By solving instances of the form for each and from the domain of we can determine the sets . Since the ’s are defined through a CSP instance, they are pp-definable in , and therefore every is a domain in . We assign the corresponding type. Clearly, the refinement is lossless and minimal. ∎
Example 5.5 (Continued from Example 5.1).
Consider again the structure from Example 5.1 and its refinement from Example 5.2 to solve . It is not hard to see that is the full refinement of of treewidth 1. Indeed, the set , , is defined by the pp-formula , and
Therefore, by Proposition 5.4 is polynomial time reducible to . As was observed in Example 5.2, the structure has an automorphism of order . The reduced structure has the domains unchanged, reduced to , reduced to , and all the relations are Cartesian products of the corresponding domains. Such a problem is obviously solvable in polynomial time.
6 Maltsev polymorphisms, -Rectangularity, and -Permutability
The concepts and results from this section can be generalized to multi-sorted structures. However, the single-sorted case is sufficient to communicate the main ideas.
6.1 The four properties
We use four properties of relational structures that are strongly related to the complexity of counting problems.
Mal’tsev polymorphisms. Let be a set. A mapping is said to be a Mal’tsev polymorphism of a relation if for any , it holds that (applied component-wise), and satisfies the equations , for all . We say that the relational structure has Mal’tsev polymorphism if all relations admit the same Mal’tsev polymorphism. Similarly, we say that the relational structure has Mal’tsev polymorphism is all relations admits to the same Mal’tsev polymorphism.
Let be an -ary relation over . In general can be exponentially large in . However if has a Mal’tsev polymorphism, admits a concise representation, linear in . Bulatov and Dalmau [7], and Dyer and Richerby [17] introduced slightly different concepts of such concise representations called “compact representation” in [7] and “frames” in [17]. We will return to these constructions in Section 7.
-Rectangularity. A binary relation is called rectangular if implies for any . A relation for is rectangular if for every , the relation is rectangular when viewed as a binary relation, a subset of . Note that rectangularity is a structural property, and it has nothing to do directly with the size of the relation or its parts. A relational structure is strongly rectangular if every relation of arity at least 2 is rectangular. The following lemma provides a connection between strong rectangularity and Mal’tsev polymorphisms and was first observed in [28] although in a different language.
Lemma 6.1 ([28], see also [17]).
A relational structure is strongly rectangular if and only if it has a Mal’tsev polymorphism.
We introduce a modular version of this concept, strongly -rectangular relations. A relational structure is said to be strongly -rectangular, if every is rectangular. The following example shows that a relational structure can be strongly rectangular, but not strongly -rectangular.
Example 6.2.
Let , , and , where is the following ternary relation, . As is easily see, is the relation , which is not rectangular, and so, is not strongly 2-rectangular. We now show that is strongly rectangular by presenting a Mal’tsev polymorphism of . Let , where addition is modulo 2. For , let also denote the triple obtained by replacing 2’s with 1’s. Then let be given by
It is straightforward that is a Mal’tsev operation and is a polymorphism of .
-Balancedness. An -by- matrix is said to be a rank-1 block matrix if by permuting rows and columns it can be transformed to a block-diagonal matrix (not necessarily square) such that every nonzero block has rank at most 1.
Let be a ternary relation, a subset of . We call balanced if the matrix , where such that and is a rank-1 block matrix. A relation of arity is balanced if every representation of as a ternary relation, a subset of is balanced. A relational structure (a constraint language ) is called strongly balanced, if every at least ternary relation () is balanced.
The following lemma relates rectangularity and balancedness.
Lemma 6.3 ([17], Lemma 29,30).
Strong balancedness implies strong rectangularity, but strong rectangularity does not imply strong balancedness.
Let be a ternary relation on . The relation , is -balanced if the matrix given by
(2) |
for and , is a rank-1 block matrix (the rank is computed in ). A relation on of arity is -balanced if every representation of as a ternary relation, a subset of , is -balanced. A relational structure (a constraint language ) is called strongly -balanced if every relation () is -balanced.
The case is somewhat special.
Lemma 6.4.
A relational structure is strongly 2-rectangular if and only if it is strongly 2-balanced.
Proof.
Suppose that contains a non-rectangular -ary relation . Since is closed under renaming coordinates, we may assume that for some there are and such that , but . Consider the relation
Clearly, . For the matrix constructed for and we have and , showing that is not rank-1 block matrix.
Conversely, suppose that an -ary relation is not -balanced, that is, for some the matrix is not rank-1 block. Since the entries of are from , it means that for some and , it holds that and . Therefore, the tuples have an odd number of extensions to a tuple from , while has an even number of such extensions (including 0). Therefore the relation
belongs to and is not rectangular. ∎
-Permutability. A congruence of a relational structure is an equivalence relation on that is definable by a pp-formula in . More generally, let be a -ary relation. A congruence of is a -ary relation pp-definable in that is an equivalence relation on . We denote the set of all congruences of (of ) by (respectively, by ). By we denote the product of binary relations: if and only if there is such that and . We say is congruence permutable if for all , where , it holds that .
Congruence -permutability is defined as follows: A -congruence of or of is an equivalence relation on or , respectively, that is -mpp-definable in . We denote the set of all -congruences of () by (). By we denote the product of binary relations: if and only if the number of elements such that and is not a multiple of . We say that is congruence -permutable if for all , where , we have . In other words, for any , if the number of tuples such that is not equal to , then so is the number of elements with .
The regular versions of strong rectangularity, congruence permutability, and the existence of Mal’tsev polymorphism are known to be equivalent.
Proposition 6.5 ([28], see also [17, 5]).
For a relational structure the following are equivalent:
(1) has a Mal’tsev polymorphism;
(2) is strongly rectangular;
(3) is congruence permutable.
For the modular versions of the same properties the picture is much more complicated.
6.2 Contrasting Properties: Modular vs. Exact Counting.
Although Proposition 6.5 provides significant insights for exact counting, we encounter a minor implication when considering the modular condition. The following lemma represents the only connection between these notions.
Lemma 6.6.
If is congruence -permutable, then it is strongly -rectangular.
Proof.
Suppose is congruence -permutable and consider a -mpp-definable relation . We need to show that is -rectangular. Define a relation by if and only if . This relation is -mpp-definable in , by
It is easy to check that this is also an equivalence relation and its equivalence classes correspond to tuples .
Hence it is a congruence of . In a similar way, define a congruence on by if and only if . Let .
Suppose . Then there exists such that and . Thus, and . Therefore, . Now, congruence -permutability implies that . Hence . Thus, there exists such that and . Thus, and . Therefore, . The strong -rectangularity follows. ∎
To demonstrate the lack of connection between Maltsev polymorphism, rectangularity, and permutability in the modular case, we present three examples.
Example 6.7.
Let . We define a relational structure over the set with the following relations:
-
•
All constant relations for all ,
-
•
The equivalence relation with equivalence classes and ,
-
•
The equivalence relation with equivalence classes and .
The structure is -rigid due to the presence of all constant relations. It is not congruence -permutable, since but . We now show that is strongly -rectangular.
Suppose an -ary , , and witness that is not rectangular, that is, , but . Consider a 2-mpp-definition of
Note that all the equivalence classes of and except for contain 2 elements. This means that as is odd, it has to be that is true. The same holds for , but is false. This is however impossible. Indeed, as all the predicates of of the form , and are true on (in the former two cases due to the rectangularity of ), it has to be that is false implies that some predicate or is false. Suppose and is false. This means that is false, which contradicts the assumption is true.
Example 6.8 (Example 6.2 re-stated).
Let , and , where is the ternary relation defined as
The constants correspond to respectively. Thus, is 2-rigid.
Example 6.9.
Let . We define a relational structure over the set with the following relations:
-
•
All constant relations for all ,
-
•
The equivalence relation with equivalence classes and ,
-
•
The equivalence relation with equivalence classes and .
The structure is -rigid due to the presence of all constant relations. According to Proposition 6.5, it does not have a Mal’tsev polymorphism because is not rectangular. We only need to demonstrate that it is congruence 2-permutable. By Lemma 6.6, this would imply that is also strongly 2-rectangular. Observe that and , and , and are interchangeable. That is, if such that , , and , where , then for all , unless . Now, let and be congruences of . Then
By the simple fact stated earlier, for any , the number of extensions is always even which is zero modulo . Hence, , unless .


7 An Algorithm for Parity
In this section we show how to solve for a relational structure that is 2-rigid, strongly 2-rectangular, and has a Mal’tsev polymorphism . Observe that an instance of can be viewed as a conjunctive formula over , and the set of solutions is a conjunctive definable relation from . Therefore, problem we solve is, given a conjunctive definition of a relation , find the parity of the number of elements in .
The main idea is to reduce the arity of . In other words, we attempt to find a relation , still 2-mpp-definable in , such that and . To accomplish this, we use witness functions first introduced in [17].
7.1 Frames and Witness Functions
Suppose that is an -ary relation with a Mal’tsev polymorphism . For each we define the following relation on : if there exist tuples and such that . For the case , we have for all because they share the common empty prefix . The following two results are straightforward corollaries of the rectangularity of and were used in [17].
Lemma 7.1 (Folklore).
is an equivalence relation for all .
Let denote the collection of the equivalence classes of , and , , where . We often refer to these classes as Frame Classes.
Lemma 7.2 (Folklore).
If and with , then there is a with and .
A mapping is called a witness function of if
-
i.
For any and , ;
-
ii.
For any and , is a witness for , i.e., ;
-
iii.
For any and with , we have .
A witness function provides a concise representation of . Let . Such a set of tuples is called a frame of . A witness function (or a frame) can be found in polynomial time given a conjunctive definition of a relation in a relational structure with a Mal’tsev polymorphism. This is the property that makes them essential for solving CSPs.
Proposition 7.3 ([17]).
Let be a relational structure. If has a Mal’tsev polymorphism, then the witness function for the relation can be computed in .
We will also use other algorithmic properties of frames.
Proposition 7.4 ([17]).
Given a frame for , a frame for , i.e., , , is the constant , can be constructed in time.
We denote the relation by , its relations by , its Frame Classes by , and its witness function by .
Proposition 7.5 ([17]).
Let . Given a frame for , a frame for , i.e., is the constant , can be constructed in time.
Lemma 7.6.
Let , . For all , if , then .
Proof.
The proof is straightforward from the definition. Suppose . Then, there exist and such that and . By the definition, . ∎
7.2 The Algorithm
In order to find as explained in the beginning of Section 7 we use a witness function and frame of to compute a frame and witness function of . If we can find such a , we repeat this process for times. Eventually, we obtain , whose cardinality can be easily found.
First, we assume that the witness function for and is given. We prove we prove the following.
Theorem 7.8.
Let be a 2-rigid, strongly 2-rectangular, has Mal’tsev polymorphism , and let be an -ary relation. Given a frame and a witness function for , the parity of can be computed in time.
In Section 7.2.2, we demonstrate an efficient method to compute the witness function in . Consequently, the main outcome of this section is summarized as follows:
Theorem 7.9 (Theorem 3.2 re-stated).
Let be a 2-rigid, strongly 2-rectangular, and has Mal’tsev polymorphism. And let be an -ary relation. Then can be solved in time .
7.2.1 Auxiliary relations
We define the following relation as a tool in out proofs. For , let be defined as follows:
(3) |
Note that the relation is 2-mpp-definable in . Thus, , and it is rectangular. Also, note that the second part of the conjunct expresses the fact that the number of extensions of should be odd. Hence, if and only if and has an odd number of extensions, i.e., .
Lemma 7.10.
Let . Then .
Proof.
We start by defining the indicator function as follows:
Now, we start by calculating the size of as it is shown below. Recall that denotes the relation defined by .
The first and second equalities are trivial by the definition of the function . The third equality holds because for a
This equation indicates that the number of extensions of to a tuple from the -ary relation is determined by appending each possible to and verifying whether belongs to . The forth equality is true, because we can split all into two disjoint sets. One with odd number of extension, and the other with even number of extension. Then, the first equivalence hold, because if and , then, . Finally, the last equivalence is valid, because if and only if . ∎
Now, we can give another equivalent definition of , different from the on in the beginning Section 7, that is easier to work with. We define the relation as follows:
(4) |
Note that the relation is 2-mpp-definable in . Thus, , and it is rectangular. Also, by the definition of , if and only if has odd number of extensions into . Therefore, the following lemma is straightforward.
Lemma 7.11.
Let . Then, .
Proof.
We have that if and only if there exists such that . Furthermore, by the definition of , it means has an odd number of extensions to a tuple from , which is equivalent to having an odd number of extensions to a tuple from . In other words, belongs to . The result follows. ∎
Lemma 7.12.
Let . Then .
Proof.
We start by calculating the cardinality of as it is shown below:
The first equality is straightforward. The second equality is true as it follows directly from the definition of the relation : if and only if has odd number of extensions, if and only if there exists such that . The first congruence holds because if and only if . The second congruence is valid because has odd number of extensions, hence should belong to . ∎
Proof of Theorem 7.8.
Our goal is to reduce the arity of from to step by step while keeping the parity of unchanged. To achieve this, we define and for . By applying Lemma 7.10 and Lemma 7.12 to , we can compute the witness function of denoted by for . We get the following congruences:
We can compute the cardinality of since we have its witness function by Theorem 7.15. We simply check if for each . Note that this process, just take times, not considering the complexity of calculating witness function.
∎
7.2.2 Calculating witness function for
In this subsection, we show how to calculate a frame, the frame classes, and a witness function for , which we denote as , , and , respectively. Since is rectangular, we can consider its frame and witness function, denoted as and . Suppose we have already calculated the frame and witness function for . By applying Lemma 7.11 and Proposition 7.7, we can obtain a witness function and frame for in time.
To calculate a witness function for , we will use several auxiliary lemmas. Once we have a witness function for , we can proceed with calculating a witness function for .
Lemma 7.13.
Let where and . If there exists such that and , then .
Proof.
We need to calculate the number of extensions of .
The first and second equalities are straightforward, as they follow directly from the definition of the function . The third equality holds because we can partition the set into equivalence classes given by the frame . The fourth equality is valid because the relation is rectangular, and so can be extended to only one class . Since there exists such that , the number of extensions of should be the cardinality of . As , the number of extensions of is modulo . Therefore, . ∎
Lemma 7.14.
Let , , and be such that and . We can check in if , where is the frame equivalence of .
Proof.
As , we know that is rectangular. Therefore, if and , then . This implies the existence of an extension such that . According to Lemma 7.13, we can check if by verifying if belongs to an class of with odd cardinality.
We begin by defining the relation as follows:
Essentially, is the same as with its first coordinates fixed to the corresponding coordinates of , and the th coordinate fixed to . We can compute the witness function and frame classes of using Proposition 7.5, with a time complexity of . We denote the resulting frame classes as . Next, we check if there exists such that . If such a exists, then by Lemma 7.6 and Lemma 7.13, we can conclude that .
Note that this process requires only time to compute the witness function for , and then time to detect whether there exists such a . Therefore, the overall time complexity of the algorithm is .
Note that if the algorithm returns for the input and , then it follows that and . This is because, in line (4) of the algorithm, is set to be and we know that and , as per the definition of . ∎
Theorem 7.15.
can be computed in time .
Proof.
At the first step, we calculate the witness function and frame for . Using Proposition 7.7 and Lemma 7.11, we can then compute the witness function and frame for .
In order to compute , we first need to compute for all . This step is relatively simple. Since if and only if there exists such that , we can check whether . By Lemma 7.13, if and only if where and . Clearly, if , then . Therefore, we can set if , and if . Note that this step only takes time, since is already given to us.
Let . According to Proposition 7.4, we can compute and in time. Next, we examine for . We check whether there exists an such that . If we find such an , we select and set . Otherwise, we assign . Note that searching for only requires time since we only need to look up , which is less than .
Since , it follows that . Also, because of the way we construct and Lemma 7.13, we have that .
Next, we use Algorithm for all to derive the equivalence relation defined by for the th coordinate. If the algorithm returns , it means that and they are in the same class. Therefore, we set . Otherwise, . We repeat this process for each whose witness function has not yet been associated with anything, and at the end, we will have the witness function for . By Proposition 7.7, we will have the witness function for .
∎
Remark 7.16.
Note that at no point the algorithm explicitly uses condition 2-rigidity, although it is among the conditions of Theorem 7.8. However, it uses constant relations in a very essential way, they are used to compute the witness function and frames. In general relational structures, the availability of constant relations is not guaranteed. However, by Theorem 2.6, we can add constant relations to if is 2-rigid.
8 Hardness and Automorphisms
An important ingredient of the complexity classification of for graphs [12] is the structure of automorphisms of graph products, see [29] for non-bipartite graphs and [12] for bipartite graphs. We compare the situation for relational structures with the result for non-bipartite graphs stated below.
8.1 Automorphisms of structures and automorphisms of products
Let be a graph. The graph is said to be -thin if it does not have twin vertices, that is, vertices with equal neighbourhoods. The graph is prime if for any representation one of is a 1-element graph. A representation is said to be prime factorization of of if all the ’s are prime.
Theorem 8.1 ([29], [12]).
Let be a prime factorization of a connected -thin non-bipartite graph , where for , we have . Then for any automorphism of , there is a permutation of such that can be split into automorphisms:
for , is an isomorphism from the th copy of to the th copy of .
As the following example shows, an analogous result is not true for relational structures.
Example 8.2.
Let be a directed graph where with directed edges noted as pairs . If we study the as a relational structure, then it is 2-rigid. However, the automorphism group of has a complicated structure. As it can been seen in the Figure 3, has the following automorphism: , and otherwise. This automorphism cannot be represented given in Theorem 8.1.

8.2 Rectangularity obstruction
One of the implication of Theorem 8.1 is that some subsets from survive -reductions by automorphism of order . We explore what the existence of such sets entails.
Let be a (multi-sorted) relational structure with base set , , and . A subset is called protected in if, after applying a -reduction to under a sequence of -automorphisms from , the subset remains non-empty. Formally, is protected if for any sequence of automorphisms , the image of under the -reduction remains non-empty:
A rectangularity obstruction in a relational structure is a violation of the rectangularity or -rectangularity property. Let be an -ary relation that is either pp-definable or -mpp-definable in . For some , let and . The relation together with the triple is a rectangularity obstruction if and . A generalized rectangularity obstruction are the relation sets , such that , , and any form a rectangularity obstruction. A rectangularity obstruction is protected if each of the sets is protected in . A generalized rectangularity obstruction , is protected if each of the sets is protected in .
A special case of a generalized rectangularity obstruction is a standard hardness gadget. For a relational structure , a standard hardness gadget is a tuple such that
-
•
, , -mpp-definable in , i.e., ;
-
•
for some , , are non-empty;
-
•
, and ;
-
•
, and ;
-
•
for all and , ;
-
•
for all and , ;
-
•
for all and , .
Thus, a standard hardness gadget is a generalized rectangularity obstruction with the extra condition , .
By the definition of a standard hardness gadget, the following lemma is straightforward.
Lemma 8.3.
Let for . Then, if there exists such that , then . Also, let for . Then, if there exists such that , then .
For a standard hardness gadget we have the following.
Proposition 8.4.
Let be a -rigid relational structure. If there exists a standard hardness gadget for , then is -complete.
In order to prove Proposition 8.4, we use the hardness of counting graph homomorphisms modulo prime numbers, as provided by Theorem 1.2. We specifically, use it for the case of bipartite graphs, in which case homomorphisms also preserve the left and right side of the partitions of the graphs.
We define the bipartite graph using the hardness gadget as follows:
-
•
,
-
•
,
-
•
.
In order to streamline the notation, we define a mapping from to by . It is straightforward to observe that is bijective.
Based on the definition of , we can define the sets for . Note that, by the definition of a standard hardness gadget, .
Before proceeding further, we introduce some notation regarding graphs. Let the neighbor set of a vertex in a graph be defined as . We say that graphs and (with a distinguished vertex) are isomorphic if there is an automorphism of mapping to . The following lemma is straightforward.
Lemma 8.5.
Let be a graph and . The graphs and are isomorphic if and only if .
Lemma 8.6.
Let and where . Then, and .
Proof.
We prove the lemma only for the case of the set . The proof for the remaining sets is similar. Let , then . Let . Thus, by the definition of , . By Lemma 8.3, . So, , therefore . Hence, by Lemma 8.5, .
Let , by the definition of , if and then there exists such that , but . Hence, by Lemma 8.5, . ∎
We need one more ingredient before proving Proposition 8.4. We need to show that the -reduced form of is not trivial. Let be an automorphism of such that for all and it is a permutation on . Since is protected, any -automorphism on has a fixed point. Let denote the set after removing all automorphisms of order from . Clearly . Thus, the reduced form is not trivial, and in fact, based on the properties of , it is not a complete bipartite graph.
Thus, the following lemma can be concluded by Theorem 1.2.
Lemma 8.7.
The problem is -hard.
Now, we are ready to prove the key lemma of this section.
Lemma 8.8.
Let have a standard hardness gadget . Then .
Proof.
Let be an instance of the problem . We define the following instance of . Note that in this instance, we only use the -mpp-definable relation from the standard hardness gadget.
-
•
For each , we define .
-
•
For each , we define .
-
•
.
-
•
For each , define .
We show that each solution for gives rise to a homomorphism from to . Let be a solution for , then . For all , set , and for all , set . Clearly, if , then since is a solution for .
Conversely, let be a homomorphism from to . Define the following solution for : . Since , if , then . Note that are nodes in . So, we can apply the reverse mapping of . Hence, we will have . Thus, is also a solution for .
Therefore, the number of solutions of in is the same as the number of solutions of . The result follows. ∎
Proof of Proposition 8.4.
Standard hardness gadgets provide a fairly limited condition for the hardness of . In fact, it is possible to prove that is -complete whenever has any protected rectangularity obstruction, not necessarily a standard gadget. However, it cannot be done using Theorem 1.2 as a black box, and is outside of the scope of this paper.
9 Binarization
We will introduce a transformation of a multi-sorted relational structure to a one consisting of binary rectangular relations. This transformation, although hugely increasing the sizes of domains, preserves many of the useful properties of including certain types of polymorphisms and automorphisms. Also, the counting CSP over the new language is parsimoniously interreducible with that over . The hope therefore is that such transformation reduces a complexity classification of to those with only binary rectangular relations, which may be more accessible. This transformation is not new, it appeared in a different context in [9] and [1]. By we denote the arity of relation .
Let be a finite multi-sorted relational structure. We assume that every is among as a unary relation. The structure is constructed as follows:
-
•
The domains are , the relations from .
-
•
For , , and , the structure contains the binary relation given by
First we show that the over is interreducible with that over .
Proposition 9.1 (see also Theorem 4,[9]).
(1) For any structure , is parsimoniously interreducible with .
(2) For any structure , is parsimoniously interreducible with .
Proof.
We use the standard definition of the CSP. Let be any instance of , with variable set and constraint set . We assume that for every with domain , contains a constraint . We construct an instance of , which has variable set and constraint set , as follows.
(i) For each , we introduce a variable . Thus .
(ii) For all , , such that we introduce a constraint .
Let be any solution of . Then define as follows. For every with , set . As is easily seen, is a solution of . Conversely, if is a solution of , then, as every is a relation from , the action of on the domains from is well defined, let us denote it . We would like to argue now that the action of on relations coincides with the component-wise action of . In other words that for any , where , it holds that . Let the th coordinate of be , which is also the th domain for . Then preserves the relation , which means that for any we have and
Then if , then , proving the result.
Conversely, suppose is any instance of with variable set and constraint set . We construct an instance of , with variable set and constraint set , as follows. Recall that every variable has an associated domain . Let be the arity of . We now create a relation on the set , as follows. For , let if there is a constraint , where the domain of is , the domain of is , and . Then is the symmetric-transitive closure of . Clearly, is an equivalence relation, which “identifies” the variables and . Now, suppose is any solution of . Then, for any , we have . Let us write (). Now, define from by for all , . We will write for this function. If, for any , we have , then we must have . This implies that , and hence , where . Let the variable set of will be the set of equivalence classes . For any , we write for its equivalence class. Let be such that for some . Then we can define by for all . Thus we have constructed a bijection between the mappings and mappings that may potentially be solutions of . We will write for this bijection. Now, will have constraint set
Then, is a solution of if and only if is a solution of , and we have a parsimonious reduction from to . ∎
The structure inherits other properties of .
Proposition 9.2.
Let be a multi-sorted structure. Then
(1) has a Mal’tsev polymorphism if and only if does;
(2) is -rigid if and only if is;
(3) If is strongly -rectangular then so is .
The first two items of Proposition 9.2 allow for a fairly straightforward proof using the algebraic approach. However, this would require the introduction of more advanced algebraic machinery. Thus, we give a more elementary proof here.
Proof.
(1) Suppose first that has a Mal’tsev polymorphism . Then for any and any , the tuple , and this action defines an operation on the domains of (i.e. relations from ). Moreover, is Mal’tsev, because in the notation above . It remains to make sure that preserves . Let , where . Then we have , and therefore, for
we obtain , and so .
Suppose now that there is a Mal’tsev polymorphism of . Since for each , the action of on the domains from is well defined, let us denote it . We would like to argue now that the action of on relations coincides with the component-wise action of . In other words that for any , where
Let the th coordinate of be , which is also the th domain for . Then preserves the relation , which means that for any we have and
Denoting , we obtain , implying that acts as coordinate-wise.
(2) Let be a -automorphism of . Then is a unary polymorphism of , and therefore as in item (1) is a unary polymorphism of . That it is a -automorphism is straightforward. The reverse claim is as in (1), as well.
(3) Suppose that is not p-rectangular. This means that there is , where is a conjunctive formula, such that is not rectangular. We consider as an instance of and apply the transformation from the proof of Proposition 9.1 (from a instance to a instance). Let , where , and . The set of constraints is the set of all atoms in . Let the set of variables and the set of constraints be constructed as in the proof of Proposition 9.1. Let also , , denote . Set
and
We prove that is not rectangular.
Without loss of generality we may assume that a witness of non--rectangularity of is as follows: , are such that , but . Let be given by and . We first observe that . Indeed, by construction if then for any solution , where we have . That means that for any and any it holds that for some and . Therefore for any , the assignment is determined by the assignment , a contradiction with the choice of a counterexample of -rectangularity.
That , but means that the first three assignments have the number of extensions to an assignment not divisible by , while has a number of such extensions that is a multiple of (including zero). Observe now that we can apply the bijection to assignments as follows: take any that extends one of them to an assignment , take and set or depending on whether we deal with or . Then since is a bijection, the number of extensions of to an assignment of equals that of to an assignment of . Thus, have the number of extensions not divisible by and so belong to , while has the number of extensions divisible by , and so does not belong to , witnessing that is not rectangular. ∎
References
- [1] Libor Barto and Marcin Kozik. Constraint satisfaction problems solvable by local consistency methods. J. ACM, 61(1):3:1–3:19, 2014.
- [2] Libor Barto, Andrei Krokhin, and Ross Willard. Polymorphisms, and how to use them. In Dagstuhl Follow-Ups, volume 7. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, 2017.
- [3] Alexander I. Barvinok. Combinatorics and Complexity of Partition Functions, volume 30 of Algorithms and combinatorics. Springer, 2016.
- [4] Vitaliy Bodnarchuk, Lev Kaluzhnin, Victor Kotov, and Boris Romov. Galois theory for Post algebras. I. Cybernetics, 5(3):243–252, 1969.
- [5] Andrei A. Bulatov. The complexity of the counting constraint satisfaction problem. J. ACM, 60(5):34:1–34:41, 2013.
- [6] Andrei A. Bulatov. A dichotomy theorem for nonuniform CSPs. In Chris Umans, editor, FOCS, pages 319–330, 2017.
- [7] Andrei A. Bulatov and Víctor Dalmau. A simple algorithm for Mal’tsev constraints. SIAM J. Comput., 36(1):16–27, 2006.
- [8] Andrei A. Bulatov and Víctor Dalmau. Towards a dichotomy theorem for the counting constraint satisfaction problem. Information and Computation, 205(5):651–678, 2007.
- [9] Andrei A. Bulatov, Martin E. Dyer, Leslie Ann Goldberg, Markus Jalsenius, Mark Jerrum, and David Richerby. The complexity of weighted and unweighted #CSP. J. Comput. Syst. Sci., 78(2):681–688, 2012.
- [10] Andrei A. Bulatov and Martin Grohe. The complexity of partition functions. Theor. Comput. Sci., 348(2-3):148–186, 2005.
- [11] Andrei A. Bulatov, Peter Jeavons, and Andrei A. Krokhin. Classifying the complexity of constraints using finite algebras. SIAM J. Comput., 34(3):720–742, 2005.
- [12] Andrei A. Bulatov and Amirhossein Kazeminia. Complexity classification of counting graph homomorphisms modulo a prime number. In STOC, pages 1024–1037. ACM, 2022.
- [13] Jin-Yi Cai and Xi Chen. Complexity of counting CSP with complex weights. J. ACM, 64(3), jun 2017.
- [14] Jin-yi Cai and Lane A. Hemachandra. On the power of parity polynomial time. In Burkhard Monien and Robert Cori, editors, STACS, volume 349 of Lecture Notes in Computer Science, pages 229–239. Springer, 1989.
- [15] Víctor Dalmau and Peter Jonsson. The complexity of counting homomorphisms seen from the other side. Theor. Comput. Sci., 329(1-3):315–323, 2004.
- [16] M. Dyer and C. Greenhill. The complexity of counting graph homomorphisms. Random Structures and Algorithms, 17:260–289, 2000.
- [17] Martin Dyer and David Richerby. An effective dichotomy for the counting constraint satisfaction problem. SIAM J on Comp, 42(3):1245–1274, 2013.
- [18] Martin E. Dyer, Leslie Ann Goldberg, and Mark Jerrum. The complexity of weighted boolean #csp. SIAM J. Comput., 38(5):1970–1986, 2009.
- [19] John Faben. The complexity of counting solutions to generalised satisfiability problems modulo k, 2008. arXiv:0809.1836.
- [20] John Faben and Mark Jerrum. The complexity of parity graph homomorphism: an initial investigation. arXiv preprint arXiv:1309.4033, 2013.
- [21] Tomás Feder and Moshe Y. Vardi. The computational structure of monotone monadic SNP and constraint satisfaction: A study through datalog and group theory. SIAM J. Comput., 28(1):57–104, 1998.
- [22] Jacob Focke, Leslie Ann Goldberg, Marc Roth, and Stanislav Zivný. Counting homomorphisms to -minor-free graphs, modulo 2. In Dániel Marx, editor, SODA, pages 2303–2314. SIAM, 2021.
- [23] David Geiger. Closed systems of functions and predicates. Pacific J Math, 27(1):95–100, 1968.
- [24] Andreas Göbel, Leslie Ann Goldberg, and David Richerby. Counting homomorphisms to square-free graphs, modulo 2. ACM Transactions on Computation Theory (TOCT), 8(3):1–29, 2016.
- [25] Andreas Göbel, J. A. Gregor Lagodzinski, and Karen Seidel. Counting homomorphisms to trees modulo a prime. In MFCS, volume 117, pages 49:1–49:13, 2018.
- [26] Heng Guo, Sangxia Huang, Pinyan Lu, and Mingji Xia. The Complexity of Weighted Boolean CSP Modulo k. In STACS), volume 9, pages 249–260, 2011.
- [27] Andreas Göbel, Leslie Ann Goldberg, and David Richerby. The complexity of counting homomorphisms to cactus graphs modulo 2. ACM Trans on Comp Th, 6(4):1–29, 2014.
- [28] J. Hagemann and A. Mitschke. On -permutable congruences. Algebra Universalis, 3:8–12, 1973.
- [29] Richard Hammack, Wilfried Imrich, and Sandi Klavzar. Handbook of Product Graphs, Second Edition. CRC Press, Inc., USA, 2nd edition, 2011.
- [30] Ulrich Hertrampf. Relations among mod-classes. Theor. Comput. Sci., 74(3):325–328, 1990.
- [31] Peter Jeavons. On the algebraic structure of combinatorial problems. Theoretical Computer Science, 200(1-2):185–204, 1998.
- [32] P.G. Jeavons, D.A. Cohen, and M. Gyssens. How to determine the expressive power of constraints. Constraints, 4:113–131, 1999.
- [33] Mark Jerrum and Alistair Sinclair. Polynomial-time approximation algorithms for the Ising model. SIAM J. Comput., 22(5):1087–1116, 1993.
- [34] Amirhossein Kazeminia and Andrei A Bulatov. Counting homomorphisms modulo a prime number. In MFCS. Schloss Dagstuhl-Leibniz-Zentrum fuer Informatik, 2019.
- [35] Phokion G Kolaitis. Constraint satisfaction, complexity, and logic. In Hellenic Conference on Artificial Intelligence, pages 1–2. Springer, 2004.
- [36] J. A. Gregor Lagodzinski, Andreas Göbel, Katrin Casel, and Tobias Friedrich. On counting (quantum-)graph homomorphisms in finite fields of prime order. CoRR, abs/2011.04827, 2021. arXiv:2011.04827.
- [37] E.H. Lieb and A.D. Sokal. A general Lee-Yang theorem for one-component and multicomponent ferromagnets. Communications in Mathematical Physics, 80(2):153–179, 1981.
- [38] L. Valiant. The complexity of computing the permanent. Theoretical Computing Science, 8:189–201, 1979.
- [39] L. Valiant. The complexity of enumeration and reliability problems. SIAM Journal on Computing, 8(3):410–421, 1979.
- [40] Dmitriy Zhuk. A proof of the CSP dichotomy conjecture. J. ACM, 67(5):30:1–30:78, 2020.
Appendix A Products of relational structures and the uniqueness of
The goal of this subsection is to prove Proposition 2.1.
Proposition A.1.
Let be a multi-sorted structure and a prime. Then up to an isomorphism there exists a unique -rigid multi-sorted structure such that .
However, in order to do this we first need to introduce some auxiliary tools. In particular we use expansions of multi-sorted structures vertices and their homomorphisms. Note that a multi-sorted relational structure with distinguished vertices can be viewed as an expansion of with additional unary symbols, one for each distinguished vertex. Also, note that these distinguished vertices may come from different sorts. In such an interpretation a homomorphism of multi-sorted structures with distinguished vertices is just a homomorphism between the corresponding expansions.
Next we introduce two types of products of multi-sorted structures. The direct product of similar -multi-sorted structures , denoted is the -multi-sorted-structure with the base set and such that the interpretation of is given by if and only if and . By we will denote the th power of , that is, the direct product of copies of . The direct product of structures is defined to be .
Two -tuples and have the same equality type if if and only if for . Let and be multi-sorted structures with distinguished vertices and such that and have the same equality type. Then denotes the structure that is obtained by taking the disjoint union of and and identifying every with , . The distinguished vertices of the new structure are .
The following statement is straightforward.
Proposition A.2.
Let be similar multi-sorted relational structures with distinguished vertices. Then
Moreover, if and only if there exist and such that for .
We will also need another simple observation. By we denote the number of injective homomorphisms from to .
Lemma A.3 (cf. [24]).
Let and be similar multi-sorted relational structures with distinguished vertices. If do not have the same equality type, then .
Proof.
If there are , where is the arity of and , such that but , then there are no homomorphisms (injective or otherwise) from to , since cannot be mapped simultaneously to both and . Otherwise, there must be such that but . Then no homomorphism can be injective because we must have . ∎
Finally, we will use factor structures. Let be a -multi-sorted structure and a collection of equivalence relations on , such that for all . By we denote the factor structure defined as follows.
-
•
is a -multi-sorted structure.
-
•
Let , where denotes the -class containing . The base set of is
-
•
For any , say, -ary, .
Factor structures often appear in relation with homomorphisms. If is a homomorphism from a multi-sorted structure to a multi-sorted structure , then the kernel of , denoted , is a collection of equivalence relations on given by
For an equivalence relation on by and we denote the number of homomorphisms from to (from to ) with kernel . The homomorphism gives rise to a homomorphism from to , where , . The homomorphism is always injective since all are injective.
We also define factor structures for structures with distinguished vertices as follows. Let be a structure with distinguished vertices and an equivalence relation on . Then , where .
Lemma A.4.
Let and be similar -rigid multi-sorted relational structures with distinguished vertices. Then, if and only if
(5) |
for all relational structures with distinguished vertices.
Proof.
The proof goes along the same lines as that in [25]. If and are isomorphic, then (5) obviously holds for all multi-sorted relational structures .
For the other direction, suppose that (5) is true for all . First, we claim that this implies that and have the same equality type. Indeed, if they do not, then without loss of generality there are such that but . Let , , and be the relational structure with the base multi-sorted set where with empty predicates, and as distinguished vertices. Note that there might exists such that is empty. Then , a contradiction with the assumption that (5) holds for all .
We show by induction on the number of vertices in that
(6) |
for all . Let be the number of distinct elements in . For the base case of the induction, consider a relational structure such that . If does not have the same equality type as , then . If has the same equality type as , the only homomorphisms from to are the ones that map to , respectively. Therefore, .
For the inductive step, let and assume that (6) holds for all with . Let be a relational structure with , and let be a collection od equivalence relations on . Then, as is easily seen
Then
Since
and
for all , it implies
Finally, we prove that (6) for implies . An injective homomorphism from a relational structure to itself is an automorphism. Since is -rigid, . Therefore, , meaning there is an injective homomorphism from to . In a similar way, there is an injective homomorphism from to . Thus, the two structures are isomorphic. ∎
Appendix B Proof of Theorem 2.6
The goal of this subsection is to prove Theorem 2.6. We start by introducing some auxiliary construction. For a relational structure the indicator problem [32] is defined as follows. Let be a (multi-sorted) relational structure and . The th indicator problem for is defined to be an instance of given by:
-
•
The set of variables is the set ;
-
•
The domains are from ;
-
•
For every (say, -ary) relation of and every , , such that , , contains the constraint .
Let also denote the set of solutions of .
Lemma B.1 ([4, 23, 32]).
(1) is the set of all -ary polymorphisms of .
(2) is conjuctive-definable in .
(3) has a Mal’tsev polymorphism if and only if contains a tuple such that for any for every .
of Theorem 2.6.
(1) Let be an instance of . The goal is to eliminate all equality relations for each domain , where . To achieve this, we apply a straightforward procedure: For every constraint of the form in , we remove it from and replace every occurrence of with .
The resulting problem instance, denoted as , belongs to . This reduction can clearly be executed in polynomial time. Additionally, although the set of solutions to differs from the set of solutions to (as some variables are eliminated), both instances have the same cardinality.
(2) We follow the same line of argument as the proof of a similar result in [8] for exact counting, and [12] for modular counting. Let , where , and let be the relation conjunctive definable by Lemma B.1 through the indicator problem. By Theorem 2.5(1) and Lemma 2.7 we may assume that has and as its predicates.
Let be an instance of . We construct an instance of as follows.
-
•
;
-
•
consists of three parts: , , and.
The number of solutions of equals the number of solutions of such that for all where . Let be the set of all such solutions of and . Then can be computed in two stages.
Let again be the poset of partitions of . Note that each partition consists of collection of partitions as where each is a partition for . For every partition we define as the instance , where
belong to the same class of ). Note that if is a solution of , then is a solution of if and only if for every from the same class of . Let us denote by the number of solutions of . The number can be computed using the oracle , since we assume that all ’s and are predicates of .
Next, we find the number of solutions of that assign , , pairwise different values. Let be the set of all such solutions. Let us denote by the number of all solutions of such that if and only if belong to the same class of . In particular, . The number can be obtained using the Möbius inversion formula for the poset . Let be Möbius-inversion function. Also, observe that for any
Therefore,
Thus can be found through a constant number of calls to .
Now, we express via . Let be the automorphism group of . We show that . For every solution in and every , is also a solution of . Moreover, since is one-to-one, is in . Conversely, for every , there exists some such that , . Note that implies , which witnesses that is of the required form. Finally, for every and every , if or then . Thus, . Since is -rigid, . Therefore . ∎