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.
Keywords and phrases:
Constraint Satisfaction Problem, Modular CountingFunding:
Andrei A. Bulatov: NSERC Discovery Grant.Copyright and License:
![[Uncaptioned image]](x1.png)
2012 ACM Subject Classification:
Theory of computation Problems, reductions and completeness ; Theory of computation Constraint and logic programmingEditors:
Olaf Beyersdorff, Michał Pilipczuk, Elaine Pimentel, and Nguyễn Kim ThắngSeries and Publisher:

1 Introduction
Counting problems in general have been intensively studied since the pioneering work by Valiant [34, 33]. 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 [2, 7] that yield connections with areas such as statistical physics, see, e.g. [27, 32]. While the complexity of exact counting solutions of a is now well-understood [13, 3, 14, 12], 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.
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 as an input.
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 [3] and was further improved and simplified by Dyer and Richerby [14]. 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 [10] 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 , [11, 25]. 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 [15] that contain problems of counting accepting paths modulo . The standard notion of reduction is again Turing reduction. Faben in [15] 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 [15], who characterized the complexity of counting the solutions of a Generalized Satisfiability problem modulo an integer, and a generalization of [15] to problems with weights by Guo et al. [21]. 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 a relational structure 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 [15]. 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 [9]. 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 , making this orbit contribute modulo to the total homomorphism count from to . If , the range of lies within the set of fixed points of . This observation motivates the following construction: let denote the substructure of induced by . We write there exists 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 ([9, 16]).
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 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 [16] 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 [13] 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 [16, 22, 19, 20, 28, 18, 31]. Finally, it was proved for arbitrary graphs in [9].
Theorem 2 ([9]).
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 2 for arbitrary relational structures. The full version of the paper can be found in [29].
The contribution of the paper is twofold. First, we analyse the existing techniques such as those from [9], and the methods used in exact counting [3, 14, 10], and their applicability to the general case. We conclude that few of them work. More specifically, Theorem 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 Example 18. Another important ingredient of the proof of Theorem 2 is a structural theorem on automorphisms of products of graphs [24]. No such result exists for products of relational structures. Moreover, in Example 18 in Section 6 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. 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 4 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 [9] 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 10 (see also Theorem 7) that, similar to the result of Bulatov and Dalmau [6], expanding a structure by a -mpp-definable relation does not change the complexity of the problem .
Theorem 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 [5, 14] 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 7 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 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).
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 . 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 modulo a prime number 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 .
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 5.
Let be a multi-sorted structure and a prime. Then up to an isomorphism there exists a unique -rigid multi-sorted structure such that . Moreover, for any relational structure it holds .
The proof of Proposition 5 follows the same lines as the analogous statement in the single-sorted case.
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 [1].
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 .
2.2 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 6 ([9]).
For any relational structure and any prime , .
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 7 was proved for exact counting in [6], for modular counting of graph homomorphisms in [16, 19, 20], and for general modular counting CSP in [9].
Theorem 7 ([9]).
Let be a -rigid -structure. Then is polynomial time reducible to .
Lemma 6 and Theorem 7 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 8.
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 [26, 8] and the exact Counting CSP [6]. The reader is referred to [1] for details about pp-definitions and their use in the study of the CSP.
Conjunctive definitions are a special case of pp-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 by if if and only if is true.
Lemma 9 ([9]).
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 .
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 9 for pp-definable relations [9], 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
2.3 Modular Expansion of Relational Structures
We follow the approach of [9] 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 [6], expanding a structure by a -mpp-definable relation does not change the complexity of the problem .
Theorem 10.
Let be a be a -structure, and a prime. Let be a relation that is defined by , then is polynomial time reducible to .
3 Structural Properties for Counting
3.1 Rectangularity, Permutability, and Friends
The key properties of relational structures heavily exploited in [3, 14, 10] to obtain characterizations of the complexity of exact counting are rectangularity, balancedness, congruence permutability, and the presence of a Mal’tsev polymorphism. Indeed, according to [14] 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, [3, 14].
Using modular pp-definitions, we can modify these properties’ definitions accordingly to obtain the properties of strong -rectangularity, -balancedness, and -permutability. Modular-pp-definitions preserve the complexity of modular problems, however, they destroy the connections between the concepts above.
-Rectangularity.
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. Finally, a relational structure is said to be strongly -rectangular, if every is rectangular.
-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), where every nonzero diagonal block has rank at most 1. Note that the rank can also be computed in , in which case we use the term rank-1 block matrix modulo .
Let be a ternary relation, a subset of . We call balanced if the matrix , where such that and is a rank-1 block matrix. It is -balanced if is a rank-1 block matrix modulo . A relation of arity is balanced if every representation of as a ternary relation, a subset of , is balanced. Similarly, A relation on 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. Similarly, a relational structure is called strongly -balanced if every relation is -balanced.
-Permutability.
A congruence of a relational structure is an equivalence relation on that is pp-definable 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 . Figure 1 demonstrates the connection between congruence permutabililty, strong rectangularity, the existence of a Mal’tsev polymorphism, strong balancedness and their modular counterparts. A collection of statements and examples proving these connections or lack thereof will be given in the full version of the paper. Below we give one such example showing that the existence of a Mal’tsev polymorphism does not guarantee 2-rectangularity.
Example 11.
Let , , and , where is the following ternary relation, (triples are written vertically), . 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, is an operation on . 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 .
4 Rigitity and Multi-sorted Structures
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.
The classification result in Theorem 2 asserts that for a -rigid graph is hard whenever the exact counting problem is hard. In the following example, we briefly show that this is no longer the case for general relational structures.
Example 12.
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 [4, 35] the decision is solvable in polynomial time, while the exact counting problem is P-complete by [6], 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.
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 12.
While Proposition 5 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 is 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 Proposition 5.
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 [17, 30].
Lemma 13 ([17, 30]).
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. The instance can also be viewed as a structure with vertex set and such that the solutions of are exactly the homomorphisms from to , see [17]. 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 . In fact, a minimal lossless of width structure is produced from by applying an appropriate local propagation algorithm [30].
Proposition 14.
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.
5 An Algorithm for Parity
In this section we outline an algorithm that solves , that is, finds the parity of the number of homomorphisms to , provided the structure satisfies some additional conditions.
Theorem 15.
Let be a 2-rigid, strongly 2-rectangular, and has a Mal’tsev polymorphism111Note that the latter condition does not follow from having a Mal’tsev polymorphism, because 2-mpp-definitions do not preserve polymorphisms.. Then can be solved in time polynomial time.
In order to prove Theorem 15 we apply some of the existing techniques such as compact representations of relations with a Mal’tsev polymorphism, but in a novel way that is very different from its original use.
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 relations will be called frame relations. The following observations are straightforward corollaries of the rectangularity of and were used in [14].
Lemma 16 (Folklore).
Let be a relation with a Mal’tsev polymorphism.
-
(1)
is an equivalence relation for all .
-
(2)
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 (i.e. a CSP instance) of a relation in a relational structure with a Mal’tsev polymorphism. This is the property that makes them essential for solving CSPs. The following transformations of frames can be performed in polynomial time.
Proposition 17 ([5, 14]).
Let be a relational structure with a Mal’tsev polymorphism and a relation has a conjunctive definition in .
-
(1)
A frame and a witness function for can be computed in .
-
(2)
Let . Given a frame for , a frame for (i.e., is the constant , ) can be constructed in time.
-
(3)
Given a frame for , a frame for , can be constructed in time.
Overview of the algorithm.
The exact counting algorithm in [14] first finds a frame of a conjunctive defined relation (a.k.a. the set of solutions of a CSP instance), and then uses the frame and the condition of balancedness to compute the number of solutions. Unfortunately, this approach does not work in our case, because according to the results of Section 3.1 the property of 2-balancedness that we need here does not correlate well with the existence of a Mal’tsev polymorphism. We therefore choose a different approach.
Let be a structure satisfying the conditions of Theorem 15 and . Since has a Mal’tsev polymorphism, a frame for can be computed in polynomial time by Proposition 17(1). Suppose that is -ary. It is not hard to see that
Therefore, if it is possible to find a frame of , we could repeat this process times eventually obtaining a unary relation such that and then just count the elements in using its frame. Unfortunately, it is not that straightforward, because Proposition 17(3) does not work for modular quantifiers. Instead, we use a more convoluted method.
Let . This relation contains essentially the same tuples as , except it also keeps their extensions to the last coordinate position. This means that , and if we know a frame of , a frame of can be found by Proposition 17(3). Finding a frame for is the crux of the algorithm.
Finding a frame for .
Let and be frame relations and a witness function (a frame) of the relation found in the previous step. Let denote the collection of the equivalence classes of , and , , where . We often refer to these classes as frame classes. By , and , , we denote yet unknown frame relations, witness function, and frame classes of (clearly, the number of classes in may differ from that of ).
First, we observe that by definition a tuple belongs to if and only if there is a class , , such that and . This makes finding and easy, they are just restrictions of and on the union of odd classes from . For and we use Proposition 17(2) to find a witness function and frame classes of . We examine for . We check whether there exists such that . If we find such an , we select and set . By construction , and by the observation above . Finally, in order to check whether for some it holds that it suffices to complete the following steps. Use use Proposition 17(2) to compute a witness function and frame classes of
where . It can be shown that if and only if there exists such that .
This completes the outline of the algorithm.
6 Hardness and Automorphisms of Direct Products of Structures
Another crucial component of Theorem 2 is the structure of automorphisms of direct products of graphs [24]. 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 the following example we show that this breaks down already for digraphs.
Example 18.
let be a directed graph where with (directed) edge set . This digraph is rigid. However, the automorphism group of , see Figure 2, 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 [9] 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 . The example above indicates that this result may no longer be true for general relational structures.
Next, we explore what implications of a structural result similar to that in [24] that is used in [9] 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 as in Lemma 1. 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 [9] 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 19.
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 can be proved 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 2 as a black box, and is outside of the scope of this paper.
7 Binarization
While studying the structure of for a relational structure and an integer may be a difficult problem, in this Section 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 show that and share many important properties.
Theorem 20.
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 20 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.
References
- [1] Libor Barto, Andrei Krokhin, and Ross Willard. Polymorphisms, and how to use them. In Dagstuhl Follow-Ups, volume 7. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2017. doi:10.4230/DFU.VOL7.15301.1.
- [2] Alexander I. Barvinok. Combinatorics and Complexity of Partition Functions, volume 30 of Algorithms and combinatorics. Springer, 2016. doi:10.1007/978-3-319-51829-9.
- [3] Andrei A. Bulatov. The complexity of the counting constraint satisfaction problem. J. ACM, 60(5):34:1–34:41, 2013. doi:10.1145/2528400.
- [4] Andrei A. Bulatov. A dichotomy theorem for nonuniform CSPs. In Chris Umans, editor, FOCS, pages 319–330, 2017. doi:10.1109/FOCS.2017.37.
- [5] Andrei A. Bulatov and Víctor Dalmau. A simple algorithm for Mal’tsev constraints. SIAM J. Comput., 36(1):16–27, 2006. doi:10.1137/050628957.
- [6] 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. doi:10.1016/J.IC.2006.09.005.
- [7] Andrei A. Bulatov and Martin Grohe. The complexity of partition functions. Theor. Comput. Sci., 348(2-3):148–186, 2005. doi:10.1016/J.TCS.2005.09.011.
- [8] 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. doi:10.1137/S0097539700376676.
- [9] Andrei A. Bulatov and Amirhossein Kazeminia. Complexity classification of counting graph homomorphisms modulo a prime number. In STOC, pages 1024–1037. ACM, 2022. doi:10.1145/3519935.3520075.
- [10] Jin-Yi Cai and Xi Chen. Complexity of counting CSP with complex weights. J. ACM, 64(3), June 2017. doi:10.1145/2822891.
- [11] 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. doi:10.1007/BFB0028987.
- [12] 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. doi:10.1016/J.TCS.2004.08.008.
- [13] M. Dyer and C. Greenhill. The complexity of counting graph homomorphisms. Random Structures and Algorithms, 17:260–289, 2000. doi:10.1002/1098-2418(200010/12)17:3/4\%3C260::AID-RSA5\%3E3.0.CO;2-W.
- [14] Martin Dyer and David Richerby. An effective dichotomy for the counting constraint satisfaction problem. SIAM J. on Comp, 42(3):1245–1274, 2013. doi:10.1137/100811258.
- [15] John Faben. The complexity of counting solutions to generalised satisfiability problems modulo , 2008. arXiv:0809.1836.
- [16] John Faben and Mark Jerrum. The complexity of parity graph homomorphism: an initial investigation. arXiv preprint arXiv:1309.4033, 2013. arXiv:1309.4033.
- [17] 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. doi:10.1137/S0097539794266766.
- [18] 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. doi:10.1137/1.9781611976465.137.
- [19] 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. doi:10.1145/2898441.
- [20] 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. doi:10.4230/LIPICS.MFCS.2018.49.
- [21] 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. doi:10.4230/LIPICS.STACS.2011.249.
- [22] 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. doi:10.1145/2635825.
- [23] J. Hagemann and A. Mitschke. On -permutable congruences. Algebra Universalis, 3:8–12, 1973.
- [24] Richard Hammack, Wilfried Imrich, and Sandi Klavzar. Handbook of Product Graphs, Second Edition. CRC Press, Inc., USA, 2nd edition, 2011.
- [25] Ulrich Hertrampf. Relations among mod-classes. Theor. Comput. Sci., 74(3):325–328, 1990. doi:10.1016/0304-3975(90)90081-R.
- [26] Peter Jeavons. On the algebraic structure of combinatorial problems. Theoretical Computer Science, 200(1-2):185–204, 1998. doi:10.1016/S0304-3975(97)00230-2.
- [27] Mark Jerrum and Alistair Sinclair. Polynomial-time approximation algorithms for the Ising model. SIAM J. Comput., 22(5):1087–1116, 1993. doi:10.1137/0222066.
- [28] Amirhossein Kazeminia and Andrei A Bulatov. Counting homomorphisms modulo a prime number. In MFCS. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2019.
- [29] Amirhossein Kazeminia and Andrei A. Bulatov. Modular counting csp: Reductions and algorithms, 2025. arXiv:2501.04224.
- [30] Phokion G Kolaitis. Constraint satisfaction, complexity, and logic. In Hellenic Conference on Artificial Intelligence, pages 1–2. Springer, 2004. doi:10.1007/978-3-540-24674-9_1.
- [31] 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.
- [32] 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.
- [33] L. Valiant. The complexity of computing the permanent. Theoretical Computing Science, 8:189–201, 1979. doi:10.1016/0304-3975(79)90044-6.
- [34] L. Valiant. The complexity of enumeration and reliability problems. SIAM Journal on Computing, 8(3):410–421, 1979. doi:10.1137/0208032.
- [35] Dmitriy Zhuk. A proof of the CSP dichotomy conjecture. J. ACM, 67(5):30:1–30:78, 2020. doi:10.1145/3402029.