This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

\stackMath

Modular Counting CSP: Reductions and Algorithms

Amirhossein Kazeminia and Andrei A.Bulatov
Simon Fraser University
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 pp for arbitrary prime pp. 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 p=2p=2 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 (#𝖢𝖲𝖯\#\mathsf{CSP}), 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 𝖢𝖲𝖯\mathsf{CSP} 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 𝖢𝖲𝖯\mathsf{CSP} 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 σ\sigma is a collection of relational symbols each of which is assigned a positive integer, the arity of the symbol. A relational structure \mathcal{H} with signature σ\sigma is a set HH and an interpretation \mathcal{R}^{\mathcal{H}} of each σ\mathcal{R}\in\sigma, where \mathcal{R}^{\mathcal{H}} is a relation or a predicate on HH whose arity equals that of \mathcal{R}. The set HH is said to be the base set or the universe of \mathcal{H}. We will use the same letter for the base set as for the structure, only in the regular font. A structure with signature σ\sigma is often called a σ\sigma-structure. Structures with the same signature are called similar.

Let 𝒢,\mathcal{G},\mathcal{H} be similar structures with signature σ\sigma. A homomorphism from 𝒢\mathcal{G} to \mathcal{H} is a mapping φ:GH\varphi:G\to H such that for any σ\mathcal{R}\in\sigma, say, of arity rr, if 𝒢(a1,,ar)\mathcal{R}^{\mathcal{G}}(a_{1},\dots,a_{r}) is true for a1,,arGa_{1},\dots,a_{r}\in G, then (φ(a1),,φ(ar))\mathcal{R}^{\mathcal{H}}(\varphi(a_{1}),\dots,\varphi(a_{r})) is also true. The set of all homomorphisms from 𝒢\mathcal{G} to \mathcal{H} is denoted 𝖧𝗈𝗆(𝒢,)\mathsf{Hom}(\mathcal{G},\mathcal{H}). The cardinality of 𝖧𝗈𝗆(𝒢,)\mathsf{Hom}(\mathcal{G},\mathcal{H}) is denoted by 𝗁𝗈𝗆(𝒢,)\mathsf{hom}(\mathcal{G},\mathcal{H}). A homomorphism φ\varphi is an isomorphism if it is bijective and the inverse mapping φ1\varphi^{-1} is a homomorphism from \mathcal{H} to 𝒢\mathcal{G}. 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 𝖢𝖲𝖯\mathsf{CSP}, the goal is, given similar relational structure 𝒢,\mathcal{G},\mathcal{H}, to decide whether there is a homomorphism from 𝒢\mathcal{G} to \mathcal{H}. The restricted problem in which \mathcal{H} is fixed and only 𝒢\mathcal{G} is given as an input is denoted by 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}). The complexity of such problems is well understood [6, 40].

Counting CSP. In the (exact) Counting 𝖢𝖲𝖯\mathsf{CSP} the goal is to find the number 𝗁𝗈𝗆(𝒢,)\mathsf{hom}(\mathcal{G},\mathcal{H}) of homomorphisms from a structure 𝒢\mathcal{G} to a similar structure \mathcal{H}. Restricted versions of the Counting CSP can be introduced in the same way as for the decision one. In the counting version of 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}) denoted #𝖢𝖲𝖯()\mathsf{\#CSP}(\mathcal{H}) the goal is to find 𝗁𝗈𝗆(𝒢,)\mathsf{hom}(\mathcal{G},\mathcal{H}) for a given structure 𝒢\mathcal{G}.

The complexity class the Counting 𝖢𝖲𝖯\mathsf{CSP} 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 #A\#A to a counting problem #B\#B is an algorithm that, given an instance II of #A\#A produces (in polynomial time) an instance II^{\prime} of #B\#B such that the answers to II and II^{\prime} are equal. A Turing reduction is a polynomial time algorithm that solves #A\#A using #B\#B 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 𝖢𝖲𝖯\mathsf{CSP}s of the form #𝖢𝖲𝖯()\mathsf{\#CSP}(\mathcal{H}) 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 𝖢𝖲𝖯\mathsf{CSP} modulo a prime number pp. If a relational structure \mathcal{H} is fixed, this problem is denoted #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}). More precisely, in #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) the objective is, given a relational structure 𝒢\mathcal{G}, to find the number of homomorphisms from 𝒢\mathcal{G} to \mathcal{H} modulo pp.

There are several complexity classes related to modular counting. The more established type of classes is 𝖬𝗈𝖽k\mathsf{Mod}_{k}P, the class of problems of deciding whether the number of accepting paths of a polynomial time nondeterministic Turing machine is not divisible by kk, [14, 30]. In particular, if k=2k=2 then 𝖬𝗈𝖽k\mathsf{Mod}_{k}P is the class \oplusP. However, problems of counting accepting paths naturally belong to classes of the form #k\#_{k}P, introduced by Faben in [19] that contain problems of counting accepting paths modulo kk. The standard notion of reduction is again Turing reduction. Faben in [19] studied the basic properties of such classes, in particular, he identified several #k\#_{k}P-complete problems.

In the case of the 𝖢𝖲𝖯\mathsf{CSP}, 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 \mathcal{H} form a group with respect to composition denoted 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{H}). The order of an automorphism π𝖠𝗎𝗍()\pi\in\mathsf{Aut}(\mathcal{H}) is the smallest number kk such that πk\pi^{k} is the identity permutation. An element aHa\in H is a fixed point of π𝖠𝗎𝗍()\pi\in\mathsf{Aut}(\mathcal{H}) if π(a)=a\pi(a)=a. The set of all fixed points of π\pi is denoted by 𝖥𝗂𝗑(π)\mathsf{Fix}(\pi).

A systematic study of counting homomorphisms in graphs was initiated by Faben and Jerrum in [19]. They observed that the automorphism group 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{H}), particularly the automorphisms of order pp, plays a crucial role in the complexity of the problem #p𝖧𝗈𝗆()\#_{p}\mathsf{Hom}(\mathcal{H}). This insight extends to relational structures, as discussed in [12]. Specifically, for a homomorphism φ\varphi from a relational structure 𝒢\mathcal{G} to \mathcal{H}, composing φ\varphi with an automorphism from 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{H}) yields another homomorphism from 𝒢\mathcal{G} to \mathcal{H}. Thus, any automorphism of \mathcal{H} acts on the set 𝖧𝗈𝗆(𝒢,)\mathsf{Hom}(\mathcal{G},\mathcal{H}) of all homomorphisms from 𝒢\mathcal{G} to \mathcal{H}. If 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{H}) contains an automorphism π\pi of order pp, the size of the orbit of φ\varphi is divisible by pp unless πφ=φ\pi\circ\varphi=\varphi. In this case, the range of φ\varphi lies within the set of fixed points 𝖥𝗂𝗑(π)\mathsf{Fix}(\pi) of π\pi, making this orbit contribute 0 modulo pp to the total homomorphism count from 𝒢\mathcal{G} to \mathcal{H}. This observation motivates the following construction: let π\mathcal{H}^{\pi} denote the substructure of \mathcal{H} induced by 𝖥𝗂𝗑(π)\mathsf{Fix}(\pi). We denote by p\mathcal{H}\rightarrow_{p}\mathcal{H}^{\prime} the existence of a π𝖠𝗎𝗍()\pi\in\mathsf{Aut}(\mathcal{H}) such that \mathcal{H}^{\prime} is isomorphic to π\mathcal{H}^{\pi}. Furthermore, we write p\mathcal{H}\rightarrow^{*}_{p}\mathcal{H}^{\prime} if there exist structures 1,,k\mathcal{H}_{1},\dots,\mathcal{H}_{k} such that \mathcal{H} is isomorphic to 1\mathcal{H}_{1}, \mathcal{H}^{\prime} is isomorphic to k\mathcal{H}_{k}, and 1p2ppk\mathcal{H}_{1}\rightarrow_{p}\mathcal{H}_{2}\rightarrow_{p}\cdots\rightarrow_{p}\mathcal{H}_{k}.

Relational structures without order pp automorphisms will be called pp-rigid.

Lemma 1.1 ([12, 20]).

Let \mathcal{H} be a relational structure and pp a prime. Then
(a) Up to an isomorphism there exists a unique pp-rigid structure p\mathcal{H}^{*p} such that pp\mathcal{H}\rightarrow_{p}^{*}\mathcal{H}^{*p}.
(b) For any relational structure 𝒢\mathcal{G} it holds that 𝗁𝗈𝗆(𝒢,)𝗁𝗈𝗆(𝒢,p)(modp).\mathsf{hom}(\mathcal{G},\mathcal{H})\equiv\mathsf{hom}(\mathcal{G},\mathcal{H}^{*p})\pmod{p}.

By Lemma 1.1 it suffices to determine the complexity of #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) for pp-rigid structures \mathcal{H}.

The existing results on modular counting. As we mentioned before, the research in modular counting 𝖢𝖲𝖯\mathsf{CSP}s has mostly been aimed at counting graph homomorphisms. The complexity of the problem #p𝖧𝗈𝗆(H)\#_{p}\mathsf{Hom}(H) of counting homomorphism to a fixed graph HH modulo a prime number pp has received significant attention in the last ten years. Faben and Jerrum in [20] posed a conjecture that up to order pp automorphism reduction p\rightarrow_{p} the complexity of this problem is the same as that for exact counting. More precisely, they conjectured that #p𝖧𝗈𝗆(H)\#_{p}\mathsf{Hom}(H) is solvable in polynomial time if and only if 𝖧𝗈𝗆(Hp)\mathsf{Hom}(H^{*p}) is. By the result of Dyer and Greenhill [16] #p𝖧𝗈𝗆(H)\#_{p}\mathsf{Hom}(H) is solvable in polynomial time if and only if every connected component of HpH^{*p} is a complete graph with all loops present or a complete bipartite graph. Therefore, proving that if a pp-rigid HH does not satisfy these conditions then #p𝖧𝗈𝗆(H)\#_{p}\mathsf{Hom}(H) is #pP\#_{p}P-hard suffices to confirm the conjecture of Faben and Jerrum. Over several years the hardness of #p𝖧𝗈𝗆(H)\#_{p}\mathsf{Hom}(H) 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 pp and any graph HH the problem #p𝖧𝗈𝗆(H)\#_{p}\mathsf{Hom}(H) is solvable in polynomial time if and only if 𝖧𝗈𝗆(Hp)\mathsf{Hom}(H^{*p}) is solvable in polynomial time. Otherwise it is #p\#_{p}P-complete.

Our Results. In this paper we begin a systematic study of the problem #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) for general relational structures \mathcal{H}. 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 pp-rigid graphs is the same as of exact counting. We, however, suggest a relational structure, a digraph 𝒯p\mathcal{T}_{p}, that is pp-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 𝒢\mathcal{G}, to try to identify the possible images of each vertex of 𝒢\mathcal{G}, 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 𝒯p\mathcal{T}_{p} mentioned above is subjected to this process, it results in a multi-sorted structure that is no longer pp-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 pp-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 \mathcal{H} by adding relations to \mathcal{H} that are primitive positive (pp-)definable in \mathcal{H}, that is, relations that can be derived from the relations of \mathcal{H} 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 pp-modular quantifiers instead of regular existential quantifiers. The semantics of a pp-modular quantifier is ”there are non-zero modulo pp 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 \langle\mathcal{H}\rangle that consists of all relations pp-definable in \mathcal{H}. The new concept gives rise to new definitions of pp-formulas and relational clones. If regular existential quantifiers in pp-formulas are replaced with pp-modular quantifiers, we obtain pp-modular primitive positive formulas (pp-mpp-formulas, for short). Then, similar to pp-definitions, a relation \mathcal{R} is said to be pp-mpp-definable in a structure \mathcal{H} if there is a pp-mpp-formula in \mathcal{H} expressing \mathcal{R}. The pp-modular clone p\langle\mathcal{H}\rangle_{p} associated with \mathcal{H} is the set of all relations pp-mpp-definable in \mathcal{H}. 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 pp-mpp-definable relation does not change the complexity of the problem #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}).

Theorem 1.3.

Let pp be a prime number and \mathcal{H} a pp-rigid relational structure. If \mathcal{R} is pp-mpp-definable in \mathcal{H}, then #p𝖢𝖲𝖯(+)\#_{p}\mathsf{CSP}(\mathcal{H}+\mathcal{R}) is polynomial time reducible to #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}).

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 #2𝖢𝖲𝖯()\#_{2}\mathsf{CSP}(\mathcal{H}) when \mathcal{H} 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 pp 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 𝖠𝗎𝗍(n)\mathsf{Aut}(\mathcal{H}^{n}) may be a difficult problem, in Section 9 we make a step forward by reducing the class of structures \mathcal{H} for which such structural results are required. More precisely, for any relational structure =(H;1,,k)\mathcal{H}=(H;\mathcal{R}_{1},\dots,\mathcal{R}_{k}) we construct its binarization b()b(\mathcal{H}) 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 𝖠𝗎𝗍(b()n)\mathsf{Aut}(b(\mathcal{H})^{n}) than 𝖠𝗎𝗍(n)\mathsf{Aut}(\mathcal{H}^{n}) itself. We prove that \mathcal{H} and b()b(\mathcal{H}) share many important properties.

Theorem 1.4.

Let \mathcal{H} be a relational structure. Then \mathcal{H} is strongly rectangular (pp-strongly rectangular, pp-rigid, has a Mal’tsev polymorphism) if and only if b()b(\mathcal{H}) is strongly rectangular (pp-strongly rectangular, pp-rigid, has a Mal’tsev polymorphism).

In Section 8 we explore what implications of a structural results about 𝖠𝗎𝗍(n)\mathsf{Aut}(\mathcal{H}^{n}) 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 #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}).

We provide a more detailed overview of the main results in Section 3.

2 Preliminaries

Let [n][n] denote the set {1,2,,n}\{1,2,\ldots,n\}. Let HnH^{n} be the Cartesian product of the set HH with itself nn times and H1××HkH_{1}\times\dots\times H_{k} the Cartesian product of sets H1,,HkH_{1},\dots,H_{k}. We denote the members of HnH^{n} and H1××HkH_{1}\times\dots\times H_{k} using bold font, 𝐚Hn\mathbf{a}\in H^{n}, 𝐚H1××Hk\mathbf{a}\in H_{1}\times\dots\times H_{k}. The ii-th element of 𝐚\mathbf{a} is denoted by 𝐚[i]\mathbf{a}[i] or 𝐚i\mathbf{a}_{i}.

For I={i1,,ik}[n]I=\{i_{1},\dots,i_{k}\}\subseteq[n] we use 𝗉𝗋I𝐚\mathsf{pr}_{I}\mathbf{a} to denote (𝐚i1,,𝐚ik)(\mathbf{a}_{i_{1}},\dots,\mathbf{a}_{i_{k}}); and for H1××Hk\mathcal{R}\subseteq H_{1}\times\dots\times H_{k} we use 𝗉𝗋I\mathsf{pr}_{I}\mathcal{R} to denote {𝗉𝗋I𝐚𝐚}\{\mathsf{pr}_{I}\mathbf{a}\mid\mathbf{a}\in\mathcal{R}\}. For 𝐚Hs\mathbf{a}\in H^{s} by #𝖾𝗑𝗍(𝐚)\mathsf{\#ext}_{\mathcal{R}}(\mathbf{a}) we denote the number of assignments 𝐛Hns\mathbf{b}\in H^{n-s} such that (𝐚,𝐛)(\mathbf{a},\mathbf{b})\in\mathcal{R}. (Note that the order of elements in 𝐚\mathbf{a} and 𝐛\mathbf{b} and \mathcal{R} might differ, hence we slightly abuse the notation here.) We denote the number of assignments mod pp by #𝗉𝖾𝗑𝗍(𝐚)\mathsf{\#_{p}ext}_{\mathcal{R}}(\mathbf{a}). Moreover, 𝗉𝗋Ip\mathsf{pr}^{p}_{I}\mathcal{R} denotes the set {𝗉𝗋I𝐚|𝐚 and #𝗉𝖾𝗑𝗍(𝗉𝗋I𝐚)0}\{\mathsf{pr}_{I}\mathbf{a}|\mathbf{a}\in\mathcal{R}\text{ and }\mathsf{\#_{p}ext}_{\mathcal{R}}(\mathsf{pr}_{I}\mathbf{a})\neq 0\}. Often, we treat relations H1××Hk\mathcal{R}\subseteq H_{1}\times\dots\times H_{k} as predicates :H1××Hk{0,1}\mathcal{R}:H_{1}\times\dots\times H_{k}\to\{0,1\}.

2.1 Multi-Sorted sets and relational structures.

We begin with introducing multi-sorted or typed sets. Let H={Hi}i[k]={H1,,Hk}H=\{H_{i}\}_{{i\in[k]}}=\{H_{1},\dots,H_{k}\} be a collection of sets. We will assume that the sets H1,,HkH_{1},\dots,H_{k} are disjoint. The cardinality of a multi-sorted set HH equals |H|=i[k]|Hi||H|=\sum_{i\in[k]}|H_{i}|. A mapping φ\varphi between two multi-sorted sets G={Gi}i[k]G=\{G_{i}\}_{{i\in[k]}} and H={Hi}i[k]H=\{H_{i}\}_{{i\in[k]}} is defined as a collection of mappings φ={φi}i[k]\varphi=\{\varphi_{i}\}_{{i\in[k]}}, where φi:GiHi\varphi_{i}:G_{i}\to H_{i}, that is, φi\varphi_{i} maps elements of the sort ii in GG to elements of the sort ii in HH. A mapping φ={φi}i[k]\varphi=\{\varphi_{i}\}_{{i\in[k]}} from {Gi}i[k]\{G_{i}\}_{{i\in[k]}} to {Hi}i[k]\{H_{i}\}_{{i\in[k]}} is injective (bijective), if for all i[k]i\in[k], φi\varphi_{i} is injective (bijective).

A multi-sorted relational signature σ\sigma over a set of types {1,,k}\{1,\dots,k\} is a collection of relational symbols, a symbol σ\mathcal{R}\in\sigma is assigned a positive integer \ell_{\mathcal{R}}, the arity of the symbol, and a tuple (i1,,i)(i_{1},\dots,i_{\ell_{\mathcal{R}}}), the type of the symbol. A multi-sorted relational structure \mathcal{H} with signature σ\sigma is a multi-sorted set {Hi}i[k]\{H_{i}\}_{i\in[k]} and an interpretation \mathcal{R}^{\mathcal{H}} of each σ\mathcal{R}\in\sigma, where \mathcal{R}^{\mathcal{H}} is a relation or a predicate on Hi1××HiH_{i_{1}}\times...\times H_{i_{\ell_{\mathcal{R}}}} and (i1,,i)(i_{1},\dots,i_{\ell_{\mathcal{R}}}) is called the type of \mathcal{R}. The multi-sorted structure \mathcal{H} is finite if HH and σ\sigma are finite. All structures in this paper are finite. The set HH is said to be the base set or the universe of \mathcal{H}. 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 𝒢,\mathcal{G},\mathcal{H} be similar multi-sorted structures with signature σ\sigma. A homomorphism φ\varphi from 𝒢\mathcal{G} to \mathcal{H} is a collection of mappings φi:GiHi\varphi_{i}:G_{i}\to H_{i}, i[k]i\in[k], from GG to HH such that for any σ\mathcal{R}\in\sigma with type (i1,,i)(i_{1},\dots,i_{\ell_{\mathcal{R}}}), if 𝒢(a1,,a)\mathcal{R}^{\mathcal{G}}(a_{1},\dots,a_{\ell_{\mathcal{R}}}) is true for (a1,,ar)Gi1××Gi(a_{1},\dots,a_{r})\in G_{i_{1}}\times...\times G_{i_{\ell_{\mathcal{R}}}}, then (φi1(a1),,φi(a))\mathcal{R}^{\mathcal{H}}(\varphi_{i_{1}}(a_{1}),\dots,\varphi_{i_{\ell_{\mathcal{R}}}}(a_{\ell_{\mathcal{R}}})) is true as well. The set of all homomorphisms from 𝒢\mathcal{G} to \mathcal{H} is denoted 𝖧𝗈𝗆(𝒢,)\mathsf{Hom}(\mathcal{G},\mathcal{H}). The cardinality of 𝖧𝗈𝗆(𝒢,)\mathsf{Hom}(\mathcal{G},\mathcal{H}) is denoted by 𝗁𝗈𝗆(𝒢,)\mathsf{hom}(\mathcal{G},\mathcal{H}). For a multi-sorted structure \mathcal{H}, the corresponding counting CSP, #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}), is the problem of computing 𝗁𝗈𝗆(𝒢,)\mathsf{hom}(\mathcal{G},\mathcal{H}) for a given structure 𝒢\mathcal{G}. A homomorphism φ\varphi is an isomorphism if it is bijective and the inverse mapping φ1\varphi^{-1} is a homomorphism from \mathcal{H} to 𝒢\mathcal{G}. If \mathcal{H} and 𝒢\mathcal{G} are isomorphic, we write 𝒢\mathcal{H}\cong\mathcal{G}. 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 \mathcal{H} form a group denoted 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{H}).

The direct product of multi-sorted σ\sigma-structures ,𝒢\mathcal{H},\mathcal{G}, denoted ×𝒢\mathcal{H}\times\mathcal{G} is the multi-sorted σ\sigma-structure with the base set H×G={Hi×Gi}i[k]H\times G=\{H_{i}\times G_{i}\}_{{i\in[k]}}, the interpretation of σ\mathcal{R}\in\sigma is given by ×𝒢((a1,b1),,(ak,bk))=1\mathcal{R}^{\mathcal{H}\times\mathcal{G}}((a_{1},b_{1}),\dots,(a_{k},b_{k}))=1 if and only if (a1,,ak)=1\mathcal{R}^{\mathcal{H}}(a_{1},\dots,a_{k})=1 and 𝒢(b1,,bk)=1\mathcal{R}^{\mathcal{G}}(b_{1},\dots,b_{k})=1. By \mathcal{H}^{\ell} we will denote the \ellth power of \mathcal{H}, that is, the direct product of \ell copies of \mathcal{H}.

Let =({Hi}i[k];1,,m)\mathcal{H}=(\{H_{i}\}_{{i\in[k]}};\mathcal{R}_{1},\dots,\mathcal{R}_{m}) be a multi-sorted relational structure and π\pi an automorphism of \mathcal{H}. For 𝒬Hi1××Hi\mathcal{Q}\subseteq H_{i_{1}}\times\dots\times H_{i_{\ell}}, we use π(𝒬)\pi(\mathcal{Q}) to denote the set {π(𝐚)𝐚𝒬}\{\pi(\mathbf{a})\mid\mathbf{a}\in\mathcal{Q}\}, where π(𝐚)=(πi1(𝐚[1]),,πi(𝐚[])\pi(\mathbf{a})=(\pi_{i_{1}}(\mathbf{a}[1]),\dots,\pi_{i_{\ell}}(\mathbf{a}[\ell]). For a prime number pp we say that π\pi has order pp if π\pi is not the identity in 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{H}) and has order pp in 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{H}). In other words, each of the πj\pi_{j}’s is either the identity mapping or has order pp, and at least one of the πj\pi_{j}’s is not the identity mapping. Structure \mathcal{H} is said to be pp-rigid if it has no automorphism of order pp. Similar to regular relational structures we can introduce reductions of multi-sorted structures by their automorphisms of order pp.

A substructure \mathcal{H}^{\prime} of \mathcal{H} induced by a collection of sets {Hi}i[k]\{H^{\prime}_{i}\}_{i\in[k]}, where HiHiH^{\prime}_{i}\subseteq H_{i} is the relational structure given by ({Hi}i[k];1,,m)(\{H^{\prime}_{i}\}_{{i\in[k]}};\mathcal{R}^{\prime}_{1},\dots,\mathcal{R}^{\prime}_{m}), where j=j(Hi1××Hi)\mathcal{R}^{\prime}_{j}=\mathcal{R}_{j}\cap(H^{\prime}_{i_{1}}\times\dots\times H^{\prime}_{i_{\ell}}) and (i1,,i)(i_{1},\dots,i_{\ell}) is the type of j\mathcal{R}_{j}. By 𝖥𝗂𝗑(π)\mathsf{Fix}(\pi) we denote the collection {𝖥𝗂𝗑(πi)}j[k]\{\mathsf{Fix}(\pi_{i})\}_{j\in[k]} of sets of fixed points of the πi\pi_{i}’s. Let π\mathcal{H}^{\pi} denote the substructure of \mathcal{H} induced by 𝖥𝗂𝗑(π)\mathsf{Fix}(\pi). We write p\mathcal{H}\rightarrow_{p}\mathcal{H}^{\prime} if there is π𝖠𝗎𝗍()\pi\in\mathsf{Aut}(\mathcal{H}) of order pp such that \mathcal{H}^{\prime} is isomorphic to π\mathcal{H}^{\pi}. We also write p\mathcal{H}\rightarrow^{*}_{p}\mathcal{H}^{\prime} if there are structures 1,,t\mathcal{H}_{1},\dots,\mathcal{H}_{t} such that \mathcal{H} is isomorphic to 1\mathcal{H}_{1}, \mathcal{H}^{\prime} is isomorphic to t\mathcal{H}_{t}, and 1p2ppt\mathcal{H}_{1}\rightarrow_{p}\mathcal{H}_{2}\rightarrow_{p}\dots\rightarrow_{p}\mathcal{H}_{t}. Let also p\mathcal{H}^{*p} be a pp-rigid structure such that pp\mathcal{H}\rightarrow^{*}_{p}\mathcal{H}^{*p}.

Proposition 2.1.

Let \mathcal{H} be a multi-sorted structure and pp a prime. Then up to an isomorphism there exists a unique pp-rigid multi-sorted structure p\mathcal{H}^{*p} such that pp\mathcal{H}\rightarrow_{p}^{*}\mathcal{H}^{*p}.

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.

The following statements are well-known for single-sorted structures, see [20, 12].

Lemma 2.2.

Let \mathcal{H} be a multi-sorted relational structure. If π\pi is a pp-automorphism of \mathcal{H}, then for any 𝒢\mathcal{G},

𝗁𝗈𝗆(𝒢,)𝗁𝗈𝗆(𝒢,π)(modp).\mathsf{hom}(\mathcal{G},\mathcal{H})\equiv\mathsf{hom}(\mathcal{G},\mathcal{H}^{\pi})\pmod{p}.
Proof.

Let H={H}i[k]H=\{H\}_{{i\in[k]}} and Hπ={Hiπi}i[k]H^{\pi}=\{H_{i}^{\pi_{i}}\}_{{i\in[k]}} denote the universes of \mathcal{H} and π\mathcal{H}^{\pi} respectively. For a similar multi-sorted structure 𝒢\mathcal{G} with universe GG, we show that the number of homomoprhisms which use at least one element of HHπH-H^{\pi} is 0(modp)0\pmod{p}.

Given any homomorphism φ:𝒢\varphi:\mathcal{G}\rightarrow\mathcal{H}, where φ={φi}i[k]\varphi=\{\varphi_{i}\}_{i\in[k]}, consider the homomorphism πφ={πiφi}i[k]{\pi\circ\varphi}=\{\pi_{i}\circ\varphi_{i}\}_{i\in[k]}. This is still a homomorphism which is different from φ\varphi as there is some element vGiv\in G_{i} such that φi(v)HiHiπi\varphi_{i}(v)\in H_{i}-H_{i}^{\pi_{i}} for all i[k]i\in[k], and so πi(φi(v))φi(v)\pi_{i}(\varphi_{i}(v))\neq\varphi_{i}(v). On the other hand πipφi\pi_{i}^{p}\circ\varphi_{i} is just φi\varphi_{i}, as πi\pi_{i} is a pp-automorphism. So π\pi acts as a permutation of order pp on the set 𝖧𝗈𝗆(𝒢,)\mathsf{Hom}(\mathcal{G},\mathcal{H}). Moreover, the orbit of π\pi containing a homomorphism that has at least one element from HiHiπH_{i}-H_{i}^{\pi} in its range has size pp. ∎

The following statement is a straightforward implication of Lemma 2.2.

Proposition 2.3.

Let \mathcal{H} be a multi-sorted relational structure and pp a prime. Then for any relational structure 𝒢\mathcal{G} it holds

𝗁𝗈𝗆(𝒢,)𝗁𝗈𝗆(𝒢,p)(modp).\mathsf{hom}(\mathcal{G},\mathcal{H})\equiv\mathsf{hom}(\mathcal{G},\mathcal{H}^{*p})\pmod{p}.

We complete this section with a definition of polymorphisms. Let Hn\mathcal{R}\subseteq H^{n} be a relation over a set HH. A kk-ary polymorphism of \mathcal{R} is a mapping f:HkHf:H^{k}\to H such that for any choice of 𝐚1,,𝐚k\mathbf{a}_{1},\dots,\mathbf{a}_{k}\in\mathcal{R}, it holds that f(𝐚1,,𝐚k)f(\mathbf{a}_{1},\dots,\mathbf{a}_{k})\in\mathcal{R} (computed component-wise). The mapping ff is a polymorphism of a (single-sorted) relational structure =(H,1,,m)\mathcal{H}=(H,\mathcal{R}_{1},\dots,\mathcal{R}_{m}) if it is a polymorphism of each relation 1,,m\mathcal{R}_{1},\dots,\mathcal{R}_{m}. In the multi-sorted case the definitions are a bit more complicated. Let H1××Hn\mathcal{R}\subseteq H_{1}\times\dots\times H_{n} be a multi-sorted relation. Instead of a single mapping we consider a family of mappings f={fi}i[n]f=\{f_{i}\}_{i\in[n]}, fi:HikHif_{i}:H^{k}_{i}\to H_{i}. The family ff is said to be a polymorphism of \mathcal{R} if it satisfies the same condition: for any choice of 𝐚1,,𝐚k\mathbf{a}_{1},\dots,\mathbf{a}_{k}\in\mathcal{R}, it holds that f(𝐚1,,𝐚k)f(\mathbf{a}_{1},\dots,\mathbf{a}_{k})\in\mathcal{R}, only in this case the mapping fif_{i} is applied in the iith coordinate position, i[n]i\in[n]. A polymorphism of a multi-sorted structure =({Hi}i[q];𝒬1,,𝒬m)\mathcal{H}=(\{H_{i}\}_{i\in[q]};\mathcal{Q}_{1},\dots,\mathcal{Q}_{m}) is again a family f={fi}iq:HikHif=\{f_{i}\}_{i\in q}:H^{k}_{i}\to H_{i} such that for each j[m]j\in[m], ff (or rather its appropriate subfamily) is a polymorphism of 𝒬j\mathcal{Q}_{j}. 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 HH a mapping φ:H3H\varphi:H^{3}\rightarrow H is said to be a Mal’tsev operation if for any a,bHa,b\in H it satisfies the conditions f(a,a,b)=f(b,a,a)=bf(a,a,b)=f(b,a,a)=b. In the multi-sorted case a family f={fi}i[n]f=\{f_{i}\}_{i\in[n]} is Mal’tsev, if every fif_{i} is Mal’tsev. A Mal’tsev operation (or a family of operations) that is a polymorphism of a relation \mathcal{R} or a relational structure \mathcal{H} is said to be a Mal’tsev polymorphism of \mathcal{R} or \mathcal{H}. One of the useful properties of Mal’tsev polymorphisms is that it enforces the rectangularity of relations. A binary relation H2\mathcal{R}\subseteq H^{2} is rectangular if whenever ((a,c),(a,d),(b,c)((a,c),(a,d),(b,c)\in\mathcal{R} it also holds that (b,d)(b,d)\in\mathcal{R}. If \mathcal{R} has a Mal’tsev polymorphism ff, it is rectangular. Indeed,

f(aabdcc)=(f(a,a,b)f(d,c,c))=(bd).f\left(\begin{array}[]{ccc}a&a&b\\ d&c&c\end{array}\right)=\left(\begin{array}[]{c}f(a,a,b)\\ f(d,c,c)\end{array}\right)=\left(\begin{array}[]{c}b\\ d\end{array}\right)\in\mathcal{R}.

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 HH be a (finite) set and Γ\Gamma a set of relations on HH. Such a set of relations is called a constraint language, and the set HH is often referred to as the domain.

The Constraint Satisfaction Problem 𝖢𝖲𝖯(Γ)\mathsf{CSP}(\Gamma) is the combinatorial problem with:
Instance: a pair 𝒫=(V,𝒞)\mathcal{P}=(V,\mathcal{C}) where VV is a finite set of variables and 𝒞\mathcal{C} is a finite set of constraints. Each constraint C𝒞C\in\mathcal{C} is a pair 𝐬,\langle\mathbf{s},\mathcal{R}\rangle where

  • 𝐬=(v1,v2,,vm)\mathbf{s}=(v_{1},v_{2},...,v_{m}) is a tuple of variables from VV of length mm, called the constraint scope;

  • Γ\mathcal{R}\in\Gamma is an mm-ary relation, called the constraint relation.

Objective: Decide whether there is a solution of 𝒫\mathcal{P}, that is, a mapping φ:VH\varphi:V\to H such that for each constraint 𝐬,𝒞\langle\mathbf{s},\mathcal{R}\rangle\in\mathcal{C} with 𝐬=(v1,,vm)\mathbf{s}=(v_{1},\dots,v_{m}) the tuple (φ(v1),,φ(vm))(\varphi(v_{1}),\dots,\varphi(v_{m})) belongs to \mathcal{R}.

In the (modular) counting version of 𝖢𝖲𝖯(Γ)\mathsf{CSP}(\Gamma) denoted #𝖢𝖲𝖯(Γ)\mathsf{\#CSP}(\Gamma) (#p𝖢𝖲𝖯(Γ)\#_{p}\mathsf{CSP}(\Gamma)) the objective is to find the number of solutions of instance 𝒫\mathcal{P} (modulo pp). 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 σ\sigma-structure \mathcal{H} the collection of interpretations \mathcal{R}^{\mathcal{H}}, σ\mathcal{R}\in\sigma, is just a set of relations, that is a constraint language over HH. Thus, for every relational structure \mathcal{H} there is an associated constraint language Γ\Gamma_{\mathcal{H}}. Conversely, every (finite) constraint language Γ\Gamma can be converted into a relational structure Γ\mathcal{H}_{\Gamma} such that ΓΓ=Γ\Gamma_{\mathcal{H}_{\Gamma}}=\Gamma 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 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}) and 𝖢𝖲𝖯(Γ)\mathsf{CSP}(\Gamma_{\mathcal{H}}) can be easily translated into each other. The same is true for #𝖢𝖲𝖯()\mathsf{\#CSP}(\mathcal{H}) and #𝖢𝖲𝖯(Γ)\mathsf{\#CSP}(\Gamma_{\mathcal{H}}). The conversion procedure goes as follows. Let 𝒢\mathcal{G} be an instance of 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}) and σ\sigma is the signature of \mathcal{H}. Create an instance 𝒫=(V,𝒞)\mathcal{P}=(V,\mathcal{C}) of 𝖢𝖲𝖯(Γ)\mathsf{CSP}(\Gamma_{\mathcal{H}}) by setting V=GV=G, the base set of 𝒢\mathcal{G}, and for every σ\mathcal{R}\in\sigma and every 𝐬𝒢\mathbf{s}\in\mathcal{R}^{\mathcal{G}}, include the constraint 𝐬,\langle\mathbf{s},\mathcal{R}^{\mathcal{H}}\rangle into 𝒞\mathcal{C}. The transformation of instances of 𝖢𝖲𝖯(Γ)\mathsf{CSP}(\Gamma) to an instance of 𝖢𝖲𝖯(Γ)\mathsf{CSP}(\mathcal{H}_{\Gamma}) 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 #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) or 𝖢𝖲𝖯()\oplus\mathsf{CSP}(\mathcal{H}) is given by variables and constraints.

The definition above can easily be extended to multi-sorted relational structures and languages. If \mathcal{H} is a multi-sorted relational structure, 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}) (#𝖢𝖲𝖯()\#\mathsf{CSP}(\mathcal{H})) asks, given a similar structure 𝒢\mathcal{G}, whether there exists a homomorphism of multi-sorted structure 𝒢\mathcal{G} to \mathcal{H} (asks to find the number of such homomorphisms). If Γ\Gamma is a set of multi-sorted relations, every variable vVv\in V for an instance (V,𝒞)(V,\mathcal{C}) of 𝖢𝖲𝖯(Γ)\mathsf{CSP}(\Gamma) is assigned a type τ(v)\tau(v) and for every constraint (v1,,vk),\langle(v_{1},\dots,v_{k}),\mathcal{R}\rangle, the sequence (τ(v1),,τ(vk))(\tau(v_{1}),\dots,\tau(v_{k})) must match the type of \mathcal{R}.

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 \mathcal{H} be a relational structure with signature σ\sigma and =\mathcal{H}^{=} its expansion by adding a binary relational symbol == interpreted as =H=_{H}, the equality relation on HH. The following reduction is straightforward.

Lemma 2.4 ([12]).

For any relational structure \mathcal{H} and any prime pp, #p𝖢𝖲𝖯(=)T#p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}^{=})\leq_{T}\#_{p}\mathsf{CSP}(\mathcal{H}). Similarly, for a constraint language Γ\Gamma on HH the problem #p𝖢𝖲𝖯(Γ{=H})\#_{p}\mathsf{CSP}(\Gamma\cup\{=_{H}\}) is polynomial time reducible to #p𝖢𝖲𝖯(Γ)\#_{p}\mathsf{CSP}(\Gamma).

A constant relation over a set HH is a unary relation Ca={a}C_{a}=\{a\}, aHa\in H. For a relational structure \mathcal{H} by 𝖼\mathcal{H}^{\mathsf{c}} we denote the expansion of \mathcal{H} by all the constant relations CaC_{a}, aHa\in H. 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 \mathcal{H} be a pp-rigid σ\sigma-structure. Then #p𝖢𝖲𝖯(𝖼)\#_{p}\mathsf{CSP}(\mathcal{H}^{\mathsf{c}}) is polynomial time reducible to #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}).

For a pp-rigid constraint language Γ\Gamma on a set HH the problem #p𝖢𝖲𝖯(Γ{CaaH})\#_{p}\mathsf{CSP}(\Gamma\cup\{C_{a}\mid a\in H\}) is polynomial time reducible to #p𝖢𝖲𝖯(Γ)\#_{p}\mathsf{CSP}(\Gamma).

Lemma 2.4 and Theorem 2.5 can be generalized to the multi-sorted case. Let ={i}i[k]\mathcal{H}=\{\mathcal{H}_{i}\}_{i\in[k]} be a multi-sorted structure with signature σ\sigma and =\mathcal{H}^{=} its expansion by adding a family of binary relational symbols =Hi=_{H_{i}} (one for each type) interpreted as the equality relation on HiH_{i}, i[k]i\in[k]. A constant relation over a set {Hi}i[k]\{H_{i}\}_{i\in[k]} is a unary relation Ca={a}C_{a}=\{a\}, aHi,i[k]a\in H_{i},i\in[k] (such a predicate can only be applied to variables of type ii). For a structure \mathcal{H} by 𝖼\mathcal{H}^{\mathsf{c}} we denote the expansion of \mathcal{H} by all the constant relations CaC_{a}, aHi,i[k]a\in H_{i},i\in[k].

Theorem 2.6 (see also [12]).

Let \mathcal{H} be a multi-sorted relational structure and pp prime.
(1) #p𝖢𝖲𝖯(=)\#_{p}\mathsf{CSP}(\mathcal{H}^{=}) is Turing reducible to #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H});
(2) Let \mathcal{H} be pp-rigid. Then #p𝖢𝖲𝖯(𝖼)\#_{p}\mathsf{CSP}(\mathcal{H}^{\mathsf{c}}) is Turing reducible to #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}).

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 \mathcal{H} be a structure with signature σ\sigma. A conjunctive formula Φ\Phi over variables {x1,,xk}\{x_{1},\dots,x_{k}\} is a conjunction of atomic formulas of the form (y1,,y)\mathcal{R}(y_{1},\dots,y_{\ell}), where σ\mathcal{R}\in\sigma is an (\ell-ary) symbol and y1,,y{x1,,xk}y_{1},\dots,y_{\ell}\in\{x_{1},\dots,x_{k}\}. A kk-ary predicate 𝒬\mathcal{Q} is conjunctive definable in \mathcal{H} if (a1,,ak)𝒬(a_{1},\dots,a_{k})\in\mathcal{Q} if and only if Φ(a1,,ak)\Phi(a_{1},\dots,a_{k}) is true.

Lemma 2.7 ([12]).

Let \mathcal{H} be a relational structure with signature σ\sigma, \mathcal{R} be conjunctive definable in \mathcal{H}, and +\mathcal{H}+\mathcal{R} denote the expansion of \mathcal{H} by a predicate symbol \mathcal{R} that is interpreted as the relation \mathcal{R} in \mathcal{H}. Then #p𝖢𝖲𝖯(+)T#p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}+\mathcal{R})\leq_{T}\#_{p}\mathsf{CSP}(\mathcal{H}).

Similarly, for a constraint language Γ\Gamma if a relation \mathcal{R} is conjunctive definable in Γ\Gamma, then #p𝖢𝖲𝖯(Γ{})T#p𝖢𝖲𝖯(Γ)\#_{p}\mathsf{CSP}(\Gamma\cup\{\mathcal{R}\})\leq_{T}\#_{p}\mathsf{CSP}(\Gamma).

We now extend the concept of primitive-positive definability to the multi-sorted case. Let \mathcal{H} be a multi-sorted relational structure with the base set HH. As before primitive positive (pp-) formula in \mathcal{H} is a first-order formula y1,,ysΦ(x1,,xk,y1,,ys),\exists y_{1},\dots,y_{s}\Phi(x_{1},\dots,x_{k},y_{1},\dots,y_{s}), where Φ\Phi is a conjunction of atomic formulas of the form z1=Hz2z_{1}=_{H}z_{2} or (z1,,z)\mathcal{R}(z_{1},\dots,z_{\ell}), z1,,z{x1,,xk,y1,,ys}z_{1},\dots,z_{\ell}\in\{x_{1},\dots,x_{k},y_{1},\dots,y_{s}\}, and \mathcal{R} is a predicate of \mathcal{H}. However, every variable in Φ\Phi is now assigned a type τ(xi),τ(yj)\tau(x_{i}),\tau(y_{j}) in such a way that for every atomic formula z1=Hz2z_{1}=_{H}z_{2} it holds that τ(z1)=τ(z2)\tau(z_{1})=\tau(z_{2}), and for any atomic formula (z1,,z)\mathcal{R}(z_{1},\dots,z_{\ell}) the sequence (τ(z1),,τ(z))(\tau(z_{1}),\dots,\tau(z_{\ell})) matches the type of \mathcal{R}. We say that \mathcal{H} pp-defines a predicate 𝒬\mathcal{Q} if there exists a pp-formula such that

𝒬(x1,,xk)=y1,,ysΦ(x1,,xk,y1,,ys).\mathcal{Q}(x_{1},\dots,x_{k})=\exists y_{1},\dots,y_{s}\Phi(x_{1},\dots,x_{k},y_{1},\dots,y_{s}).

For 𝐚\mathbf{a}\in\mathcal{R} by #𝖾𝗑𝗍Φ(𝐚)\mathsf{\#ext}_{\Phi}(\mathbf{a}) we denote the number of assignments 𝐛Hτ(y1)××Hτ(ys)\mathbf{b}\in H_{\tau(y_{1})}\times\dots\times H_{\tau(y_{s})} to y1,,ysy_{1},\dots,y_{s} such that Φ(𝐚,𝐛)\Phi(\mathbf{a},\mathbf{b}) is true. We denote the number of such assignments mod pp by #𝗉𝖾𝗑𝗍Φ(𝐚)\mathsf{\#_{p}ext}_{\Phi}(\mathbf{a}).

While when \mathcal{H} 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 \mathcal{H} (single- or multi-sorted) \langle\mathcal{H}\rangle denotes the relational clone of \mathcal{H}, that is, the set of all relations pp-definable in \mathcal{H}

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

pp-rigidity. The classification result in Theorem 1.2 asserts that #p𝖧𝗈𝗆(H)\#_{p}\mathsf{Hom}(H) for a pp-rigid graph HH 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 pp be a prime number and Tp={0,,p1,p,p+1}T_{p}=\{0,\dots,p-1,p,p+1\}. A relational structure 𝒯p\mathcal{T}_{p} has the base set TpT_{p} and predicates ,C0,,Cp+1\mathcal{R},C_{0},\dots,C_{p+1}, where CaC_{a} is the constant relation {(a)}\{(a)\} and =Tp2{(0,p),,(p1,p)}\mathcal{R}=T^{2}_{p}-\{(0,p),\dots,(p-1,p)\}. The structure 𝒯p\mathcal{T}_{p} is pp-rigid as it contains all the constant relations and every automorphism must preserve them, implying that every element of TpT_{p} is a fixed point. By [6, 40] the decision 𝖢𝖲𝖯(𝒯p)\mathsf{CSP}(\mathcal{T}_{p}) is solvable in polynomial time, while the exact counting problem #𝖢𝖲𝖯(𝒯p)\#\mathsf{CSP}(\mathcal{T}_{p}) is #\#P-complete by [8], as it does not have a Mal’tsev polymorphism and \mathcal{R} is not rectangular (see below). However, if 𝒢\mathcal{G} is a structure similar to 𝒯p\mathcal{T}_{p} and there is a homomorphism φ:𝒢𝒯p\varphi:\mathcal{G}\to\mathcal{T}_{p} such that some vertex vv of 𝒢\mathcal{G} is mapped to a{0,,p1}a\in\{0,\dots,p-1\} then, unless vv is bound by CaC_{a}, the mapping that differs from φ\varphi only at vv by sending it to any b{0,,p1}b\in\{0,\dots,p-1\} is also a homomorphism. Since |{0,,p1}|=p|\{0,\dots,p-1\}|=p, this means that the elements 0,,p10,\dots,p-1 can be effectively eliminated from 𝒯p\mathcal{T}_{p}, and the resulting structure is somewhat trivial. Therefore #p𝖢𝖲𝖯(𝒯p)\#_{p}\mathsf{CSP}(\mathcal{T}_{p}) 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 H1××HnH_{1}\times\dots\times H_{n} 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 =(V,E)\mathcal{H}=(V,E) be a directed graph where V={a,b,c,d}V=\{a,b,c,d\} with (directed) edge set E={(b,a),(b,c),(c,d)}E=\{(b,a),(b,c),(c,d)\}. This digraph is rigid. However, the automorphism group of 2\mathcal{H}^{2}, see Figure 1, has a complicated structure. As is easily seen 2\mathcal{H}^{2} 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 #p𝖧𝗈𝗆(+))\#_{p}\mathsf{Hom}(\mathcal{H}+\mathcal{R})), where +\mathcal{H}+\mathcal{R} denotes the expansion of \mathcal{H} by a relation \mathcal{R} pp-definable in \mathcal{H}, is polynomial time reducible to #p𝖧𝗈𝗆()\#_{p}\mathsf{Hom}(\mathcal{H}) (see below). The example above indicates that this result may no longer be true for general relational structures.

Refer to caption
Figure 1: The structure of \mathcal{H} and 2\mathcal{H}^{2}

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 H1×H2\mathcal{R}\subseteq H_{1}\times H_{2} is said to be rectangular if (a,c),(a,d),(b,c)(a,c),(a,d),(b,c)\in\mathcal{R} implies (b,d)(b,d)\in\mathcal{R} for any a,bA1,c,dA2a,b\in A_{1},c,d\in A_{2}. A relation Hn\mathcal{R}\subseteq H^{n} for n2n\geq 2 is rectangular if for every I[n]I\subsetneq[n], the relation RR is rectangular when viewed as a binary relation, a subset of 𝗉𝗋I×𝗉𝗋[n]I\mathsf{pr}_{I}\mathcal{R}\times\mathsf{pr}_{[n]-I}\mathcal{R}. A relational structure \mathcal{H} is strongly rectangular if every relation \mathcal{R}\in\langle\mathcal{H}\rangle of arity at least 2 is rectangular.

An nn-by-mm matrix MM 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 (x,y,z)\mathcal{R}(x,y,z) be a ternary relation,a subset of H1×H2×H3H_{1}\times H_{2}\times H_{3}. We call \mathcal{R} balanced if the matrix 𝖬|H1|×|H2|\mathsf{M}_{\mathcal{R}}\in\mathbb{Z}^{|H_{1}|\times|H_{2}|}, where 𝖬[x,y]=|{zH3:(x,y,z)}|\mathsf{M}_{\mathcal{R}}[x,y]=|\{z\in H_{3}:(x,y,z)\in\mathcal{R}\}| such that xH1x\in H_{1} and yH2y\in H_{2} is a rank-1 block matrix. A relation \mathcal{R} of arity n>3n>3 is balanced if every representation of \mathcal{R} as a ternary relation, a subset of Hk×H×HnkH^{k}\times H^{\ell}\times H^{n-k-\ell}, is balanced. A relational structure \mathcal{H} is called strongly balanced if every relation \mathcal{R}\in\langle\mathcal{H}\rangle 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] #𝖢𝖲𝖯()\#\mathsf{CSP}(\mathcal{H}) is polynomial time solvable if and only if \mathcal{H} 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 pp-rectangularity and pp-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 pp-rectangularity, pp-permutability, pp-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 pp-rectangularity, pp-permutability, pp-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 pp-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 𝒯p\mathcal{T}_{p} introduced in the beginning of Section 3.1 and discover that when considered as a multi-sorted structure 𝒯p\mathcal{T}_{p} is not pp-rigid, and therefore can be transformed so that the corresponding modular CSP is solvable in polynomial time. The idea is, given an instance 𝒢\mathcal{G} of #p𝖧𝗈𝗆(𝒯p)\#_{p}\mathsf{Hom}(\mathcal{T}_{p}), to use some preprocessing algorithm (such as local propagation or a solution algorithm for the decision CSP) to reduce possible range of vertices from 𝒢\mathcal{G} under homomorphisms. We then refine the instance by replacing 𝒯p\mathcal{T}_{p} with a multi-sorted structure in such a way that every possible range of a vertex from 𝒢\mathcal{G} 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 𝒯p\mathcal{T}_{p} the sets TpT_{p} and {0}\{0\} have different types, and an automorphism of such a structure may act differently on these sets and no longer has to have 0 as a fixed point when acting on TpT_{p}.

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 pp-rigid structure whose complexity differs from that for exact counting.

Modular existential quantifiers. We follow the approach of [12] by expanding the relational structure \mathcal{H} by adding pp-definable relations, but doing in a manner friendly to modular counting.

We introduce a new form of expansion which is using pp-modular quantifiers instead of regular existential quantifiers. The semantics of a pp-modular quantifier is ”there are non-zero modulo pp 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 pp-modular quantifiers, we obtain pp-modular primitive positive formulas (pp-mpp-formulas, for short). The pp-modular quantifier is denoted p\exists^{\equiv p}, and so pp-mpp-formulas have the form

py1,,y1py1++s1+1,,ykΦ(z1,,zm).\exists^{\equiv p}y_{1},\dots,y_{\ell_{1}}\dots\exists^{\equiv p}y_{\ell_{1}+\dots+\ell_{s-1}+1},\dots,y_{k}\Phi(z_{1},\dots,z_{m}).

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 ={(1,0,0),(1,1,0),(1,1,1),(2,2,2)}\mathcal{R}=\{(1,0,0),(1,1,0),(1,1,1),(2,2,2)\} be a relation on {0,1,2}\{0,1,2\}. Then formulas 3y3z(x,y,z)\exists^{\equiv 3}y\exists^{\equiv 3}z\ \ \mathcal{R}(x,y,z) and 3y,z(x,y,z)\exists^{\equiv 3}y,z\ \ \mathcal{R}(x,y,z) define sets {1,2}\{1,2\} and {2}\{2\}, respectively.

Every relational structure is associated with a relational clone \langle\mathcal{H}\rangle that consists of all relations pp-definable in \mathcal{H}. Then, similar to pp-definitions, a relation \mathcal{R} is said to be pp-mpp-definable in a structure \mathcal{H} if there is a pp-mpp-formula in \mathcal{H} expressing \mathcal{R}. The pp-modular clone p\langle\mathcal{H}\rangle_{p} associated with \mathcal{H} is the set of all relations pp-mpp-definable in \mathcal{H}. Similar to the result of Bulatov and Dalmau [8], expanding a structure by a pp-mpp-definable relation does not change the complexity of the problem #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}).

Theorem 3.1.

Let \mathcal{H} be a be a σ\sigma-structure with equality, and pp a prime. Let \mathcal{R} be a relation that is defined by

R(x1,,xk)=py1,,yΦ(x1,,xk,y)R(x_{1},\dots,x_{k})=\exists^{\equiv p}y_{1},\dots,y_{\ell}\Phi(x_{1},\dots,x_{k},y)

then #p𝖢𝖲𝖯(+)\#_{p}\mathsf{CSP}(\mathcal{H}+\mathcal{R}) is polynomial time reducible to #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}).

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 #2𝖢𝖲𝖯()\#_{2}\mathsf{CSP}(\mathcal{H}) when \mathcal{H} satisfies both the 2-rectangularity and the usual strong rectangularity conditions (or, equivalently, has a Mal’tsev polymorphism). Note that the case p=2p=2 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 Hn\mathcal{R}\subseteq H^{n} is defined as a subset \mathcal{R}^{\prime}\subseteq\mathcal{R} that satisfies two conditions. Firstly, if \mathcal{R} includes a tuple where the ii-th component is aa, then \mathcal{R}^{\prime} must also include at least one such tuple. Secondly, for 1<in1<i\leq n, consider a set SHS\subseteq H. We say SS is ii-equivalent in \mathcal{R} if \mathcal{R} has tuples that agree on their first i1i-1 components and whose ii-th components form exactly the set SS. Any set that is ii-equivalent in \mathcal{R} must also be ii-equivalent in \mathcal{R}^{\prime}, though \mathcal{R}^{\prime} may have fewer tuples sharing these common prefixes compared to \mathcal{R}. It is demonstrated in [17] that every nn-ary relation over HH such that has Mal’tsev polymorphism, has a compact frame of size at most n|H|n|H|, despite \mathcal{R} potentially having up to |H|n|H|^{n} elements. Additionally, we provide a method for constructing such a frame efficiently and describe how to reconstruct the strongly rectangular relation \mathcal{R} 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 nn variables as an nn-ary relation \mathcal{R}. First of all the algorithm finds a frame for \mathcal{R} using the existing techniques [7].Then it looks for a frame for the relation ~𝗉𝗋[n1]\widetilde{\mathcal{R}}\subseteq\mathsf{pr}_{[n-1]}\mathcal{R} consisting of the tuples from 𝗉𝗋[n1]\mathsf{pr}_{[n-1]}\mathcal{R} that have odd number of tuples from \mathcal{R}. 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 \mathcal{R} ever further. The key property of this procedure is that the parity of ~\widetilde{\mathcal{R}} equals that of \mathcal{R}. Once reduced to a unary relation, determining the parity becomes strightforward.

Theorem 3.2.

Let \mathcal{H} be a 2-rigid, strongly 2-rectangular, and 2\langle\mathcal{H}\rangle_{2} has Mal’tsev polymorphism111Note that the latter condition does not follow from \mathcal{H} having a Mal’tsev polymorphism, because 2-mpp-definitions do not preserve polymorphisms, as we show in Section 6.. And let 2\mathcal{R}\in\langle\mathcal{H}\rangle_{2} be an nn-ary relation. Then #2𝖢𝖲𝖯()\#_{2}\mathsf{CSP}(\mathcal{H}) can be solved in time O(n5)O(n^{5}).

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 𝖠𝗎𝗍(n)\mathsf{Aut}(\mathcal{H}^{n}) can be. A rectangularity obstruction is a violation of the rectangularity or pp-rectangularity property, that is, a (nn-ary) relation \mathcal{R} pp- or pp-mpp-definable in a structure \mathcal{H}, k[n]k\in[n], and tuples 𝐚,𝐛𝗉𝗋[k],𝐜,𝐝𝗉𝗋[n][k]\mathbf{a},\mathbf{b}\in\mathsf{pr}_{[k]}\mathcal{R},\mathbf{c},\mathbf{d}\in\mathsf{pr}_{[n]-[k]}\mathcal{R} such that (𝐚,𝐜),(𝐚,𝐝),(𝐛,𝐝)(\mathbf{a},\mathbf{c}),(\mathbf{a},\mathbf{d}),(\mathbf{b},\mathbf{d})\in\mathcal{R}, but (𝐛,𝐜)(\mathbf{b},\mathbf{c})\not\in\mathcal{R}. A generalized rectangularity obstruction are the relation \mathcal{R} and sets A1,1,A1,2𝗉𝗋[k]A_{1,1},A_{1,2}\subseteq\mathsf{pr}_{[k]}\mathcal{R}, A2,1,A2,2𝗉𝗋[n][k]A_{2,1},A_{2,2}\subseteq\mathsf{pr}_{[n]-[k]}\mathcal{R} such that A1,1A1,2=A_{1,1}\cap A_{1,2}=\emptyset, A2,1A2,2=A_{2,1}\cap A_{2,2}=\emptyset, and any 𝐚A1,1,𝐛A1,2,𝐜A2,1,𝐝A2,2\mathbf{a}\in A_{1,1},\mathbf{b}\in A_{1,2},\mathbf{c}\in A_{2,1},\mathbf{d}\in A_{2,2} form a rectangularity obstruction.

At the first glance, if such an obstruction exists, it should be possible to prove the hardness of #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}). Indeed, \mathcal{R} can be viewed as a bipartite graph 𝖪\mathsf{K}_{\mathcal{R}}, whose parts of the bipartition are 𝗉𝗋[k]\mathsf{pr}_{[k]}\mathcal{R} and 𝗉𝗋[n][k]\mathsf{pr}_{[n]-[k]}\mathcal{R}, and as the rectangularity obstruction shows, this graph is not complete bipartite implying that #𝖧𝗈𝗆(𝖪)\#\mathsf{Hom}(\mathsf{K}_{\mathcal{R}}) is #P-complete. However, the hardness of #p𝖧𝗈𝗆(𝖪)\#_{p}\mathsf{Hom}(\mathsf{K}_{\mathcal{R}}) also involves the requirement that 𝖪\mathsf{K}_{\mathcal{R}} is pp-rigid. pp-rigidity is achieved by restricting the problem to induced subgraphs of 𝖪\mathsf{K}_{\mathcal{R}}. However, such a subgraph may avoid the (generalized) rectangularity obstruction rendering it useless.

The obstruction A1,1,A1,2𝗉𝗋[k]A_{1,1},A_{1,2}\subseteq\mathsf{pr}_{[k]}\mathcal{R}, A2,1,A2,2𝗉𝗋[n][k]A_{2,1},A_{2,2}\subseteq\mathsf{pr}_{[n]-[k]}\mathcal{R} is said to be protected in \mathcal{R} if, after applying a pp-reduction to \mathcal{R} under a sequence of pp-automorphisms from 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{R}), for the resulting relation ~\tilde{\mathcal{R}} it holds that 𝗉𝗋[k]~A1,1,𝗉𝗋[k]~A1,2\mathsf{pr}_{[k]}\tilde{\mathcal{R}}\cap A_{1,1},\mathsf{pr}_{[k]}\tilde{\mathcal{R}}\cap A_{1,2}\neq\emptyset, 𝗉𝗋[n][k]~A2,1,𝗉𝗋[n][k]~A2,2\mathsf{pr}_{[n]-[k]}\tilde{\mathcal{R}}\cap A_{2,1},\mathsf{pr}_{[n]-[k]}\tilde{\mathcal{R}}\cap A_{2,2}\neq\emptyset. In fact,Theorem 4.2 [12] implies, although implicitly, that any pp-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 𝖪\mathsf{K}_{\mathcal{R}}, that is, survives pp-reductions of 𝖪\mathsf{K}_{\mathcal{R}} itself. In this case we say that the obstruction is graph-protected.

Proposition 3.3.

Let \mathcal{H} be a (multi-sorted) relational structure and pp a prime number. If \mathcal{H} has a graph protected generalized rectangularity obstruction modulo pp, #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) is #pP\#_{p}P-complete.

We consider a special case of graph-protected generalized rectangularity obstructions, standard hardness gadgets, that have to satisfy the additional condition A1,1A1,2=𝗉𝗋[k],A2,1A2,2=𝗉𝗋[n][k]A_{1,1}\cup A_{1,2}=\mathsf{pr}_{[k]}\mathcal{R},A_{2,1}\cup A_{2,2}=\mathsf{pr}_{[n]-[k]}\mathcal{R}. 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 #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}). In fact, it is possible to prove that #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) is #pP\#_{p}P-complete whenever \mathcal{H} 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 𝖠𝗎𝗍(k)\mathsf{Aut}(\mathcal{H}^{k}) for a relational structure \mathcal{H} and an integer kk may be a difficult problem, in Section 9 we make a step forward by reducing the class of structures \mathcal{H} 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 =(H;1,,k)\mathcal{H}=(H;\mathcal{R}_{1},\dots,\mathcal{R}_{k}) we construct its binarization b()b(\mathcal{H}) as follows. The structure b()b(\mathcal{H}) is multi-sorted, and the domains are the relations 1,,k\mathcal{R}_{1},\dots,\mathcal{R}_{k} viewed as sets of tuples, thus, b()b(\mathcal{H}) has kk domains. For every pair i,j[k]i,j\in[k] (i,ji,j are allowed to be equal) and any s[i],t[j]s\in[\ell_{i}],t\in[\ell_{j}], where i,j\ell_{i},\ell_{j}are the arities of i,j\mathcal{R}_{i},\mathcal{R}_{j}, the structure b()b(\mathcal{H}) contains a binary relation 𝒬stij={(𝐚,𝐛)𝐚i,𝐛j,𝐚[s]=𝐛[t]}\mathcal{Q}^{ij}_{st}=\{(\mathbf{a},\mathbf{b})\mid\mathbf{a}\in\mathcal{R}_{i},\mathbf{b}\in\mathcal{R}_{j},\mathbf{a}[s]=\mathbf{b}[t]\}. We prove that \mathcal{H} and b()b(\mathcal{H}) share many important properties.

Theorem 3.4.

Let \mathcal{H} be a relational structure. Then \mathcal{H} is strongly rectangular (pp-strongly rectangular, pp-rigid, has a Mal’tsev polymorphism) if and only if b()b(\mathcal{H}) is strongly rectangular (pp-strongly rectangular, pp-rigid, has a Mal’tsev polymorphism).

In addition to Theorem 3.4 every relation of b()b(\mathcal{H}) 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 𝖠𝗎𝗍(b()n)\mathsf{Aut}(b(\mathcal{H})^{n}) than 𝖠𝗎𝗍(n)\mathsf{Aut}(\mathcal{H}^{n}) 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 pp the pp-modular quantifier p\exists^{\equiv p} is interpreted as follows

(x1,,xk)=\displaystyle\mathcal{R}(x_{1},\dots,x_{k})= py1,,ysΦ(x1,,xk,y1,,ys) is true\displaystyle\exists^{\equiv p}y_{1},\dots,y_{s}\Phi(x_{1},\dots,x_{k},y_{1},\dots,y_{s})\text{ is true } (1)
#𝖾𝗑𝗍Φ(x1,,xk)0(modp)#𝗉𝖾𝗑𝗍Φ(x1,,xk)0.\displaystyle\Leftrightarrow\mathsf{\#ext}_{\Phi}(x_{1},\dots,x_{k})\not\equiv 0\pmod{p}\Leftrightarrow\mathsf{\#_{p}ext}_{\Phi}(x_{1},\dots,x_{k})\not=0.

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 ={(1,0,0),(1,1,0),(1,1,1),(2,2,2)}\mathcal{R}=\{(1,0,0),(1,1,0),(1,1,1),(2,2,2)\}. Then the formula 3y3z(x,y,z)\exists^{\equiv 3}y\exists^{\equiv 3}z\ \ \mathcal{R}(x,y,z) defines the set {1,2}\{1,2\}, since in every step the number of extensions is not divisible by 3. However, the formula 3y,z(x,y,z)\exists^{\equiv 3}y,z\ \ \mathcal{R}(x,y,z) results in the set {2}\{2\}.

A primitive positive formula that uses modular existential quantifiers mod pp instead of regular ones is call a pp-modular primitive positive. the relation it defines is said to be pp-mpp-definable, and the definition itself is called a pp-mpp-definition. If for the pp-mpp-definition (1) #𝗉𝖾𝗑𝗍Φ(𝐚)=1\mathsf{\#_{p}ext}_{\Phi}(\mathbf{a})=1 for all 𝐚\mathbf{a}\in\mathcal{R}, the pp-mpp definition is said to be strict. By Proposition 5.6 from [12] if \mathcal{R} has a pp-mpp-definition, it has a strict pp-mpp definition.

Finally, we show that adding pp-mpp-definable relations also does not change the complexity of a CSP.

Lemma 4.2.

Let \mathcal{H} be a multi-sorted relational structure with signature σ\sigma, \mathcal{R} be conjunctive definable in \mathcal{H}, and +\mathcal{H}+\mathcal{R} denotes the expansion of \mathcal{H} by the predicate symbol \mathcal{R} that is interpreted as the relation \mathcal{R} in \mathcal{H}. Then #p𝖢𝖲𝖯(+)T#p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}+\mathcal{R})\leq_{T}\#_{p}\mathsf{CSP}(\mathcal{H}).

Proof.

Let \mathcal{R} be defined by a conjunctive formula

𝒬1(y11,,y11)𝒬s(ys1,,yss),\mathcal{Q}_{1}(y_{11},\dots,y_{1\ell_{1}})\wedge\dots\wedge\mathcal{Q}_{s}(y_{s1},\dots,y_{s\ell_{s}}),

where 𝒬1,,𝒬sσ\mathcal{Q}_{1},\dots,\mathcal{Q}_{s}\in\sigma and yij{x1,,xk}y_{ij}\in\{x_{1},\dots,x_{k}\} for all i,ji,j. We use the standard definition of the CSP. Let 𝒫=(V,𝒞)\mathcal{P}=(V,\mathcal{C}) be an instance of #p𝖢𝖲𝖯(+)\#_{p}\mathsf{CSP}(\mathcal{H}+\mathcal{R}). If 𝒞\mathcal{C} contains a constraint of the form (x1,,xk),\langle(x_{1},\dots,x_{k}),\mathcal{R}\rangle, replace it with constraints (y11,,y11),𝒬1,,,(ys1,,yss),𝒬s\langle(y_{11},\dots,y_{1\ell_{1}}),\mathcal{Q}_{1}\rangle,,\dots,\langle(y_{s1},\dots,y_{s\ell_{s}}),\mathcal{Q}_{s}\rangle. As is easily seen, the resulting instance has exactly the same solutions as 𝒫\mathcal{P}. Repeat this procedure while constraints containing \mathcal{R} remain. The resulting instance 𝒫\mathcal{P}^{\prime} has the same solutions as 𝒫\mathcal{P}, and is an instance of #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}). ∎

Theorem 4.3.

Let \mathcal{H} be a be a σ\sigma-structure with equality, and pp a prime. Let \mathcal{R} be a relation that is defined by

R(x1,,xk)=py1,,yΦ(x1,,xk,y)R(x_{1},\dots,x_{k})=\exists^{\equiv p}y_{1},\dots,y_{\ell}\Phi(x_{1},\dots,x_{k},y)

then #p𝖢𝖲𝖯(+)\#_{p}\mathsf{CSP}(\mathcal{H}+\mathcal{R}) is polynomial time reducible to #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}).

Proof.

Without loss of generality we may assume that the pp-mpp-definition of \mathcal{R} given in the theorem is strict. We use the standard definition of the CSP.

Take a problem instance 𝒫=(V,𝒞)\mathcal{P}=(V,\mathcal{C}) of #p𝖢𝖲𝖯(+)\#_{p}\mathsf{CSP}(\mathcal{H}+\mathcal{R}) where 𝒞={C1,,Ct}\mathcal{C}=\{C_{1},\dots,C_{t}\}. Without loss of generality we may assume that C1,,CmC_{1},\dots,C_{m}, mtm\leq t, are the constraints containing \mathcal{R}. Then the arity of CiC_{i} is kk for i[m]i\in[m].

Let 𝒫\mathcal{P}^{\prime} be the problem instance from #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) in which each constraint Ci=(xi1,,xik),C_{i}=\langle(x_{i1},\dots,x_{ik}),\mathcal{R}\rangle is replaced with formula Φ(xi1,,xik,y1i,,yi)\Phi(x_{i1},\dots,x_{ik},y^{i}_{1},\dots,y^{i}_{\ell}) where all the variables yjiy^{i}_{j} are different and do not occur in 𝒫\mathcal{P}.

For a solution φ\varphi to 𝒫\mathcal{P}, as for every i[m]i\in[m], (xi1,,xik)\mathcal{R}(x_{i1},\dots,x_{ik}) is true, φ\varphi can be extended to a solution φ\varphi^{\prime} of 𝒫\mathcal{P}^{\prime}. Since the pp-mpp-definition of \mathcal{R} we use is strict, the number #𝖾𝗑𝗍(φ)\mathsf{\#ext}(\varphi) of such extensions is equal to 1(modp)1\pmod{p}. Therefore, the number of solutions of 𝒫\mathcal{P} and that of 𝒫\mathcal{P}^{\prime} are equal (modp)\pmod{p}. The result follows. ∎

For a structure \mathcal{H} the set of all relations pp-definable in \mathcal{H} is called the relational clone of \mathcal{H} and denoted by \langle\mathcal{H}\rangle. The set of relations pp-mpp-definable in \mathcal{H} is called the modular clone and denoted by p\langle\mathcal{H}\rangle_{p}.

5 Rigidity

Rigid graphs and rigid structures

Recall that the group of automorphisms of a multi-sorted structure \mathcal{H} is denoted by 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{H}). An automorphism π𝖠𝗎𝗍()\pi\in\mathsf{Aut}(\mathcal{H}) has order pp if every component of π\pi has order pp or is the identity permutation, and at least one of the components has order pp. Relational structures without order pp automorphisms are called pp-rigid. By the result of [12] if \mathcal{H} is a pp-rigid graph then #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) is polynomial time if and only if #CSP()\#CSP(\mathcal{H}) is. The following example shows that it is not the case for relational structures.

Example 5.1.

Fix a prime number pp and let Tp={0,,p1,p,p+1}T_{p}=\{0,\dots,p-1,p,p+1\}. A relational structure 𝒯p\mathcal{T}_{p} has the base set TpT_{p} and predicates ,C0,,Cp+1\mathcal{R},C_{0},\dots,C_{p+1}, where CaC_{a} is the constant relation {(a)}\{(a)\} and =Tp2{(0,p),,(p1,p)}\mathcal{R}=T^{2}_{p}-\{(0,p),\dots,(p-1,p)\}. The structure 𝒯p\mathcal{T}_{p} is obviously pp-rigid as it contains all the constant relations. By [6, 40] the decision 𝖢𝖲𝖯(𝒯p)\mathsf{CSP}(\mathcal{T}_{p}) is solvable in polynomial time, while the exact counting problem #𝖢𝖲𝖯(𝒯p)\#\mathsf{CSP}(\mathcal{T}_{p}) is #\#P-complete by [8], as it contains an induced subgraph (or subrelation) {(0,0),(p,0),(p,p)}\{(0,0),(p,0),(p,p)\} (or alternatively it does not have a Mal’tsev polymorphism). In fact, structures like 𝒯p\mathcal{T}_{p} 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 #𝖢𝖲𝖯\#\mathsf{CSP}, see [8]. We now show that #p𝖢𝖲𝖯(𝒯p)\#_{p}\mathsf{CSP}(\mathcal{T}_{p}) can be solved in polynomial time.

We outline the idea of the algorithm here and later will describe a more general algorithm. Let 𝒫=(V,𝒞)\mathcal{P}=(V,\mathcal{C}) be an instance of #p𝖢𝖲𝖯(𝒯p)\#_{p}\mathsf{CSP}(\mathcal{T}_{p}). Perform the following three steps:
Step 1. Establish the arc-consistency of 𝒫\mathcal{P}. That is, repeat the following procedure until no changes are possible. Pick constraints C1=𝐬1,1,C2=𝐬2,2C_{1}=\langle\mathbf{s}_{1},\mathcal{R}_{1}\rangle,C_{2}=\langle\mathbf{s}_{2},\mathcal{R}_{2}\rangle such that W=𝐬1𝐬2W=\mathbf{s}_{1}\cap\mathbf{s}_{2}\neq\emptyset and a tuple 𝐚1\mathbf{a}\in\mathcal{R}_{1}. If there is no tuple 𝐛2\mathbf{b}\in\mathcal{R}_{2} such that 𝗉𝗋W𝐛=𝗉𝗋W𝐚\mathsf{pr}_{W}\mathbf{b}=\mathsf{pr}_{W}\mathbf{a}, remove 𝐚\mathbf{a} from 1\mathcal{R}_{1}.
Step 2. For every variable vVv\in V there is now a domain DvD_{v} such that, for any C=𝐬,𝒞C=\langle\mathbf{s},\mathcal{R}\rangle\in\mathcal{C} with v𝐬v\in\mathbf{s}, it holds that 𝗉𝗋v=Dv\mathsf{pr}_{v}\mathcal{R}=D_{v}. If Dv=D_{v}=\emptyset for some vVv\in V, output 0, as 𝒫\mathcal{P} has no solutions in this case. Otherwise remove all the variables from VV such that |Dv|=1|D_{v}|=1. Denote the resulting problem 𝒫=(V,𝒞)\mathcal{P}^{\prime}=(V^{\prime},\mathcal{C}^{\prime}). The number of solutions to 𝒫\mathcal{P}^{\prime} equals that of 𝒫\mathcal{P}.
Step 3. It is not difficult to see that if Dv{0,,p1}D_{v}\cap\{0,\dots,p-1\}\neq\emptyset for some variable vVv\in V^{\prime} then {0,,p1}Dv\{0,\dots,p-1\}\subseteq D_{v}. Moreover, if φ\varphi is a solution of 𝒫\mathcal{P}^{\prime} and φ(v){0,,p1}\varphi(v)\in\{0,\dots,p-1\}, then any mapping ψ\psi such that ψ(v){0,,p1}\psi(v)\in\{0,\dots,p-1\} and ψ(w)=φ(w)\psi(w)=\varphi(w), wV{v}w\in V^{\prime}-\{v\}, is also a solution of 𝒫\mathcal{P}^{\prime}. For every such variable vv remove {0,,p1}\{0,\dots,p-1\} from DvD_{v}, as the number of solutions φ\varphi to 𝒫\mathcal{P}^{\prime} with φ(v){0,,p1}\varphi(v)\in\{0,\dots,p-1\} is a multiple of pp. Then repeat Step 2.
Step 4. In the remaining case Dv={p,p+1}D_{v}=\{p,p+1\} for every vVv\in V^{\prime}. It is not difficult to see that any mapping from VV^{\prime} to {p,p+1}\{p,p+1\} is a solution of 𝒫\mathcal{P}^{\prime}. Therefore, output 2|V|(modp)2^{|V^{\prime}|}\pmod{p}.

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-pp-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 =({Hi}i[k];1,,m)\mathcal{H}=(\{H_{i}\}_{{i\in[k]}};\mathcal{R}_{1},\dots,\mathcal{R}_{m}) be a multi-sorted relational structure. We say that a structure 𝒢\mathcal{G} is a refinement of \mathcal{H} if it satisfies the following conditions:

  • (a)

    𝒢=({Gi}i[q];𝒬1,,𝒬t)\mathcal{G}=(\{G_{i}\}_{{i\in[q]}};\mathcal{Q}_{1},\dots,\mathcal{Q}_{t}), where the GiG_{i}’ are pairwise disjoint,

  • (b)

    for every i[q]i\in[q], there is an injective mapping ξi:GiHi\xi_{i}:G_{i}\to H_{i^{\prime}} for some i[k]i^{\prime}\in[k],

  • (c)

    for every j[t]j\in[t] there is j[m]j^{\prime}\in[m] with jHi1××Hi\mathcal{R}_{j^{\prime}}\subseteq H_{i_{1}}\times\dots\times H_{i_{\ell}} and 𝒬j={(a1,,a)Gi1××Gi(ξi1(a1),,ξi(a))j}\mathcal{Q}_{j}=\{(a_{1},\dots,a_{\ell})\in G_{i^{\prime}_{1}}\times\dots\times G_{i^{\prime}_{\ell}}\mid(\xi_{i^{\prime}_{1}}(a_{1}),\dots,\xi_{i^{\prime}_{\ell}}(a_{\ell}))\in\mathcal{R}_{j^{\prime}}\}, where GirG_{i^{\prime}_{r}} such that ξir(Gir)Hir𝗉𝗋rj\xi_{i^{\prime}_{r}}(G_{i^{\prime}_{r}})\subseteq H_{i_{r}}\cap\mathsf{pr}_{r}\mathcal{R}_{j^{\prime}}.

Condition (a) is required because the domains of a multi-sorted structure have to be disjoint. Condition (b) basically says that GiG_{i} consists of copies of some elements of HiH_{i^{\prime}}. Condition (c) amounts to saying that 𝒬jj\mathcal{Q}_{j}\subseteq\mathcal{R}_{j^{\prime}}, except it uses copies of the elements of \mathcal{H}. In the notation of item (c) we use ξ(a1,,a)\xi(a_{1},\dots,a_{\ell}) to denote (ξi1(a1),,ξi(a))(\xi_{i^{\prime}_{1}}(a_{1}),\dots,\xi_{i^{\prime}_{\ell}}(a_{\ell})), we use ξ(𝒬j)\xi(\mathcal{Q}_{j}) to denote {ξ(a1,,a)(a1,,a)𝒬j}\{\xi(a_{1},\dots,a_{\ell})\mid(a_{1},\dots,a_{\ell})\in\mathcal{Q}_{j}\}, and ξ1(j)\xi^{-1}(\mathcal{R}_{j^{\prime}}) for {(a1,,a)Gi1××Giξ(a1,,a)j}\{(a_{1},\dots,a_{\ell})\in G_{i^{\prime}_{1}}\times\dots\times G_{i^{\prime}_{\ell}}\mid\xi(a_{1},\dots,a_{\ell})\in\mathcal{R}_{j^{\prime}}\}.

It is possible that while \mathcal{H} is pp-rigid, its refinement is not and Lemma 2.2 may apply.

Example 5.2 (Continued from Example 5.1).

Consider the structure 𝒯p\mathcal{T}_{p} from Example 5.1. Let Gi={i}G_{i}=\{i^{\prime}\} for i{0,,p+1}i\in\{0,\dots,p+1\}, Gp+2={p′′,(p+1)′′}G_{p+2}=\{p^{\prime\prime},(p+1)^{\prime\prime}\}, and Gp+3={0,,(p1),(p+1)}G_{p+3}=\{0^{*},\dots,(p-1)^{*},(p+1)^{*}\}. For convenience we use G1G_{-1} to denote TpT_{p}. The mappings ξi:GiH\xi_{i}:G_{i}\to H simply erase dashes and stars of elements from GiG_{i}. Then for every i,j{1,,p+3}i,j\in\{-1,\dots,p+3\} we introduce relation 𝒬ij=ξ1((ξi(Gi)×ξj(Gj))\mathcal{Q}_{ij}=\xi^{-1}(\mathcal{R}\cap(\xi_{i}(G_{i})\times\xi_{j}(G_{j})). For instance, 𝒬1p+2=({0,,p+1}×{p+1}){(p,p),(p+1,p)}\mathcal{Q}_{-1p+2}=(\{0,\dots,p+1\}\times\{p+1\})\cup\{(p,p),(p+1,p)\}. Also, by construction the only constant relations needed to be introduced are CiC_{i^{\prime}} on GiG_{i} for i{0,,p+1}i\in\{0,\dots,p+1\}. The structure

𝒯p=(G1,,Gp+3;𝒬ij,i,j{1,,p+3}:Ci,i{0,,p+1})\mathcal{T}^{*}_{p}=(G_{-1},\dots,G_{p+3};\mathcal{Q}_{ij},i,j\in\{-1,\dots,p+3\}:C_{i^{\prime}},i\in\{0,\dots,p+1\})

is a refinement of 𝒯p\mathcal{T}_{p}. Therefore the structure 𝒯p\mathcal{T}*_{p} is not pp-rigid, as the collection of mappings πi\pi_{i}, i{1,,p+3}i\in\{-1,\dots,p+3\}, defined as follows is an automorphism. The mappings π0,,πp+2\pi_{0},\dots,\pi_{p+2} are identity mappings. The mapping π1\pi_{-1} is given by π1(p)=p,π1(p+1)=p+1\pi_{-1}(p)=p,\pi_{-1}(p+1)=p+1, and π1(a)=a+1(modp)\pi_{-1}(a)=a+1\pmod{p} for a{0,,p1}a\in\{0,\dots,p-1\}. Finally, πp+3\pi_{p+3} is the restriction of π1\pi_{-1} on Gp+3G_{p+3} (we stars added to the elements of Gp+3G_{p+3}).

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 (x1,,xk)\mathcal{R}(x_{1},\dots,x_{k}) is pp-definable in a multi-sorted structure \mathcal{H} containing the equality predicate if and only if there exists a similar structure 𝒢R\mathcal{G}_{R} containing vertices x1,,xkx_{1},\dots,x_{k} such that for any (a1,,ak)R(a_{1},\dots,a_{k})\in R it holds that (a1,,ak)(a_{1},\dots,a_{k})\in\mathcal{R} if and only if there is a homomorphism from 𝒢\mathcal{G}_{\mathcal{R}} to \mathcal{H} that maps xix_{i} to aia_{i}, i[k]i\in[k]. We will say that 𝒢\mathcal{G}_{\mathcal{R}} defines RR in \mathcal{H}.

Let =({Hi}i[k];1,,m)\mathcal{H}=(\{H_{i}\}_{{i\in[k]}};\mathcal{R}_{1},\dots,\mathcal{R}_{m}) be a multi-sorted relational structure. The Gaifman graph of \mathcal{H} is the graph G()=(V,E)G(\mathcal{H})=(V,E), where V=i[k]HiV=\bigcup_{i\in[k]}H_{i} and (a,b)E(a,b)\in E if and only if there is j[m]j\in[m] and 𝐚j\mathbf{a}\in\mathcal{R}_{j} such that 𝐚[s]=a,𝐚[t]=b\mathbf{a}[s]=a,\mathbf{a}[t]=b for some coordinate positions s,ts,t of j\mathcal{R}_{j}. The structure \mathcal{H} has treewidth dd if G()G(\mathcal{H}) has treewidth dd.

We say that a refinement 𝒢=({Gi}i[q];𝒬1,,𝒬t)\mathcal{G}=(\{G_{i}\}_{{i\in[q]}};\mathcal{Q}_{1},\dots,\mathcal{Q}_{t}) of \mathcal{H} is width dd definable if for every i[q]i\in[q] there is a structure 𝒢i\mathcal{G}_{i} of treewidth at most dd that defines ξi(Gi)\xi_{i}(G_{i}) in \mathcal{H}. In a similar way, we say that 𝒢\mathcal{G} is a definable refinement if for every i[q]i\in[q] the set ξi(Gi)\xi_{i}(G_{i}) is pp-definable in \mathcal{H}. Finally, we say that 𝒢\mathcal{G} is the full width dd definable refinement (respectively, full definable refinement) if it satisfies the following conditions.

  • (1)

    It is a width dd definable refinement (respectively, a definable refinement).

  • (2)

    For every unary relation UU definable in \mathcal{H} by a structure of treewidth at most dd (respectively, pp-definable unary relation) there is i[q]i\in[q] such that ξi(Gi)=U\xi_{i}(G_{i})=U.

  • (3)

    For every relation SS obtained from some relation j\mathcal{R}_{j} by restricting it to domains definable by structures of width dd (respectively by pp-definable domains), there is 𝒬j\mathcal{Q}_{j^{\prime}} such that ξ(𝒬j)=S\xi(\mathcal{Q}_{j^{\prime}})=S.

Since the original domains HiH_{i}, i[k]i\in[k], have trivial pp-definitions, they (or rather their copies) are always among the GjG_{j}’s, and copies of the original relations are also among the 𝒬j\mathcal{Q}_{j}’s, although they may be over different, smaller domains than the i\mathcal{R}_{i}’s.

Next, we extend refinements to CSP instances. Let 𝒢=({Gi}i[q];𝒬1,,𝒬t)\mathcal{G}=(\{G_{i}\}_{{i\in[q]}};\mathcal{Q}_{1},\dots,\mathcal{Q}_{t}) be a refinement of \mathcal{H} and 𝒫=(V,𝒞)\mathcal{P}=(V,\mathcal{C}) an instance of 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}). Recall that every variable vVv\in V is assigned a sort σ(v)[k]\sigma(v)\in[k]. Let σ:V[q]\sigma^{\prime}:V\to[q] be such that ξσ(v):Gσ(v)Hσ(v)\xi_{\sigma^{\prime}(v)}:G_{\sigma^{\prime}(v)}\to H_{\sigma(v)} for each vVv\in V. The instance 𝒫σ=(V,𝒞σ)\mathcal{P}^{\sigma^{\prime}}=(V,\mathcal{C}^{\sigma^{\prime}}) is said to be a refinement for 𝒢\mathcal{G} of 𝒫\mathcal{P} with the sort function σ\sigma^{\prime} if it satisfies the following two conditions

  • (a)

    every vVv\in V is assigned the sort σ(v)\sigma^{\prime}(v);

  • (b)

    for every C=𝐬,𝒞C=\langle\mathbf{s},\mathcal{R}\rangle\in\mathcal{C}, 𝐬=(v1,,v)\mathbf{s}=(v_{1},\dots,v_{\ell}), it holds that ξσ(v)(Gσ(vi))𝗉𝗋i\xi_{\sigma^{\prime}(v)}(G_{\sigma^{\prime}(v_{i})})\subseteq\mathsf{pr}_{i}\mathcal{R}, i[]i\in[\ell], and there is C=𝐬,ξ1()𝒞σC^{\prime}=\langle\mathbf{s},\xi^{-1}(\mathcal{R})\rangle\in\mathcal{C}^{\sigma^{\prime}}.

The refinement 𝒫σ\mathcal{P}^{\sigma^{\prime}} is lossless if for every solution φ\varphi of 𝒫\mathcal{P} the mapping ξ1φ\xi^{-1}\circ\varphi is a solution of 𝒫σ\mathcal{P}^{\sigma^{\prime}}. Suppose 𝒢\mathcal{G} is full pp-definable. The refinement 𝒫σ\mathcal{P}^{\sigma^{\prime}} is minimal lossless if it is lossless and for each vVv\in V, σ(v)\sigma^{\prime}(v) is minimal (with respect to inclusion of ξσ(v)(Gσ(v)\xi_{\sigma^{\prime}(v)}(G_{\sigma^{\prime}(v)} in the original domain). If 𝒢\mathcal{G} is full of treewidth dd, the definition is bit more complicated. As we saw in Section 2.2, the instance 𝒫\mathcal{P} can also be viewed as a structure \mathcal{F} with vertex set VV and such that the solutions of 𝒫\mathcal{P} are exactly the homomorphisms from \mathcal{F} to \mathcal{H}. Then 𝒫σ\mathcal{P}^{\sigma^{\prime}} is minimal lossless of width dd if it is lossless and for every vVv\in V, ξσ(v)(Gσ(v))\xi_{\sigma^{\prime}(v)}(G_{\sigma^{\prime}(v)}) is minimal with respect to inclusion among unary relations defined by a structure 𝒢v\mathcal{G}_{v} of treewidth dd with a designated variable xx and such that there is a homomorphism from 𝒢i\mathcal{G}_{i} to \mathcal{F} mapping xx to vv.

Proposition 5.4.

Let \mathcal{H} be a multi-sorted relational structure.
(1) Let 𝒢\mathcal{G} be the full width dd definable refinement of \mathcal{H}. For any instance 𝒫\mathcal{P} of 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}), its minimal lossless refinement of width dd for 𝒢\mathcal{G} can be found in polynomial time.
(2) Let \mathcal{H} be a relational structure containing all the constant relations and such that 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}) is solvable in polynomial time, and 𝒢\mathcal{G} the full definable refinement of \mathcal{H}. Then for any instance 𝒫\mathcal{P} of 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}), its minimal lossless refinement for 𝒢\mathcal{G} can be found in polynomial time.

Proof.

The method we use in the proof of this proposition is, given an instance 𝒫=(V,𝒞)\mathcal{P}=(V,\mathcal{C}) of 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}), to, first, identify the correct domains for each variable, and then restrict 𝒫\mathcal{P} to those domains and assign to each variable the type associated with its domain.

(1) In this case we first run the dd-consistency algorithm on 𝒫\mathcal{P} (for definitions and properties of this algorithm see [21, 35]). This reduction is lossless. Let GivG_{i_{v}} denote the domain of vv\in after establishing dd-consistency. By the results of [21, 35] every domain GivG_{i_{v}} is definable by a structure of treewidth at most dd and is minimal with this property. Therefore, each GivG_{i_{v}} is a domain of 𝒢\mathcal{G}.

(2) By solving instances of the form 𝒫v=a=(V,𝒞{(v),Ca(v))\mathcal{P}_{v=a}=(V,\mathcal{C}\cup\{\langle(v),C_{a}(v)\rangle) for each vVv\in V and aa from the domain of vv we can determine the sets Dv={aφ(v)=a, φ is a solution of 𝒫}D_{v}=\{a\mid\varphi(v)=a,\text{ $\varphi$ is a solution of $\mathcal{P}$}\}. Since the DvD_{v}’s are defined through a CSP instance, they are pp-definable in \mathcal{H}, and therefore every DvD_{v} is a domain in 𝒢\mathcal{G}. We assign vv the corresponding type. Clearly, the refinement is lossless and minimal. ∎

Example 5.5 (Continued from Example 5.1).

Consider again the structure 𝒯p\mathcal{T}_{p} from Example 5.1 and its refinement 𝒯p\mathcal{T}^{*}_{p} from Example 5.2 to solve #p𝖢𝖲𝖯(𝒯p)\#_{p}\mathsf{CSP}(\mathcal{T}_{p}). It is not hard to see that 𝒯p\mathcal{T}^{*}_{p} is the full refinement of 𝒯p\mathcal{T}_{p} of treewidth 1. Indeed, the set ξi(Gi)\xi_{i}(G_{i}), i{0,,p+1}i\in\{0,\dots,p+1\}, is defined by the pp-formula Ci(x)C_{i}(x), and

ξp+2(Gp+2)(x)=y((x,y)Cp(y)),ξp+3(Gp+3)(x)=y((y,x)C0(y)).\xi_{p+2}(G_{p+2})(x)=\exists y(\mathcal{R}(x,y)\wedge C_{p}(y)),\qquad\xi_{p+3}(G_{p+3})(x)=\exists y(\mathcal{R}(y,x)\wedge C_{0}(y)).

Therefore, by Proposition 5.4 #pCSP(𝒯p)\#_{p}CSP(\mathcal{T}_{p}) is polynomial time reducible to #pCSP(𝒯p)\#_{p}CSP(\mathcal{T}^{*}_{p}). As was observed in Example 5.2, the structure 𝒯p\mathcal{T}^{*}_{p} has an automorphism π\pi of order pp. The reduced structure (𝒯p)π(\mathcal{T}^{*}_{p})^{\pi} has the domains G0,,Gp+1,Gp+2G_{0},\dots,G_{p+1},G_{p+2} unchanged, G1G_{-1} reduced to {p,p+1}\{p,p+1\}, Gp+3G_{p+3} reduced to {(p+1)}\{(p+1)^{*}\}, and all the relations are Cartesian products of the corresponding domains. Such a problem is obviously solvable in polynomial time.

6 Maltsev polymorphisms, pp-Rectangularity, and pp-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 HH be a set. A mapping φ:H3H\varphi:H^{3}\rightarrow H is said to be a Mal’tsev polymorphism of a relation Hn\mathcal{R}\subseteq H^{n} if for any 𝐮1,𝐮2,𝐮3\mathbf{u}_{1},\mathbf{u}_{2},\mathbf{u}_{3}\in\mathcal{R}, it holds that (𝐮1,𝐮2,𝐮3)(\mathbf{u}_{1},\mathbf{u}_{2},\mathbf{u}_{3})\in\mathcal{R} (applied component-wise), and φ\varphi satisfies the equations φ(a,b,b)=φ(b,b,a)=a\varphi(a,b,b)=\varphi(b,b,a)=a, for all a,bHa,b\in H. We say that the relational structure \mathcal{H} has Mal’tsev polymorphism if all relations \mathcal{R}\in\langle\mathcal{H}\rangle admit the same Mal’tsev polymorphism. Similarly, we say that the relational structure \mathcal{H} has Mal’tsev polymorphism is all relations p\mathcal{R}\in\langle\mathcal{H}\rangle_{p} admits to the same Mal’tsev polymorphism.

Let \mathcal{R} be an nn-ary relation over HnH^{n}. In general |||\mathcal{R}| can be exponentially large in nn. However if \mathcal{R} has a Mal’tsev polymorphism, \mathcal{R} admits a concise representation, linear in nn. 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.

pp-Rectangularity. A binary relation A1×A2\mathcal{R}\subseteq A_{1}\times A_{2} is called rectangular if (a,c),(a,d),(b,c)(a,c),(a,d),(b,c)\in\mathcal{R} implies (b,d)(b,d)\in\mathcal{R} for any a,bA1,c,dA2a,b\in A_{1},c,d\in A_{2}. A relation Hn\mathcal{R}\subseteq H^{n} for n2n\geq 2 is rectangular if for every I[n]I\subsetneq[n], the relation RR is rectangular when viewed as a binary relation, a subset of 𝗉𝗋I×𝗉𝗋[n]I\mathsf{pr}_{I}\mathcal{R}\times\mathsf{pr}_{[n]-I}\mathcal{R}. 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 \mathcal{H} is strongly rectangular if every relation \mathcal{R}\in\langle\mathcal{H}\rangle 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 pp-rectangular relations. A relational structure \mathcal{H} is said to be strongly pp-rectangular, if every p\mathcal{R}\in\langle\mathcal{H}\rangle_{p} is rectangular. The following example shows that a relational structure can be strongly rectangular, but not strongly pp-rectangular.

Example 6.2.

Let H={0,1,2}H=\{0,1,2\}, p=2p=2, and =(H;)\mathcal{H}=(H;\mathcal{R}), where \mathcal{R} is the following ternary relation, ={(0,0,0),(0,1,1),(1,0,1),(1,0,2),(1,1,0)}\mathcal{R}=\{(0,0,0),(0,1,1),(1,0,1),(1,0,2),(1,1,0)\}. As is easily see, 2z(x,y,z)\exists^{\equiv 2}z\mathcal{R}(x,y,z) is the relation {(0,0),(0,1),(1,1)}\{(0,0),(0,1),(1,1)\}, which is not rectangular, and so, \mathcal{H} is not strongly 2-rectangular. We now show that \mathcal{H} is strongly rectangular by presenting a Mal’tsev polymorphism of \mathcal{H}. Let f(x,y,z)=x+y+zf(x,y,z)=x+y+z, where addition is modulo 2. For 𝐚=(a1,a2,a3)H3\mathbf{a}=(a_{1},a_{2},a_{3})\in H^{3}, let also 𝐚{0,1}3\mathbf{a}^{\prime}\in\{0,1\}^{3} denote the triple obtained by replacing 2’s with 1’s. Then let g(x,y,z)g(x,y,z) be given by

g(𝐚)={2,if 𝐚{(2,a,a),(a,a,2)aH},f(𝐚)otherwise.g(\mathbf{a})=\left\{\begin{array}[]{ll}2,&\text{if }\mathbf{a}\in\{(2,a,a),(a,a,2)\mid a\in H\},\\ f(\mathbf{a}^{\prime})&\text{otherwise}.\end{array}\right.

It is straightforward that gg is a Mal’tsev operation and is a polymorphism of \mathcal{H}.

pp-Balancedness. An nn-by-mm matrix MM 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 (x,y,z)\mathcal{R}(x,y,z) be a ternary relation, a subset of A1×A2×A3A_{1}\times A_{2}\times A_{3}. We call \mathcal{R} balanced if the matrix 𝖬|A1|×|A2|\mathsf{M}_{\mathcal{R}}\in\mathbb{Z}^{|A_{1}|\times|A_{2}|}, where 𝖬[x,y]=|{zA3:(x,y,z)}|\mathsf{M}_{\mathcal{R}}[x,y]=|\{z\in A_{3}:(x,y,z)\in\mathcal{R}\}| such that xA1x\in A_{1} and yA2y\in A_{2} is a rank-1 block matrix. A relation \mathcal{R} of arity n>3n>3 is balanced if every representation of \mathcal{R} as a ternary relation, a subset of Hk×H×HnkH^{k}\times H^{\ell}\times H^{n-k-\ell} is balanced. A relational structure \mathcal{H} (a constraint language Γ\Gamma) is called strongly balanced, if every at least ternary relation \mathcal{R}\in\langle\mathcal{H}\rangle (Γ\mathcal{R}\in\langle\Gamma\rangle) 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 (x,y,z)\mathcal{R}(x,y,z) be a ternary relation on A1×A2×A3A_{1}\times A_{2}\times A_{3}. The relation \mathcal{R}, is pp-balanced if the matrix 𝖬p|A1|×|A2|\mathsf{M}_{\mathcal{R}}\in\mathbb{Z}_{p}^{|A_{1}|\times|A_{2}|} given by

𝖬[x,y]|{(x,y,z)H3:(x,y,z)}|(modp),\mathsf{M}_{\mathcal{R}}[x,y]\equiv|\{(x,y,z)\in H^{3}:(x,y,z)\in\mathcal{R}\}|\pmod{p}, (2)

for xA1x\in A_{1} and yA2y\in A_{2}, is a rank-1 block matrix (the rank is computed in p\mathbb{Z}_{p}). A relation \mathcal{R} on HH of arity n>3n>3 is pp-balanced if every representation of \mathcal{R} as a ternary relation, a subset of Hk×H×HnkH^{k}\times H^{\ell}\times H^{n-k-\ell}, is pp-balanced. A relational structure \mathcal{H} (a constraint language Γ\Gamma) is called strongly pp-balanced if every relation p\mathcal{R}\in\langle\mathcal{H}\rangle_{p} (Γp\mathcal{R}\in\langle\Gamma\rangle_{p}) is pp-balanced.

The case p=2p=2 is somewhat special.

Lemma 6.4.

A relational structure \mathcal{H} is strongly 2-rectangular if and only if it is strongly 2-balanced.

Proof.

Suppose that 2\langle\mathcal{H}\rangle_{2} contains a non-rectangular nn-ary relation \mathcal{R}. Since 2\langle\mathcal{H}\rangle_{2} is closed under renaming coordinates, we may assume that for some k<nk<n there are 𝐚,𝐛𝗉𝗋[k]\mathbf{a},\mathbf{b}\in\mathsf{pr}_{[k]}\mathcal{R} and 𝐜,𝐝[n][k]\mathbf{c},\mathbf{d}\in\mathcal{R}_{[n]-[k]}\mathcal{R} such that (𝐚,𝐜),(𝐚,𝐝),(𝐛,𝐜)(\mathbf{a},\mathbf{c}),(\mathbf{a},\mathbf{d}),(\mathbf{b},\mathbf{c})\in\mathcal{R}, but (𝐛,𝐝)(\mathbf{b},\mathbf{d})\not\in\mathcal{R}. Consider the relation

𝒬(x1,,xn,xn+1)=(x1,,xn)(xn=xn+1).\mathcal{Q}(x_{1},\dots,x_{n},x_{n+1})=\mathcal{R}(x_{1},\dots,x_{n})\wedge(x_{n}=x_{n+1}).

Clearly, 𝒬2\mathcal{Q}\in\langle\mathcal{H}\rangle_{2}. For the matrix 𝖬𝒬\mathsf{M}_{\mathcal{Q}} constructed for kk and =n\ell=n we have 𝖬𝒬[𝐚,𝐜]=𝖬𝒬[𝐚,𝐝]=𝖬𝒬[𝐛,𝐜]=1\mathsf{M}_{\mathcal{Q}}[\mathbf{a},\mathbf{c}]=\mathsf{M}_{\mathcal{Q}}[\mathbf{a},\mathbf{d}]=\mathsf{M}_{\mathcal{Q}}[\mathbf{b},\mathbf{c}]=1 and 𝖬𝒬[𝐛,𝐝]=0\mathsf{M}_{\mathcal{Q}}[\mathbf{b},\mathbf{d}]=0, showing that 𝖬𝒬\mathsf{M}_{\mathcal{Q}} is not rank-1 block matrix.

Conversely, suppose that an nn-ary relation 2\mathcal{R}\in\langle\mathcal{H}\rangle_{2} is not 22-balanced, that is, for some k<<nk<\ell<n the matrix 𝖬\mathsf{M}_{\mathcal{R}} is not rank-1 block. Since the entries of 𝖬\mathsf{M}_{\mathcal{R}} are from 2\mathbb{Z}_{2}, it means that for some 𝐚,𝐛𝗉𝗋[k]\mathbf{a},\mathbf{b}\in\mathsf{pr}_{[k]}\mathcal{R} and 𝐜,𝐝𝗉𝗋[]\mathbf{c},\mathbf{d}\in\mathsf{pr}_{[\ell]}\mathcal{R}, it holds that 𝖬𝒬[𝐚,𝐜]=𝖬𝒬[𝐚,𝐝]=𝖬𝒬[𝐛,𝐜]=1\mathsf{M}_{\mathcal{Q}}[\mathbf{a},\mathbf{c}]=\mathsf{M}_{\mathcal{Q}}[\mathbf{a},\mathbf{d}]=\mathsf{M}_{\mathcal{Q}}[\mathbf{b},\mathbf{c}]=1 and 𝖬𝒬[𝐛,𝐝]=0\mathsf{M}_{\mathcal{Q}}[\mathbf{b},\mathbf{d}]=0. Therefore, the tuples (𝐚,𝐜),(𝐚,𝐝),(𝐛,𝐜)H(\mathbf{a},\mathbf{c}),(\mathbf{a},\mathbf{d}),(\mathbf{b},\mathbf{c})\in H^{\ell} have an odd number of extensions to a tuple from \mathcal{R}, while (𝐛,𝐝)H(\mathbf{b},\mathbf{d})\in H^{\ell} has an even number of such extensions (including 0). Therefore the relation

𝒬(x1,,x)=2x+1,,xn(x1,,xn)\mathcal{Q}(x_{1},\dots,x_{\ell})=\exists^{\equiv 2}x_{\ell+1},\dots,x_{n}\;\mathcal{R}(x_{1},\dots,x_{n})

belongs to 2\langle\mathcal{H}\rangle_{2} and is not rectangular. ∎

pp-Permutability. A congruence of a relational structure \mathcal{H} is an equivalence relation θ\theta on HH that is definable by a pp-formula in \mathcal{H}. More generally, let 𝒮\mathcal{S}\in\langle\mathcal{H}\rangle be a kk-ary relation. A congruence of 𝒮\mathcal{S} is a 2k2k-ary relation pp-definable in \mathcal{H} that is an equivalence relation on 𝒮\mathcal{S}. We denote the set of all congruences of \mathcal{H} (of 𝒮\mathcal{S}) by 𝖢𝗈𝗇()\mathsf{Con}(\mathcal{H}) (respectively, by 𝖢𝗈𝗇(𝒮)\mathsf{Con}(\mathcal{S})). By \circ we denote the product of binary relations: (a,b)𝒬(a,b)\in\mathcal{R}\circ\mathcal{Q} if and only if there is cc such that (a,c)(a,c)\in\mathcal{R} and (c,b)𝒬(c,b)\in\mathcal{Q}. We say \mathcal{H} is congruence permutable if for all α,β𝖢𝗈𝗇()\alpha,\beta\in\mathsf{Con}(\mathcal{R}), where \mathcal{R}\in\langle\mathcal{H}\rangle, it holds that αβ=βα\alpha\circ\beta=\beta\circ\alpha.

Congruence pp-permutability is defined as follows: A pp-congruence of \mathcal{H} or of 𝒮p\mathcal{S}\in\langle\mathcal{H}\rangle_{p} is an equivalence relation on HH or 𝒮\mathcal{S}, respectively, that is pp-mpp-definable in \mathcal{H}. We denote the set of all pp-congruences of \mathcal{H} (𝒮\mathcal{S}) by 𝖢𝗈𝗇p()\mathsf{Con}_{p}(\mathcal{H}) (𝖢𝗈𝗇p(𝒮)\mathsf{Con}_{p}(\mathcal{S})). By \stackMath\stackinsetccp\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}} we denote the product of binary relations: (a,b)\stackMath\stackinsetccp𝒬(a,b)\in\mathcal{R}\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\mathcal{Q} if and only if the number of elements cc such that (a,c)(a,c)\in\mathcal{R} and (c,b)𝒬(c,b)\in\mathcal{Q} is not a multiple of pp. We say that \mathcal{H} is congruence pp-permutable if for all α,β𝖢𝗈𝗇p(𝒮)\alpha,\beta\in\mathsf{Con}_{p}(\mathcal{S}), where 𝒮p\mathcal{S}\in\langle\mathcal{H}\rangle_{p}, we have α\stackMath\stackinsetccpβ=β\stackMath\stackinsetccpα\alpha\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\beta=\beta\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\alpha. In other words, for any 𝐚,𝐛𝒮\mathbf{a},\mathbf{b}\in\mathcal{S}, if the number of tuples 𝐜𝒮\mathbf{c}\in\mathcal{S} such that (𝐚,𝐜)α,(𝐜,𝐛)β(\mathbf{a},\mathbf{c})\in\alpha,(\mathbf{c},\mathbf{b})\in\beta is not equal to 0(modp)0\pmod{p}, then so is the number of elements 𝐝𝒮\mathbf{d}\in\mathcal{S} with (𝐛,𝐝)α,(𝐝,𝐚)β(\mathbf{b},\mathbf{d})\in\alpha,(\mathbf{d},\mathbf{a})\in\beta.

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 \mathcal{H} the following are equivalent:
(1) \mathcal{H} has a Mal’tsev polymorphism;
(2) \mathcal{H} is strongly rectangular;
(3) \mathcal{H} 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 \mathcal{H} is congruence pp-permutable, then it is strongly pp-rectangular.

Proof.

Suppose \mathcal{H} is congruence pp-permutable and consider a pp-mpp-definable relation Hr×Hs\mathcal{R}\subseteq H^{r}\times H^{s}. We need to show that \mathcal{R} is pp-rectangular. Define a relation 1\sim_{1}\subseteq\mathcal{R} by (𝐱1,𝐲1)1(𝐱2,𝐲2)(\mathbf{x}_{1},\mathbf{y}_{1})\sim_{1}(\mathbf{x}_{2},\mathbf{y}_{2}) if and only if 𝐱1=𝐱2\mathbf{x}_{1}=\mathbf{x}_{2}. This relation is pp-mpp-definable in \mathcal{H}, by

(𝐱1,𝐲1)1(𝐱2,𝐲2):=(𝐱1,𝐲1)(𝐱2,𝐲2)(𝐱1=𝐱2)(\mathbf{x}_{1},\mathbf{y}_{1})\sim_{1}(\mathbf{x}_{2},\mathbf{y}_{2}):=\mathcal{R}(\mathbf{x}_{1},\mathbf{y}_{1})\wedge\mathcal{R}(\mathbf{x}_{2},\mathbf{y}_{2})\wedge(\mathbf{x}_{1}=\mathbf{x}_{2})

It is easy to check that this is also an equivalence relation and its equivalence classes correspond to tuples 𝐱𝗉𝗋[r]\mathbf{x}\in\mathsf{pr}_{[r]}\mathcal{R}.

Hence it is a congruence of \mathcal{R}. In a similar way, define a congruence 2\sim_{2} on \mathcal{R} by (𝐱1,𝐲1)2(𝐱2,𝐲2)(\mathbf{x}_{1},\mathbf{y}_{1})\sim_{2}(\mathbf{x}_{2},\mathbf{y}_{2}) if and only if 𝐲1=𝐲2\mathbf{y}_{1}=\mathbf{y}_{2}. Let α=1\stackMath\stackinsetccp2\alpha=\sim_{1}\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\sim_{2}.

Suppose ((𝐚,𝐛),(𝐜,𝐝))α((\mathbf{a},\mathbf{b}),(\mathbf{c},\mathbf{d}))\in\alpha. Then there exists (𝐮,𝐯)(\mathbf{u},\mathbf{v})\in\mathcal{R} such that (𝐚,𝐛)1(𝐮,𝐯)(\mathbf{a},\mathbf{b})\sim_{1}(\mathbf{u},\mathbf{v}) and (𝐮,𝐯)2(𝐜,𝐝)(\mathbf{u},\mathbf{v})\sim_{2}(\mathbf{c},\mathbf{d}). Thus, 𝐚=𝐮\mathbf{a}=\mathbf{u} and 𝐝=𝐯\mathbf{d}=\mathbf{v}. Therefore, (𝐚,𝐛),(𝐚,𝐝),(𝐜,𝐝)(\mathbf{a},\mathbf{b}),(\mathbf{a},\mathbf{d}),(\mathbf{c},\mathbf{d})\in\mathcal{R}. Now, congruence pp-permutability implies that 1\stackMath\stackinsetccp2=2\stackMath\stackinsetccp1\sim_{1}\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\sim_{2}=\sim_{2}\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\sim_{1}. Hence ((𝐜,𝐝),(𝐚,𝐛))α((\mathbf{c},\mathbf{d}),(\mathbf{a},\mathbf{b}))\in\alpha. Thus, there exists (𝐮,𝐯)(\mathbf{u}^{\prime},\mathbf{v}^{\prime})\in\mathcal{R} such that (𝐜,𝐝)1(𝐮,𝐯)(\mathbf{c},\mathbf{d})\sim_{1}(\mathbf{u}^{\prime},\mathbf{v}^{\prime}) and (𝐮,𝐯)2(𝐚,𝐛)(\mathbf{u}^{\prime},\mathbf{v}^{\prime})\sim_{2}(\mathbf{a},\mathbf{b}). Thus, 𝐜=𝐮\mathbf{c}=\mathbf{u}^{\prime} and 𝐛=𝐯\mathbf{b}=\mathbf{v}^{\prime}. Therefore, (𝐚,𝐜),(𝐜,𝐛),(𝐛,𝐝)(\mathbf{a},\mathbf{c}),(\mathbf{c},\mathbf{b}),(\mathbf{b},\mathbf{d})\in\mathcal{R}. The strong pp-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 H={a1,a2,a3,a4,a5,a6,a7}H=\{a_{1},a_{2},a_{3},a_{4},a_{5},a_{6},a_{7}\}. We define a relational structure \mathcal{H} over the set HH with the following relations:

  • All constant relations CaiC_{a_{i}} for all i[7]i\in[7],

  • The equivalence relation \mathcal{R} with equivalence classes a1/={a1,a2,a3}{a_{1}}/_{\mathcal{R}}=\{a_{1},a_{2},a_{3}\} and a4/={a4,a5,a6,a7}{a_{4}}/_{\mathcal{R}}=\{a_{4},a_{5},a_{6},a_{7}\},

  • The equivalence relation 𝒬\mathcal{Q} with equivalence classes a1/𝒬={a1,a2,a4,a5}{a_{1}}/_{\mathcal{Q}}=\{a_{1},a_{2},a_{4},a_{5}\} and a3/𝒬={a3,a6,a7}{a_{3}}/_{\mathcal{Q}}=\{a_{3},a_{6},a_{7}\}.

The structure =(H;,𝒬,Ca1,,Ca7)\mathcal{H}=(H;\mathcal{R},\mathcal{Q},C_{a_{1}},...,C_{a_{7}}) is 22-rigid due to the presence of all constant relations. It is not congruence 22-permutable, since (a1,a6)\stackMath\stackinsetccp𝒬(a_{1},a_{6})\in\mathcal{R}\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\mathcal{Q} but (a1,a6)𝒬\stackMath\stackinsetccp(a_{1},a_{6})\not\in\mathcal{Q}\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\mathcal{R}. We now show that \mathcal{H} is strongly 22-rectangular.

Suppose an nn-ary 𝒮2\mathcal{S}\in\langle\mathcal{H}\rangle_{2}, k[n]k\in[n], and 𝐚,𝐛𝗉𝗋[k]𝒮,𝐜,𝐝𝗉𝗋[n][k]𝒮\mathbf{a},\mathbf{b}\in\mathsf{pr}_{[k]}\mathcal{S},\mathbf{c},\mathbf{d}\in\mathsf{pr}_{[n]-[k]}\mathcal{S} witness that \mathcal{R} is not rectangular, that is, (𝐚,𝐜),(𝐚,𝐝),(𝐛,𝐜)𝒮(\mathbf{a},\mathbf{c}),(\mathbf{a},\mathbf{d}),(\mathbf{b},\mathbf{c})\in\mathcal{S}, but (𝐛,𝐝)𝒮(\mathbf{b},\mathbf{d})\not\in\mathcal{S}. Consider a 2-mpp-definition of 𝒮\mathcal{S}

𝒮(x1,,xn)=2y1,,ymΦ(x1,,xn,y1,,ym).\mathcal{S}(x_{1},\dots,x_{n})=\exists^{\equiv 2}y_{1},\dots,y_{m}\Phi(x_{1},\dots,x_{n},y_{1},\dots,y_{m}).

Note that all the equivalence classes of \mathcal{R} and 𝒬\mathcal{Q} except for {a3}\{a_{3}\} contain 2 elements. This means that as #𝖾𝗑𝗍Φ(𝐚,𝐜)\mathsf{\#ext}_{\Phi}(\mathbf{a},\mathbf{c}) is odd, it has to be that Φ(𝐚,𝐜,a3,,a3)\Phi(\mathbf{a},\mathbf{c},a_{3},\dots,a_{3}) is true. The same holds for Φ(𝐚,𝐝,a3,,a3),Φ(𝐛,𝐜,a3,,a3)\Phi(\mathbf{a},\mathbf{d},a_{3},\dots,a_{3}),\Phi(\mathbf{b},\mathbf{c},a_{3},\dots,a_{3}), but Φ(𝐛,𝐝,a3,,a3)\Phi(\mathbf{b},\mathbf{d},a_{3},\dots,a_{3}) is false. This is however impossible. Indeed, as all the predicates of Φ\Phi of the form (xi,xj),𝒬(xi,xj),(yi,yj)\mathcal{R}(x_{i},x_{j}),\mathcal{Q}(x_{i},x_{j}),\mathcal{R}(y_{i},y_{j}), and 𝒬(yi,yj)\mathcal{Q}(y_{i},y_{j}) are true on (𝐛,𝐝,a3,,a3)(\mathbf{b},\mathbf{d},a_{3},\dots,a_{3}) (in the former two cases due to the rectangularity of ,𝒬\mathcal{R},\mathcal{Q}), it has to be that Φ(𝐛,𝐝,a3,,a3)\Phi(\mathbf{b},\mathbf{d},a_{3},\dots,a_{3}) is false implies that some predicate (xi,yj)\mathcal{R}(x_{i},y_{j}) or 𝒬(xi,yj)\mathcal{Q}(x_{i},y_{j}) is false. Suppose i[k]i\in[k] and (xi,yj)\mathcal{R}(x_{i},y_{j}) is false. This means that (𝐛i,a3)\mathcal{R}(\mathbf{b}_{i},a_{3}) is false, which contradicts the assumption Φ(𝐛,𝐜,a3,,a3)\Phi(\mathbf{b},\mathbf{c},a_{3},\dots,a_{3}) is true.

Example 6.8 (Example 6.2 re-stated).

Let H={0,1,2}H=\{0,1,2\}, and =(H;,C0,C1,C2)\mathcal{H}=(H;\mathcal{R},C_{0},C_{1},C_{2}), where \mathcal{R} is the ternary relation defined as

={(0,0,0),(0,1,1),(1,0,1),(1,0,2),(1,1,0)}.\mathcal{R}=\{(0,0,0),(0,1,1),(1,0,1),(1,0,2),(1,1,0)\}.

The constants C0,C1,C2C_{0},C_{1},C_{2} correspond to 0,1,20,1,2 respectively. Thus, \mathcal{H} is 2-rigid.

Define the relation 2z(x,y,z)\exists^{\equiv 2}z\mathcal{R}(x,y,z) as {(0,0),(0,1),(1,1)}\{(0,0),(0,1),(1,1)\}, which is not rectangular. Hence, \mathcal{H} is not strongly 2-rectangular. As shown in Example 6.2, \mathcal{H} has a Mal’tsev polymorphism. Therefore, by Proposition 6.5, it is strongly rectangular.

Example 6.9.

Let H={a1,a2,a3,a4,a5,a6}H=\{a_{1},a_{2},a_{3},a_{4},a_{5},a_{6}\}. We define a relational structure \mathcal{H} over the set HH with the following relations:

  • All constant relations CaiC_{a_{i}} for all i[6]i\in[6],

  • The equivalence relation \mathcal{R} with equivalence classes a1/={a1,a2,a3,a4}a_{1}/_{\mathcal{R}}=\{a_{1},a_{2},a_{3},a_{4}\} and a5/={a5,a6}a_{5}/_{\mathcal{R}}=\{a_{5},a_{6}\},

  • The equivalence relation 𝒬\mathcal{Q} with equivalence classes a1/𝒬={a1,a2,a5,a6}a_{1}/_{\mathcal{Q}}=\{a_{1},a_{2},a_{5},a_{6}\} and a3/𝒬={a3,a4}a_{3}/_{\mathcal{Q}}=\{a_{3},a_{4}\}.

The structure =(H;,𝒬,Ca1,,Ca6)\mathcal{H}=(H;\mathcal{R},\mathcal{Q},C_{a_{1}},\ldots,C_{a_{6}}) is 22-rigid due to the presence of all constant relations. According to Proposition 6.5, it does not have a Mal’tsev polymorphism because 𝒬\mathcal{R}\circ\mathcal{Q} is not rectangular. We only need to demonstrate that it is congruence 2-permutable. By Lemma 6.6, this would imply that \mathcal{H} is also strongly 2-rectangular. Observe that a1a_{1} and a2a_{2}, a3a_{3} and a4a_{4}, a5a_{5} and a6a_{6} are interchangeable. That is, if 2\mathcal{R}^{\prime}\in\langle\mathcal{H}\rangle_{2} such that Hn\mathcal{R}^{\prime}\subseteq H^{n}, n>1n>1, and (ai,𝐛)(a_{i},\mathbf{b})\in\mathcal{R}^{\prime}, where 𝐛Hn1\mathbf{b}\in H^{n-1}, then (ai+1,𝐛)(a_{i+1},\mathbf{b})\in\mathcal{R}^{\prime} for all i[3]i\in[3], unless |𝗉𝗋1|=1|\mathsf{pr}_{1}\mathcal{R}^{\prime}|=1. Now, let 𝒬\mathcal{Q}^{\prime} and \mathcal{R}^{\prime} be congruences of 2\mathcal{R}^{\prime}\in\langle\mathcal{H}\rangle_{2}. Then

(𝒬\stackMath\stackinsetccp𝒮)(x,y)=2z(𝒬(x,z)𝒮(z,y)).(\mathcal{Q}^{\prime}\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\mathcal{S}^{\prime})(x,y)=\exists^{\equiv 2}z\,(\mathcal{Q}^{\prime}(x,z)\wedge\mathcal{S}^{\prime}(z,y)).

By the simple fact stated earlier, for any (x,y)(x,y), the number of extensions is always even which is zero modulo 22. Hence, 𝒬\stackMath\stackinsetccp𝒮=𝒮\stackMath\stackinsetccp𝒬=\mathcal{Q}^{\prime}\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\mathcal{S}^{\prime}=\mathcal{S}^{\prime}\stackMath\stackinset{c}{}{c}{}{\scriptscriptstyle p}{\scalebox{0.65}{$\bigcirc$}}\mathcal{Q}^{\prime}=\emptyset, unless ||=1|\mathcal{R}^{\prime}|=1.

Refer to caption
(a) Congruence Permutability, Strong Rectangularity, and Mal’tsev polymorphism are equavalent (See [28, 17, 5]). Also, Strong Balancedness implies Strong Rectangularity(See [17]).
Refer to caption
(b) The only connection that is preserved for the modular case is Congruence pp-Permutability implies Strong pp-rectangularity. Also, Strong 2-rectangularity is equivalence to Strong 2-Balancedness. For proofs and counterexample See Section 6
Figure 2: The connection between 4 properties is shown above. Figure (2(a)) shows the connection for the exact counting. Figure (2(b)) shows the the connection for the modular counterparts.

7 An Algorithm for Parity

In this section we show how to solve #2𝖢𝖲𝖯()\#_{2}\mathsf{CSP}(\mathcal{H}) for a relational structure \mathcal{H} that is 2-rigid, strongly 2-rectangular, and has a Mal’tsev polymorphism φ\varphi. Observe that an instance of #2𝖢𝖲𝖯()\#_{2}\mathsf{CSP}(\mathcal{H}) can be viewed as a conjunctive formula over \mathcal{H}, and the set of solutions is a conjunctive definable relation from 2\langle\mathcal{H}\rangle_{2}. Therefore, problem we solve is, given a conjunctive definition of a relation \mathcal{R}, find the parity of the number of elements in \mathcal{R}.

The main idea is to reduce the arity of \mathcal{R}. In other words, we attempt to find a relation ~\widetilde{\mathcal{R}}, still 2-mpp-definable in \mathcal{H}, such that ~Hn1\widetilde{\mathcal{R}}\subseteq H^{n-1} and |~|||(mod2)|\widetilde{\mathcal{R}}|\equiv|\mathcal{R}|\pmod{2}. To accomplish this, we use witness functions first introduced in [17].

7.1 Frames and Witness Functions

Suppose that \mathcal{R} is an nn-ary relation with a Mal’tsev polymorphism φ\varphi. For each i[n]i\in[n] we define the following relation i\sim_{i} on 𝗉𝗋i\mathsf{pr}_{i}\mathcal{R}: aiba\sim_{i}b if there exist tuples 𝐱Hi1\mathbf{x}\in H^{i-1} and 𝐲a,𝐲bHni\mathbf{y}_{a},\mathbf{y}_{b}\in H^{n-i} such that (𝐱,a,𝐲a) and (𝐱,b,𝐲b)(\mathbf{x},a,\mathbf{y}_{a})\in\mathcal{R}\text{ and }(\mathbf{x},b,\mathbf{y}_{b})\in\mathcal{R}. For the case i=1i=1, we have a1ba\sim_{1}b for all a,b𝗉𝗋1a,b\in\mathsf{pr}_{1}\mathcal{R} because they share the common empty prefix ε\varepsilon. The following two results are straightforward corollaries of the rectangularity of \mathcal{R} and were used in [17].

Lemma 7.1 (Folklore).

i\sim_{i} is an equivalence relation for all i[n]i\in[n].

Let i\mathcal{E}_{i} denote the collection of the equivalence classes of i\sim_{i}, and i={i,1,,i,i}\mathcal{E}_{i}=\{\mathcal{E}_{i,1},\dots,\mathcal{E}_{i,\ell_{i}}\}, i,j𝗉𝗋i\mathcal{E}_{i,j}\subseteq\mathsf{pr}_{i}\mathcal{R}, where j[i]j\in[\ell_{i}]. We often refer to these classes as Frame Classes.

Lemma 7.2 (Folklore).

If aiba\sim_{i}b and 𝐱\mathbf{x}\in\mathcal{R} with xi=ax_{i}=a, then there is a 𝐲\mathbf{y}\in\mathcal{R} with 𝐲i=b\mathbf{y}_{i}=b and 𝗉𝗋[i1]𝐱=𝗉𝗋[i1]𝐲\mathsf{pr}_{[i-1]}\mathbf{x}=\mathsf{pr}_{[i-1]}\mathbf{y}.

A mapping ω:[n]×HHn{}\omega:[n]\times H\rightarrow H^{n}\cup\{\bot\} is called a witness function of \mathcal{R} if

  • i.

    For any i[n]i\in[n] and a𝗉𝗋ia\not\in\mathsf{pr}_{i}\mathcal{R}, ω(i,a)=\omega(i,a)=\bot;

  • ii.

    For any i[n]i\in[n] and a𝗉𝗋ia\in\mathsf{pr}_{i}\mathcal{R}, ω(i,a)\omega(i,a)\in\mathcal{R} is a witness for (i,a)(i,a), i.e., 𝗉𝗋iω(i,a)=a\mathsf{pr}_{i}\omega(i,a)=a;

  • iii.

    For any i[n]i\in[n] and a,b𝗉𝗋ia,b\in\mathsf{pr}_{i}\mathcal{R} with aiba\sim_{i}b, we have 𝗉𝗋[i1]ω(i,a)=𝗉𝗋[i1]ω(i,b)\mathsf{pr}_{[i-1]}\omega(i,a)=\mathsf{pr}_{[i-1]}\omega(i,b).

A witness function ω\omega provides a concise representation of \mathcal{R}. Let F={ω(i,a)i[n],a𝗉𝗋i}F=\{\omega(i,a)\mid i\in[n],a\in\mathsf{pr}_{i}\mathcal{R}\}. Such a set of tuples is called a frame of \mathcal{R}. 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 \mathcal{H} be a relational structure. If \mathcal{H} has a Mal’tsev polymorphism, then the witness function for the relation (x1,,xn)=i[m]i(xi1,,xit)\mathcal{R}(x_{1},\dots,x_{n})=\bigwedge_{i\in[m]}\mathcal{R}_{i}(x_{i_{1}},\dots,x_{i_{t}}) can be computed in O(mn4)O(mn^{4}).

We will also use other algorithmic properties of frames.

Proposition 7.4 ([17]).

Given a frame FF for (x1,x2,,xn)\mathcal{R}(x_{1},x_{2},...,x_{n}), a frame for (x1,x2,,xn)Ca(xs)\mathcal{R}(x_{1},x_{2},...,x_{n})\wedge C_{a}(x_{s}), i.e., xsx_{s}, s[n]s\in[n], is the constant aa, can be constructed in O(n2)O(n^{2}) time.

We denote the relation (x1,,xn)Ca(xs)\mathcal{R}(x_{1},...,x_{n})\wedge C_{a}(x_{s}) by sa\mathcal{R}^{s\leftarrow a}, its j\sim_{j} relations by jsa\sim^{s\leftarrow a}_{j}, its Frame Classes by s,tsa\mathcal{E}^{s\leftarrow a}_{s,t}, and its witness function by ωsa\omega^{s\leftarrow a}.

Proposition 7.5 ([17]).

Let I[n]I\subseteq[n]. Given a frame FF for (x1,x2,,xn)\mathcal{R}(x_{1},x_{2},...,x_{n}), a frame for (x1,x2,,xn)(sICas(xs))\mathcal{R}(x_{1},x_{2},...,x_{n})\wedge(\bigwedge_{s\in I}C_{a_{s}}(x_{s})), i.e., xsx_{s} is the constant asHa_{s}\in H, sIs\in I can be constructed in O(n3)O(n^{3}) time.

Lemma 7.6.

Let i[n1]i\in[n-1], a,b,cHa,b,c\in H. For all s+1ins+1\leq i\leq n, if bisacb\sim^{s\leftarrow a}_{i}c, then bicb\sim_{i}c.

Proof.

The proof is straightforward from the definition. Suppose bisacb\sim^{s\leftarrow a}_{i}c. Then, there exist 𝐱Hi1\mathbf{x}\in H^{i-1} and 𝐲b,𝐲cHni\mathbf{y}_{b},\mathbf{y}_{c}\in H^{n-i} such that (𝐱,b,𝐲b),(𝐱,c,𝐲c)sa(\mathbf{x},b,\mathbf{y}_{b}),(\mathbf{x},c,\mathbf{y}_{c})\in\mathcal{R}^{s\leftarrow a} and 𝗉𝗋s𝐱=a\mathsf{pr}_{s}\mathbf{x}=a. By the definition, bicb\sim_{i}c. ∎

Proposition 7.7 ([17], [5]).

Given a frame FF for (x1,x2,,xn)\mathcal{R}(x_{1},x_{2},...,x_{n}), a frame for 𝒬(x1,x2,xn1)=y(x1,,xn1,y)\mathcal{Q}(x_{1},x_{2}...,x_{n-1})=\exists y\mathcal{R}(x_{1},...,x_{n-1},y), can be constructed in O(n)O(n) time.

7.2 The Algorithm

In order to find ~\widetilde{\mathcal{R}} as explained in the beginning of Section 7 we use a witness function and frame of \mathcal{R} to compute a frame and witness function of ~\widetilde{\mathcal{R}}. If we can find such a ~\widetilde{\mathcal{R}}, we repeat this process for n1n-1 times. Eventually, we obtain ~H\widetilde{\mathcal{R}}^{*}\subseteq H, whose cardinality can be easily found.

First, we assume that the witness function for \mathcal{R} and ~\widetilde{\mathcal{R}} is given. We prove we prove the following.

Theorem 7.8.

Let \mathcal{H} be a 2-rigid, strongly 2-rectangular, 2\langle\mathcal{H}\rangle_{2} has Mal’tsev polymorphism , and let 2\mathcal{R}\in\langle\mathcal{H}\rangle_{2} be an nn-ary relation. Given a frame FF and a witness function ω\omega for \mathcal{R}, the parity of \mathcal{R} can be computed in O(n)O(n) time.

In Section 7.2.2, we demonstrate an efficient method to compute the witness function in O(n4)O(n^{4}). Consequently, the main outcome of this section is summarized as follows:

Theorem 7.9 (Theorem 3.2 re-stated).

Let \mathcal{H} be a 2-rigid, strongly 2-rectangular, and 2\langle\mathcal{H}\rangle_{2} has Mal’tsev polymorphism. And let 2\mathcal{R}\in\langle\mathcal{H}\rangle_{2} be an nn-ary relation. Then #2𝖢𝖲𝖯()\#_{2}\mathsf{CSP}(\mathcal{H}) can be solved in time O(n5)O(n^{5}).

7.2.1 Auxiliary relations

We define the following relation as a tool in out proofs. For 2\mathcal{R}\in\langle\mathcal{H}\rangle_{2}, let 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}} be defined as follows:

𝖯𝖠𝖱(𝐱,y)=(𝐱,y)(2z(𝐱,z))\mathsf{PAR}_{\mathcal{R}}(\mathbf{x},y)=\mathcal{R}(\mathbf{x},y)\wedge(\exists^{\equiv 2}z\;\;\mathcal{R}(\mathbf{x},z)) (3)

Note that the relation 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}} is 2-mpp-definable in \mathcal{H}. Thus, 𝖯𝖠𝖱2\mathsf{PAR}_{\mathcal{R}}\in\langle\mathcal{H}\rangle_{2}, and it is rectangular. Also, note that the second part of the conjunct expresses the fact that the number of extensions of 𝐱\mathbf{x} should be odd. Hence, (𝐱,y)𝖯𝖠𝖱(\mathbf{x},y)\in\mathsf{PAR}_{\mathcal{R}} if and only if (𝐱,y)(\mathbf{x},y)\in\mathcal{R} and 𝐱\mathbf{x} has an odd number of extensions, i.e., #𝖾𝗑𝗍(𝐱)1(mod2)\mathsf{\#ext}_{\mathcal{R}}(\mathbf{x})\equiv 1\pmod{2}.

Lemma 7.10.

Let 2\mathcal{R}\in\langle\mathcal{H}\rangle_{2}. Then |||𝖯𝖠𝖱|(mod2)|\mathcal{R}|\equiv|\mathsf{PAR}_{\mathcal{R}}|\pmod{2}.

Proof.

We start by defining the indicator function as follows:

𝗌𝗀𝗇(𝐱)={1𝐱,0𝐱.\mathsf{sgn}(\mathbf{x}\in\mathcal{R})=\left\{\begin{array}[]{ll}1&\mathbf{x}\in\mathcal{R},\\ 0&\mathbf{x}\not\in\mathcal{R}.\end{array}\right.

Now, we start by calculating the size of \mathcal{R} as it is shown below. Recall that 𝗉𝗋[n1]2\mathsf{pr}^{2}_{[n-1]}\mathcal{R} denotes the relation defined by 2v(𝐱,y)\exists^{\equiv 2}v\mathcal{R}(\mathbf{x},y).

||\displaystyle|\mathcal{R}| =𝐱Hn𝗌𝗀𝗇(𝐱)\displaystyle=\sum_{\mathbf{x}\in H^{n}}\mathsf{sgn}(\mathbf{x}\in\mathcal{R})
=𝐲Hn1zH𝗌𝗀𝗇((𝐲,z))\displaystyle=\sum_{\mathbf{y}\in H^{n-1}}\sum_{z\in H}\mathsf{sgn}((\mathbf{y},z)\in\mathcal{R})
=𝐲Hn1#𝖾𝗑𝗍(𝐲)\displaystyle=\sum_{\mathbf{y}\in H^{n-1}}\mathsf{\#ext}_{\mathcal{R}}(\mathbf{y})
=𝐲Hn1𝐲𝗉𝗋[n1]2#𝖾𝗑𝗍(𝐲)+𝐲Hn1𝐲𝗉𝗋[n1]2#𝖾𝗑𝗍(𝐲)\displaystyle=\sum_{\begin{subarray}{c}\mathbf{y}\in H^{n-1}\\ \mathbf{y}\in\mathsf{pr}^{2}_{[n-1]}\mathcal{R}\end{subarray}}\mathsf{\#ext}_{\mathcal{R}}(\mathbf{y})+\sum_{\begin{subarray}{c}\mathbf{y}\in H^{n-1}\\ \mathbf{y}\not\in\mathsf{pr}^{2}_{[n-1]}\mathcal{R}\end{subarray}}\mathsf{\#ext}_{\mathcal{R}}(\mathbf{y})
𝐲Hn1𝐲𝗉𝗋[n1]2#𝖾𝗑𝗍(𝐲)(mod2)\displaystyle\equiv\bigoplus_{\begin{subarray}{c}\mathbf{y}\in H^{n-1}\\ \mathbf{y}\in\mathsf{pr}^{2}_{[n-1]}\mathcal{R}\end{subarray}}\mathsf{\#ext}_{\mathcal{R}}(\mathbf{y})\pmod{2}
|𝖯𝖠𝖱|(mod2)\displaystyle\equiv|\mathsf{PAR}_{\mathcal{R}}|\pmod{2}

The first and second equalities are trivial by the definition of the function 𝗌𝗀𝗇\mathsf{sgn}. The third equality holds because for a 𝐲Hn1\mathbf{y}\in H^{n-1}

#𝖾𝗑𝗍(𝐲)=zH𝗌𝗀𝗇((𝐲,z)).\mathsf{\#ext}_{\mathcal{R}}(\mathbf{y})=\sum_{z\in H}\mathsf{sgn}((\mathbf{y},z)\in\mathcal{R}).

This equation indicates that the number of extensions of 𝐲Hn1\mathbf{y}\in H^{n-1} to a tuple from the nn-ary relation \mathcal{R} is determined by appending each possible zHz\in H to 𝐲\mathbf{y} and verifying whether (𝐲,z)(\mathbf{y},z) belongs to \mathcal{R}. The forth equality is true, because we can split all 𝐲𝗉𝗋[n1]\mathbf{y}\in\mathsf{pr}_{[n-1]}\mathcal{R} 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 𝐲𝗉𝗋[n1]\mathbf{y}\in\mathsf{pr}_{[n-1]}\mathcal{R} and 𝐲𝗉𝗋[n1]2\mathbf{y}\not\in\mathsf{pr}^{2}_{[n-1]}\mathcal{R}, then, #𝖾𝗑𝗍(𝐲)0mod2\mathsf{\#ext}_{\mathcal{R}}(\mathbf{y})\equiv 0\mod 2. Finally, the last equivalence is valid, because (𝐱,y)𝖯𝖠𝖱(\mathbf{x},y)\in\mathsf{PAR}_{\mathcal{R}} if and only if #𝖾𝗑𝗍(𝐱)#𝖾𝗑𝗍𝖯𝖠𝖱(𝐱)1(mod2)\mathsf{\#ext}_{\mathcal{R}}(\mathbf{x})\equiv\mathsf{\#ext}_{\mathsf{PAR}_{\mathcal{R}}}(\mathbf{x})\equiv 1\pmod{2}. ∎

Now, we can give another equivalent definition of ~\widetilde{\mathcal{R}}, different from the on in the beginning Section 7, that is easier to work with. We define the relation ~Hn1\widetilde{\mathcal{R}}\subseteq H^{n-1} as follows:

~(𝐱)=2y𝖯𝖠𝖱(𝐱,y)\widetilde{\mathcal{R}}(\mathbf{x})=\exists^{\equiv 2}y\;\;\mathsf{PAR}_{\mathcal{R}}(\mathbf{x},y) (4)

Note that the relation ~\widetilde{\mathcal{R}} is 2-mpp-definable in \mathcal{H}. Thus, ~2\widetilde{\mathcal{R}}\in\langle\mathcal{H}\rangle_{2}, and it is rectangular. Also, by the definition of 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}, 𝐱~\mathbf{x}\in\widetilde{\mathcal{R}} if and only if 𝐱\mathbf{x} has odd number of extensions into \mathcal{R}. Therefore, the following lemma is straightforward.

Lemma 7.11.

Let 𝒬(𝐱)=y𝖯𝖠𝖱(𝐱,y)\mathcal{Q}(\mathbf{x})=\exists y\;\;\mathsf{PAR}_{\mathcal{R}}(\mathbf{x},y). Then, 𝒬=~\mathcal{Q}=\widetilde{\mathcal{R}}.

Proof.

We have that 𝐱𝗉𝗋[n1]𝖯𝖠𝖱\mathbf{x}\in\mathsf{pr}_{[n-1]}\mathsf{PAR}_{\mathcal{R}} if and only if there exists yHy\in H such that (𝐱,y)𝖯𝖠𝖱(\mathbf{x},y)\in\mathsf{PAR}_{\mathcal{R}}. Furthermore, by the definition of 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}, it means 𝐱\mathbf{x} has an odd number of extensions to a tuple from 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}, which is equivalent to having an odd number of extensions to a tuple from \mathcal{R}. In other words, 𝐱\mathbf{x} belongs to 𝗉𝗋[n1]2\mathsf{pr}^{2}_{[n-1]}\mathcal{R}. The result follows. ∎

Lemma 7.12.

Let 2\mathcal{R}\in\langle\mathcal{H}\rangle_{2}. Then |~||𝖯𝖠𝖱|(mod2)|\widetilde{\mathcal{R}}|\equiv|\mathsf{PAR}_{\mathcal{R}}|\pmod{2}.

Proof.

We start by calculating the cardinality of ~\widetilde{\mathcal{R}} as it is shown below:

|~|\displaystyle|\widetilde{\mathcal{R}}| =𝐱Hn1𝗌𝗀𝗇(𝐱~)\displaystyle=\sum_{\mathbf{x}\in H^{n-1}}\mathsf{sgn}(\mathbf{x}\in\widetilde{\mathcal{R}})
=𝐱Hn1yH𝗌𝗀𝗇((𝐱,y))\displaystyle=\sum_{\begin{subarray}{c}\mathbf{x}\in H^{n-1}\\ y\in H\end{subarray}}\mathsf{sgn}((\mathbf{x},y)\in\mathcal{R})
𝐱Hn1yH𝗌𝗀𝗇((𝐱,y))(mod2)\displaystyle\equiv\bigoplus_{\mathbf{x}\in H^{n-1}}\bigoplus_{y\in H}\mathsf{sgn}((\mathbf{x},y)\in\mathcal{R})\pmod{2}
𝐱Hn1yH𝗌𝗀𝗇((𝐱,y)𝖯𝖠𝖱)(mod2)\displaystyle\equiv\bigoplus_{\mathbf{x}\in H^{n-1}}\bigoplus_{y\in H}\mathsf{sgn}((\mathbf{x},y)\in\mathsf{PAR}_{\mathcal{R}})\pmod{2}
|𝖯𝖠𝖱|(mod2)\displaystyle\equiv|\mathsf{PAR}_{\mathcal{R}}|\pmod{2}

The first equality is straightforward. The second equality is true as it follows directly from the definition of the relation ~\widetilde{\mathcal{R}}: 𝐱\mathbf{x}\in\mathcal{R} if and only if 𝐱\mathbf{x} has odd number of extensions, if and only if there exists y𝗉𝗋n2y\in\mathsf{pr}^{2}_{n}\mathcal{R} such that (𝐱,y)(\mathbf{x},y)\in\mathcal{R}. The first congruence holds because y𝗉𝗋n2y\in\mathsf{pr}^{2}_{n}\mathcal{R} if and only if yH𝗌𝗀𝗇((𝐱,y))1(mod2)\bigoplus_{y\in H}\mathsf{sgn}((\mathbf{x},y)\in\mathcal{R})\equiv 1\pmod{2}. The second congruence is valid because 𝐱\mathbf{x} has odd number of extensions, hence (𝐱,y)(\mathbf{x},y) should belong to 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}. ∎

Proof of Theorem 7.8.

Our goal is to reduce the arity of \mathcal{R} from nn to 11 step by step while keeping the parity of |||\mathcal{R}| unchanged. To achieve this, we define (n)=\mathcal{R}^{(n)}=\mathcal{R} and (k1)=~(k)\mathcal{R}^{(k-1)}=\widetilde{\mathcal{R}}^{(k)} for 1kn1\leq k\leq n. By applying Lemma 7.10 and Lemma 7.12 to (k)\mathcal{R}^{(k)}, we can compute the witness function of (k1)\mathcal{R}^{(k-1)} denoted by ω(k1)\omega^{(k-1)} for nk1n\geq k\geq 1. We get the following congruences:

|||(n)||(n1)||(1)|(mod2),|\mathcal{R}|\equiv|\mathcal{R}^{(n)}|\equiv|\mathcal{R}^{(n-1)}|\equiv...\equiv|\mathcal{R}^{(1)}|\pmod{2},

We can compute the cardinality of (1)H\mathcal{R}^{(1)}\subseteq H since we have its witness function ω(1)\omega^{(1)} by Theorem 7.15. We simply check if ω(1)(1,a)\omega^{(1)}(1,a)\neq\bot for each aHa\in H. Note that this process, just take O(n)O(n) times, not considering the complexity of calculating witness function.

Algorithm 1 𝖢𝖺𝗅𝖼𝗎𝗅𝖺𝗍𝖾𝖲𝗂𝗓𝖾\mathsf{CalculateSize}(ω,,n\omega,\mathcal{E},n)
1:if n=1n=1 then
2:     \ell\leftarrow Count how many aHa\in H, ω(1,a)\omega(1,a)\neq\bot
3:     Return (mod2)\ell\pmod{2}
4:end if
5:if for all t[|n|]t\in[|\mathcal{E}_{n}|], |n,t|0(mod2)|\mathcal{E}_{n,t}|\equiv 0\pmod{2} then
6:     Return 0
7:end if
8:ω~,~𝖥𝗂𝗇𝖽𝖶𝗂𝗍𝗇𝖾𝗌𝗌𝖥𝗎𝗇𝖼𝗍𝗂𝗈𝗇(ω,)\widetilde{\omega},\widetilde{\mathcal{E}}\leftarrow\mathsf{FindWitnessFunction}(\omega,\mathcal{E})
9:Return 𝖢𝖺𝗅𝖼𝗎𝗅𝖺𝗍𝖾𝖲𝗂𝗓𝖾\mathsf{CalculateSize}(ω~,~,n1\widetilde{\omega},\widetilde{\mathcal{E}},n-1)

7.2.2 Calculating witness function for ~\widetilde{\mathcal{R}}

In this subsection, we show how to calculate a frame, the frame classes, and a witness function for ~\widetilde{\mathcal{R}}, which we denote as F~\widetilde{F}, ~\widetilde{\mathcal{E}}, and ω~\widetilde{\omega}, respectively. Since 𝖯𝖠𝖱2\mathsf{PAR}_{\mathcal{R}}\in\langle\mathcal{H}\rangle_{2} is rectangular, we can consider its frame and witness function, denoted as \mathcal{E}^{\prime} and ω\omega^{\prime}. Suppose we have already calculated the frame and witness function for 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}. By applying Lemma 7.11 and Proposition 7.7, we can obtain a witness function and frame for ~\widetilde{\mathcal{R}} in O(n)O(n) time.

To calculate a witness function for 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}, we will use several auxiliary lemmas. Once we have a witness function for 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}, we can proceed with calculating a witness function for ~\widetilde{\mathcal{R}}.

Lemma 7.13.

Let (𝐱,y)(\mathbf{x},y)\in\mathcal{R} where 𝐱Hn1\mathbf{x}\in H^{n-1} and yHy\in H. If there exists s[|n,s|]s\in[|\mathcal{E}_{n,s}|] such that |n,s|1(mod2)|\mathcal{E}_{n,s}|\equiv 1\pmod{2} and yn,sy\in\mathcal{E}_{n,s}, then (𝐱,y)𝖯𝖠𝖱(\mathbf{x},y)\in\mathsf{PAR}_{\mathcal{R}}.

Proof.

We need to calculate the number of extensions of 𝐱\mathbf{x}.

#𝖾𝗑𝗍(𝐱)\displaystyle\mathsf{\#ext}_{\mathcal{R}}(\mathbf{x}) =zH𝗌𝗀𝗇((𝐱,z))\displaystyle=\sum_{z\in H}\mathsf{sgn}((\mathbf{x},z)\in\mathcal{R})
=z𝗉𝗋n𝗌𝗀𝗇((𝐱,z))\displaystyle=\sum_{z\in\mathsf{pr}_{n}\mathcal{R}}\mathsf{sgn}((\mathbf{x},z)\in\mathcal{R})
=i[|n|]zn,i𝗌𝗀𝗇((𝐱,z))\displaystyle=\sum_{i\in[|\mathcal{E}_{n}|]}\sum_{z\in\mathcal{E}_{n,i}}\mathsf{sgn}((\mathbf{x},z)\in\mathcal{R})
=zn,s𝗌𝗀𝗇((𝐱,z))\displaystyle=\sum_{z\in\mathcal{E}_{n,s}}\mathsf{sgn}((\mathbf{x},z)\in\mathcal{R})
|n,s|1(mod2).\displaystyle\equiv|\mathcal{E}_{n,s}|\equiv 1\pmod{2}.

The first and second equalities are straightforward, as they follow directly from the definition of the function 𝗌𝗀𝗇\mathsf{sgn}. The third equality holds because we can partition the set 𝗉𝗋n\mathsf{pr}_{n}\mathcal{R} into equivalence classes given by the frame FF. The fourth equality is valid because the relation \mathcal{R} is rectangular, and so 𝐱\mathbf{x} can be extended to only one class n,s\mathcal{E}_{n,s}. Since there exists s[|n|]s\in[|\mathcal{E}_{n}|] such that yn,sy\in\mathcal{E}_{n,s}, the number of extensions of 𝐱\mathbf{x} should be the cardinality of n,s\mathcal{E}_{n,s}. As |n,s|1|\mathcal{E}_{n,s}|\equiv 1, the number of extensions of 𝐱\mathbf{x} is 11 modulo 22. Therefore, (𝐱,y)𝖯𝖠𝖱(\mathbf{x},y)\in\mathsf{PAR}_{\mathcal{R}}. ∎

Lemma 7.14.

Let a,bHa,b\in H, k[n]k\in[n], and 𝐱Hn\mathbf{x}\in H^{n} be such that 𝐱𝖯𝖠𝖱\mathbf{x}\in\mathsf{PAR}_{\mathcal{R}} and 𝗉𝗋k𝐱=a\mathsf{pr}_{k}\mathbf{x}=a. We can check in O(n3)O(n^{3}) if akba\sim^{\prime}_{k}b, where k\sim^{\prime}_{k} is the frame equivalence of 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}.

Proof.

As 𝖯𝖠𝖱2\mathsf{PAR}_{\mathcal{R}}\in\langle\mathcal{H}\rangle_{2}, we know that 𝗉𝗋[k]𝖯𝖠𝖱\mathsf{pr}_{[k]}\mathsf{PAR}_{\mathcal{R}} is rectangular. Therefore, if (𝗉𝗋[k1]𝐱,a)𝗉𝗋[k]𝖯𝖠𝖱(\mathsf{pr}_{[k-1]}\mathbf{x},a)\in\mathsf{pr}_{[k]}\mathsf{PAR}_{\mathcal{R}} and akba\sim^{\prime}_{k}b, then (𝗉𝗋[k1]𝐱,b)𝗉𝗋[k]𝖯𝖠𝖱(\mathsf{pr}_{[k-1]}\mathbf{x},b)\in\mathsf{pr}_{[k]}\mathsf{PAR}_{\mathcal{R}}. This implies the existence of an extension (𝐲,c)Hnk(\mathbf{y},c)\in H^{n-k} such that (𝗉𝗋[k1]𝐱,a,𝐲,c)𝖯𝖠𝖱(\mathsf{pr}_{[k-1]}\mathbf{x},a,\mathbf{y},c)\in\mathsf{PAR}_{\mathcal{R}}. According to Lemma 7.13, we can check if (𝗉𝗋[k1]𝐱,a,𝐲,c)𝖯𝖠𝖱(\mathsf{pr}_{[k-1]}\mathbf{x},a,\mathbf{y},c)\in\mathsf{PAR}_{\mathcal{R}} by verifying if cc belongs to an n\mathcal{E}_{n} class of \mathcal{R} with odd cardinality.

We begin by defining the relation 𝒮(x1,,xn)\mathcal{S}(x_{1},...,x_{n}) as follows:

𝒮(x1,,xn)=(x1,,xn)(i[k1]xsCdi)(xkCb)\mathcal{S}(x_{1},...,x_{n})=\mathcal{R}(x_{1},...,x_{n})\wedge(\bigwedge_{i\in[k-1]}x_{s}\in C_{d_{i}})\wedge(x_{k}\in C_{b})

Essentially, 𝒮\mathcal{S} is the same as \mathcal{R} with its first k1k-1 coordinates fixed to the corresponding coordinates of 𝐱\mathbf{x}, and the kkth coordinate fixed to bb. We can compute the witness function and frame classes of 𝒮\mathcal{S} using Proposition 7.5, with a time complexity of O(n3)O(n^{3}). We denote the resulting frame classes as ′′\mathcal{E}^{\prime\prime}. Next, we check if there exists t[|n′′|]t\in[|\mathcal{E}^{\prime\prime}_{n}|] such that |n,t′′|1(mod2)|\mathcal{E}^{\prime\prime}_{n,t}|\equiv 1\pmod{2}. If such a tt exists, then by Lemma 7.6 and Lemma 7.13, we can conclude that akba\sim^{\prime}_{k}b.

Note that this process requires only O(n3)O(n^{3}) time to compute the witness function for 𝒮\mathcal{S}, and then O(1)O(1) time to detect whether there exists such a tt. Therefore, the overall time complexity of the algorithm is O(n3)O(n^{3}).

Algorithm 2 𝖢𝗁𝖾𝖼𝗄𝖤𝗉𝗌𝗂𝗅𝗈𝗇𝖢𝗅𝖺𝗌𝗌\mathsf{CheckEpsilonClass}(𝐱Hn,a,bH,k[n]\mathbf{x}\in H^{n},a,b\in H,k\in[n])
1:Construct 𝒮\mathcal{S} as 𝒮(x1,,xn)=(x1,,xn)(i[k1]xsCdi)(xkCb)\mathcal{S}(x_{1},...,x_{n})=\mathcal{R}(x_{1},...,x_{n})\wedge(\bigwedge_{i\in[k-1]}x_{s}\in C_{d_{i}})\wedge(x_{k}\in C_{b})
2:Calculate ′′\mathcal{E}^{\prime\prime} classes of 𝒮\mathcal{S} with its witness function ω′′\omega^{\prime\prime}
3:if there exists t[|n′′|]t\in[|\mathcal{E}^{\prime\prime}_{n}|] such that |n,t′′|1(mod2)|\mathcal{E}^{\prime\prime}_{n,t}|\equiv 1\pmod{2} then
4:     set ω(k,b)=ω′′(n,c)\omega^{\prime}(k,b)=\omega^{\prime\prime}(n,c), for cn,t′′c\in\mathcal{E}^{\prime\prime}_{n,t}
5:     Return ω(k,b)\omega^{\prime}(k,b)
6:else
7:     Return \bot
8:end if

Note that if the algorithm 𝖢𝗁𝖾𝖼𝗄𝖤𝗉𝗌𝗂𝗅𝗈𝗇𝖢𝗅𝖺𝗌𝗌\mathsf{CheckEpsilonClass} returns 𝐲Hn\mathbf{y}\in H^{n} for the input 𝐱H\mathbf{x}\in H and a,bHa,b\in H, then it follows that 𝗉𝗋k𝐲=b\mathsf{pr}_{k}\mathbf{y}=b and 𝗉𝗋[k1]𝐱=𝗉𝗋[k1]𝐲\mathsf{pr}_{[k-1]}\mathbf{x}=\mathsf{pr}_{[k-1]}\mathbf{y}. This is because, in line (4) of the algorithm, ω(k,b)\omega^{\prime}(k,b) is set to be ω′′(n,c)\omega^{\prime\prime}(n,c) and we know that 𝗉𝗋kω′′(n,c)=b\mathsf{pr}_{k}\omega^{\prime\prime}(n,c)=b and 𝗉𝗋[k1]ω′′(n,c)=𝗉𝗋[k1]𝐱\mathsf{pr}_{[k-1]}\omega^{\prime\prime}(n,c)=\mathsf{pr}_{[k-1]}\mathbf{x}, as per the definition of 𝒮\mathcal{S}. ∎

Theorem 7.15.

ω~(k,a)\widetilde{\omega}(k,a) can be computed in time O(n4)O(n^{4}).

Proof.

At the first step, we calculate the witness function ω\omega^{\prime} and frame FF^{\prime} for 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}. Using Proposition 7.7 and Lemma 7.11, we can then compute the witness function and frame for ~\widetilde{\mathcal{R}}.

In order to compute ω\omega^{\prime}, we first need to compute ω(n,a)\omega^{\prime}(n,a) for all aHa\in H. This step is relatively simple. Since a𝗉𝗋n𝖯𝖠𝖱a\in\mathsf{pr}_{n}\mathsf{PAR}_{\mathcal{R}} if and only if there exists 𝐱Hn1\mathbf{x}\in H^{n-1} such that (𝐱,a)𝖯𝖠𝖱(\mathbf{x},a)\in\mathsf{PAR}_{\mathcal{R}}, we can check whether #𝖾𝗑𝗍(𝐱)1(mod2)\mathsf{\#ext}_{\mathcal{R}}(\mathbf{x})\equiv 1\pmod{2}. By Lemma 7.13, a𝗉𝗋n𝖯𝖠𝖱a\in\mathsf{pr}_{n}\mathsf{PAR}_{\mathcal{R}} if and only if an,sa\in\mathcal{E}_{n,s} where s[|n|]s\in[|\mathcal{E}_{n}|] and |[n,s]|1(mod2)|[\mathcal{E}_{n,s}]|\equiv 1\pmod{2}. Clearly, if anba\sim_{n}b, then anba\sim^{\prime}_{n}b. Therefore, we can set ω(n,a)=ω(n,a)\omega^{\prime}(n,a)=\omega(n,a) if |n,s|1(mod2)|\mathcal{E}_{n,s}|\equiv 1\pmod{2}, and ω(n,a)=\omega^{\prime}(n,a)=\bot if |n,s|0(mod2)|\mathcal{E}_{n,s}|\equiv 0\pmod{2}. Note that this step only takes O(1)O(1) time, since ω\omega is already given to us.

Let k[n1]k\in[n-1]. According to Proposition 7.4, we can compute ωka\omega^{k\leftarrow a} and ka\mathcal{E}^{k\leftarrow a} in O(n2)O(n^{2}) time. Next, we examine n,ika\mathcal{E}^{k\leftarrow a}_{n,i} for i[|nka|]i\in[|\mathcal{E}^{k\leftarrow a}_{n}|]. We check whether there exists an s[|nka|]s\in[|\mathcal{E}^{k\leftarrow a}_{n}|] such that |n,ska|1mod2|\mathcal{E}^{k\leftarrow a}_{n,s}|\equiv 1\mod 2. If we find such an ss, we select bn,skab\in\mathcal{E}^{k\leftarrow a}_{n,s} and set ω(k,a)=ωka(n,b)\omega^{\prime}(k,a)=\omega^{k\leftarrow a}(n,b). Otherwise, we assign ω(k,a)=\omega^{\prime}(k,a)=\bot. Note that searching for ss only requires O(1)O(1) time since we only need to look up |nka||\mathcal{E}^{k\leftarrow a}_{n}|, which is less than |H||H|.

Since ω(k,a)=ωka(n,b)\omega^{\prime}(k,a)=\omega^{k\leftarrow a}(n,b), it follows that 𝗉𝗋kω(k,a)=𝗉𝗋kωka(n,b)=a\mathsf{pr}_{k}\omega^{\prime}(k,a)=\mathsf{pr}_{k}\omega^{k\leftarrow a}(n,b)=a. Also, because of the way we construct ω(k,a)\omega^{\prime}(k,a) and Lemma 7.13, we have that ω(k,a)𝖯𝖠𝖱\omega^{\prime}(k,a)\in\mathsf{PAR}_{\mathcal{R}}.

Next, we use Algorithm 𝖢𝗁𝖾𝖼𝗄𝖤𝗉𝗌𝗂𝗅𝗈𝗇𝖢𝗅𝖺𝗌𝗌(ω(k,a),a,b)\mathsf{CheckEpsilonClass}(\omega^{\prime}(k,a),a,b) for all bHb\in H to derive the equivalence relation k\sim^{\prime}_{k} defined by 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}} for the kkth coordinate. If the algorithm returns 𝐲\mathbf{y}, it means that akba\sim^{\prime}_{k}b and they are in the same class. Therefore, we set ω(k,b)=𝐲\omega^{\prime}(k,b)=\mathbf{y}. Otherwise, a≁kba\not\sim^{\prime}_{k}b. We repeat this process for each aHa\in H whose witness function has not yet been associated with anything, and at the end, we will have the witness function for 𝖯𝖠𝖱\mathsf{PAR}_{\mathcal{R}}. By Proposition 7.7, we will have the witness function for ~\widetilde{\mathcal{R}}.

Algorithm 3 𝖥𝗂𝗇𝖽𝖶𝗂𝗍𝗇𝖾𝗌𝗌𝖥𝗎𝗇𝖼𝗍𝗂𝗈𝗇(ω,)\mathsf{FindWitnessFunction}(\omega,\mathcal{E})
1:Compute ω\omega and \mathcal{E} for \mathcal{R}.
2:for each aHa\in H do
3:     Find sns\in\mathcal{E}_{n} such that an,sa\in\mathcal{E}_{n,s}
4:     if  |n,s|1(mod2)|\mathcal{E}_{n,s}|\equiv 1\pmod{2} then
5:         ω(n,a)ω(n,a)\omega^{\prime}(n,a)\leftarrow\omega(n,a)
6:     else
7:         Set ω(n,a)\omega^{\prime}(n,a)\leftarrow\bot
8:     end if
9:end for
10:for each k[n1]k\in[n-1] do
11:     Set DHD\leftarrow H
12:     while DD\not=\emptyset do
13:         for each aDa\in D do
14:              Calculate ωka\omega^{k\leftarrow a} and ka\mathcal{E}^{k\leftarrow a}
15:              if  there exists s[|nka|]s\in[|\mathcal{E}^{k\leftarrow a}_{n}|] such that |n,ska|1(mod2)|\mathcal{E}^{k\leftarrow a}_{n,s}|\equiv 1\pmod{2} then
16:                  Pick bn,skab\in\mathcal{E}^{k\leftarrow a}_{n,s}
17:                  Set ω(k,a)ω(n,b)\omega^{\prime}(k,a)\leftarrow\omega(n,b)
18:                  for each cD{a}c\in D\setminus\{a\} do
19:                       Set 𝐲𝖢𝗁𝖾𝖼𝗄𝖤𝗉𝗌𝗂𝗅𝗈𝗇𝖢𝗅𝖺𝗌𝗌(ω(k,a),a,c,k)\mathbf{y}\leftarrow\mathsf{CheckEpsilonClass}(\omega^{\prime}(k,a),a,c,k)
20:                       if  𝐲\mathbf{y}\not=\bot then
21:                           Set ω(k,b)𝐲\omega^{\prime}(k,b)\leftarrow\mathbf{y}
22:                           Set DD{c}D\leftarrow D\setminus\{c\}
23:                       end if
24:                  end for
25:              else
26:                  Set ω(k,a)\omega^{\prime}(k,a)\leftarrow\bot
27:              end if
28:         end for
29:     end while
30:end for
31:Calculate ω~\widetilde{\omega} and ~\widetilde{\mathcal{E}} based on ω\omega^{\prime} and \mathcal{E}^{\prime} by projection \triangleright Proposition 7.7
32:Return ω~\widetilde{\omega} and ~\widetilde{\mathcal{E}}

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 \mathcal{H} if \mathcal{H} is 2-rigid.

8 Hardness and Automorphisms

An important ingredient of the complexity classification of #pCSP\#_{p}CSP 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 G=(V,E)G=(V,E) be a graph. The graph GG is said to be {\mathfrak{R}}-thin if it does not have twin vertices, that is, vertices with equal neighbourhoods. The graph GG is prime if for any representation G=G1×G2G=G_{1}\times G_{2} one of G1,G2G_{1},G_{2} is a 1-element graph. A representation G=G1××GrG=G_{1}\times\dots\times G_{r} is said to be prime factorization of of GG if all the GiG_{i}’s are prime.

Theorem 8.1 ([29], [12]).

Let G=G1××GrG=G_{1}\times\dots\times G_{r} be a prime factorization of a connected {\mathfrak{R}}-thin non-bipartite graph 𝖦\mathsf{G}, where for vV(G)v\in V(G), we have v=(v1,,vr)v=(v_{1},\dots,v_{r}). Then for any automorphism ψ\psi of 𝖦\mathsf{G}^{\ell}, there is a permutation π\pi of []×[r][\ell]\times[r] such that ψ\psi can be split into rr\ell automorphisms:

ψ([v1],,[v])=((ψ1,1([vπ(1,1)])ψ1,r([vπ(1,r)])),,(ψ,1([vπ(,1)])ψ,r([vπ(,r)]))),\displaystyle\psi([v_{1}],\dots,[v_{\ell}])=\left(\begin{pmatrix}{\psi_{1,1}([v_{\pi(1,1)}])}\\ \vdots\\ {\psi_{1,r}([v_{\pi(1,r)}])}\end{pmatrix},...,\begin{pmatrix}{\psi_{\ell,1}([v_{\pi(\ell,1)}])}\\ \vdots\\ {\psi_{\ell,r}([v_{\pi(\ell,r)}])}\end{pmatrix}\right),

for (i,j)=π(i,j)(i^{\prime},j^{\prime})=\pi(i,j), ψi,j\psi_{i,j} is an isomorphism from the ii^{\prime}th copy of GjG_{j^{\prime}} to the iith copy of GjG_{j}.

As the following example shows, an analogous result is not true for relational structures.

Example 8.2.

Let =(V,E)\mathcal{H}=(V,E) be a directed graph where V={a,b,,c,d}V=\{a,b,,c,d\} with directed edges noted as pairs E={(b,a),(b,c),(c,d)}E=\{(b,a),(b,c),(c,d)\}. If we study the \mathcal{H} as a relational structure, then it is 2-rigid. However, the automorphism group of 2\mathcal{H}^{2} has a complicated structure. As it can been seen in the Figure 3, 2\mathcal{H}^{2} has the following automorphism: π(a,d)=(c,d),π(c,d)=(a,d)\pi(a,d)=(c,d),\pi(c,d)=(a,d), and π(x,y)=(x,y)\pi(x,y)=(x,y) otherwise. This automorphism cannot be represented given in Theorem 8.1.

Refer to caption
Figure 3: The structure of \mathcal{H} and 2\mathcal{H}^{2}

8.2 Rectangularity obstruction

One of the implication of Theorem 8.1 is that some subsets from G1××GrG_{1}\times\dots\times G_{r} survive pp-reductions by automorphism of order pp. We explore what the existence of such sets entails.

Let \mathcal{H} be a (multi-sorted) relational structure with base set HH, n1n\geq 1, and Hn\mathcal{R}\subseteq H^{n}. A subset SS\subseteq\mathcal{R} is called protected in \mathcal{R} if, after applying a pp-reduction to \mathcal{R} under a sequence of pp-automorphisms from 𝖠𝗎𝗍()\mathsf{Aut}(\mathcal{R}), the subset S~\widetilde{S} remains non-empty. Formally, SS is protected if for any sequence of automorphisms π1,π2,,πk𝖠𝗎𝗍()\pi_{1},\pi_{2},\ldots,\pi_{k}\in\mathsf{Aut}(\mathcal{R}), the image of SS under the pp-reduction remains non-empty:

S𝖥𝗂𝗑(π1π2πk).S\cap\mathsf{Fix}(\pi_{1}\circ\pi_{2}\circ\cdots\circ\pi_{k})\neq\emptyset.

A rectangularity obstruction in a relational structure \mathcal{H} is a violation of the rectangularity or pp-rectangularity property. Let Hn\mathcal{R}\subseteq H^{n} be an nn-ary relation that is either pp-definable or pp-mpp-definable in \mathcal{H}. For some k[n]k\in[n], let 𝐚,𝐛𝗉𝗋[k]\mathbf{a},\mathbf{b}\in\mathsf{pr}_{[k]}\mathcal{R} and 𝐜,𝐝𝗉𝗋[n][k]\mathbf{c},\mathbf{d}\in\mathsf{pr}_{[n]-[k]}\mathcal{R}. The relation \mathcal{R} together with the triple (𝐚,𝐜),(𝐚,𝐝),(𝐛,𝐜)(\mathbf{a},\mathbf{c}),(\mathbf{a},\mathbf{d}),(\mathbf{b},\mathbf{c}) is a rectangularity obstruction if (𝐚,𝐜),(𝐚,𝐝),(𝐛,𝐜)(\mathbf{a},\mathbf{c}),(\mathbf{a},\mathbf{d}),(\mathbf{b},\mathbf{c})\in\mathcal{R} and (𝐛,𝐜)(\mathbf{b},\mathbf{c})\not\in\mathcal{R}. A generalized rectangularity obstruction are the relation \mathcal{R} sets A1,1,A1,2𝗉𝗋[k]A_{1,1},A_{1,2}\subseteq\mathsf{pr}_{[k]}\mathcal{R}, A2,1,A2,2𝗉𝗋[n][k]A_{2,1},A_{2,2}\subseteq\mathsf{pr}_{[n]-[k]}\mathcal{R} such that A1,1A1,2=A_{1,1}\cap A_{1,2}=\emptyset, A2,1A2,2=A_{2,1}\cap A_{2,2}=\emptyset, and any 𝐚A1,1,𝐛A1,2,𝐜A2,1,𝐝A2,2\mathbf{a}\in A_{1,1},\mathbf{b}\in A_{1,2},\mathbf{c}\in A_{2,1},\mathbf{d}\in A_{2,2} form a rectangularity obstruction. A rectangularity obstruction is protected if each of the sets {(𝐚,𝐜)},{(𝐚,𝐝)},{(𝐛,𝐜)}\{(\mathbf{a},\mathbf{c})\},\{(\mathbf{a},\mathbf{d})\},\{(\mathbf{b},\mathbf{c})\} is protected in \mathcal{R}. A generalized rectangularity obstruction A1,1,A1,2𝗉𝗋[k]A_{1,1},A_{1,2}\subseteq\mathsf{pr}_{[k]}\mathcal{R}, A2,1,A2,2𝗉𝗋[n][k]A_{2,1},A_{2,2}\subseteq\mathsf{pr}_{[n]-[k]}\mathcal{R} is protected if each of the sets (A1,1×A2,1),(A1,1×A2,2),(A1,2×A2,1)\mathcal{R}\cap(A_{1,1}\times A_{2,1}),\mathcal{R}\cap(A_{1,1}\times A_{2,2}),\mathcal{R}\cap(A_{1,2}\times A_{2,1}) is protected in \mathcal{R}.

A special case of a generalized rectangularity obstruction is a standard hardness gadget. For a relational structure \mathcal{H}, a standard hardness gadget is a tuple (,A1,1,A1,2,A2,1,A2,2)(\mathcal{R},A_{1,1},A_{1,2},A_{2,1},A_{2,2}) such that

  • Hn\mathcal{R}\subseteq H^{n}, n2n\geq 2, pp-mpp-definable in \mathcal{H}, i.e., p\mathcal{R}\in\langle\mathcal{H}\rangle_{p};

  • for some s[n]s\in[n], 0<s<n0<s<n, A1,1,A1,2𝗉𝗋[s],A2,1,A2,2𝗉𝗋[n][s]A_{1,1},A_{1,2}\subseteq\mathsf{pr}_{[s]}\mathcal{R},A_{2,1},A_{2,2}\subseteq\mathsf{pr}_{[n]-[s]}\mathcal{R} are non-empty;

  • A1,1A1,2=𝗉𝗋[s]A_{1,1}\cup A_{1,2}=\mathsf{pr}_{[s]}\mathcal{R}, and A1,1A1,2=A_{1,1}\cap A_{1,2}=\emptyset;

  • A2,1A2,2=𝗉𝗋[n][s]A_{2,1}\cup A_{2,2}=\mathsf{pr}_{[n]-[s]}\mathcal{R}, and A2,1A2,2=A_{2,1}\cap A_{2,2}=\emptyset;

  • for all 𝐱A1,1\mathbf{x}\in A_{1,1} and 𝐲A2,1\mathbf{y}\in A_{2,1}, (𝐱,𝐲)(\mathbf{x},\mathbf{y})\notin\mathcal{R};

  • for all 𝐱A1,1A1,2\mathbf{x}\in A_{1,1}\cup A_{1,2} and 𝐲A2,2\mathbf{y}\in A_{2,2}, (𝐱,𝐲)(\mathbf{x},\mathbf{y})\in\mathcal{R};

  • for all 𝐱A1,2\mathbf{x}\in A_{1,2} and 𝐲A2,1A2,2\mathbf{y}\in A_{2,1}\cup A_{2,2}, (𝐱,𝐲)(\mathbf{x},\mathbf{y})\in\mathcal{R}.

Thus, a standard hardness gadget is a generalized rectangularity obstruction with the extra condition A1,1A1,2=𝗉𝗋[s]A_{1,1}\cup A_{1,2}=\mathsf{pr}_{[s]}\mathcal{R}, A2,1A2,2=𝗉𝗋[n][s]A_{2,1}\cup A_{2,2}=\mathsf{pr}_{[n]-[s]}\mathcal{R}.

By the definition of a standard hardness gadget, the following lemma is straightforward.

Lemma 8.3.

Let 𝐱1,𝐱2A1,i\mathbf{x}_{1},\mathbf{x}_{2}\in A_{1,i} for i[2]i\in[2]. Then, if there exists 𝐲𝗉𝗋[n][k]\mathbf{y}\in\mathsf{pr}_{[n]-[k]}\mathcal{R} such that (𝐱1,𝐲)(\mathbf{x}_{1},\mathbf{y})\in\mathcal{R}, then (𝐱2,𝐲)(\mathbf{x}_{2},\mathbf{y})\in\mathcal{R}. Also, let 𝐲1,𝐲2A2,i\mathbf{y}_{1},\mathbf{y}_{2}\in A_{2,i} for i[2]i\in[2]. Then, if there exists 𝐱𝗉𝗋[k]\mathbf{x}\in\mathsf{pr}_{[k]}\mathcal{R} such that (𝐱,𝐲1)(\mathbf{x},\mathbf{y}_{1})\in\mathcal{R}, then (𝐱,𝐲2)(\mathbf{x},\mathbf{y}_{2})\in\mathcal{R}.

For a standard hardness gadget we have the following.

Proposition 8.4.

Let \mathcal{H} be a pp-rigid relational structure. If there exists a standard hardness gadget (,A1,1,A1,2,A2,1,A2,2)(\mathcal{R},A_{1,1},A_{1,2},A_{2,1},A_{2,2}) for \mathcal{H}, then #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) is #p\#_{p}-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 𝖪=(LR,E)\mathsf{K}_{\mathcal{R}}=(L\cup R,E) using the hardness gadget (,A1,1,A1,2,A2,1,A2,2)(\mathcal{R},A_{1,1},A_{1,2},A_{2,1},A_{2,2}) as follows:

  • L={u𝐱𝐱𝗉𝗋[s]}L=\{u_{\mathbf{x}}\mid\mathbf{x}\in\mathsf{pr}_{[s]}\mathcal{R}\},

  • R={v𝐲𝐲𝗉𝗋[n][s]}R=\{v_{\mathbf{y}}\mid\mathbf{y}\in\mathsf{pr}_{[n]-[s]}\mathcal{R}\},

  • E={(u𝐱,v𝐲)(𝐱,𝐲)}E=\{(u_{\mathbf{x}},v_{\mathbf{y}})\mid(\mathbf{x},\mathbf{y})\in\mathcal{R}\}.

In order to streamline the notation, we define a mapping 𝔉\mathfrak{F} from 𝗉𝗋[s]𝗉𝗋[n][s]\mathsf{pr}_{[s]}\mathcal{R}\cup\mathsf{pr}_{[n]-[s]}\mathcal{R} to LRL\cup R by 𝔉(𝐱)=a𝐱\mathfrak{F}(\mathbf{x})=a_{\mathbf{x}}. It is straightforward to observe that 𝔉\mathfrak{F} is bijective.

Based on the definition of 𝖪\mathsf{K}_{\mathcal{R}}, we can define the sets Ai,j={a𝐱𝐱Ai,j}A^{\prime}_{i,j}=\{a_{\mathbf{x}}\mid\mathbf{x}\in A_{i,j}\} for i,j[2]i,j\in[2]. Note that, by the definition of a standard hardness gadget, A1,1A1,2=A2,1A2,2=A^{\prime}_{1,1}\cap A^{\prime}_{1,2}=A^{\prime}_{2,1}\cap A^{\prime}_{2,2}=\emptyset.

Before proceeding further, we introduce some notation regarding graphs. Let the neighbor set of a vertex in a graph 𝖦=(V,E)\mathsf{G}=(V,E) be defined as N𝖦(v)={uV(u,v)E}N_{\mathsf{G}}(v)=\{u\in V\mid(u,v)\in E\}. We say that graphs (𝖦,a)(\mathsf{G},a) and (𝖦,b)(\mathsf{G},b) (with a distinguished vertex) are isomorphic if there is an automorphism of 𝖦\mathsf{G} mapping aa to bb. The following lemma is straightforward.

Lemma 8.5.

Let 𝖦=(V,E)\mathsf{G}=(V,E) be a graph and a,bVa,b\in V. The graphs (𝖦,a)(\mathsf{G},a) and (𝖦,b)(\mathsf{G},b) are isomorphic if and only if N𝖦(a)=N𝖦(b)N_{\mathsf{G}}(a)=N_{\mathsf{G}}(b).

Lemma 8.6.

Let a𝐱,b𝐱Ai,ja_{\mathbf{x}},b_{\mathbf{x^{\prime}}}\in A^{\prime}_{i,j} and c𝐳Ai,jc_{\mathbf{z}}\in A^{\prime}_{i,j^{\prime}} where jjj\neq j^{\prime}. Then, (𝖪,a𝐱)(𝖪,b𝐱)(\mathsf{K}_{\mathcal{R}},a_{\mathbf{x}})\cong(\mathsf{K}_{\mathcal{R}},b_{\mathbf{x^{\prime}}}) and (𝖪,a𝐱)≇(𝖪,c𝐳)(\mathsf{K}_{\mathcal{R}},a_{\mathbf{x}})\not\cong(\mathsf{K}_{\mathcal{R}},c_{\mathbf{z}}).

Proof.

We prove the lemma only for the case of the set A1,1A^{\prime}_{1,1}. The proof for the remaining sets is similar. Let a𝐱,b𝐱A1,1a_{\mathbf{x}},b_{\mathbf{x^{\prime}}}\in A^{\prime}_{1,1}, then 𝐱,𝐱A1,1\mathbf{x},\mathbf{x^{\prime}}\in A_{1,1}. Let (a𝐱,d𝐲)E(a_{\mathbf{x}},d_{\mathbf{y}})\in E. Thus, by the definition of 𝖪\mathsf{K}_{\mathcal{R}}, (𝐱,𝐲)(\mathbf{x},\mathbf{y})\in\mathcal{R}. By Lemma 8.3, (𝐱,𝐲)(\mathbf{x^{\prime}},\mathbf{y})\in\mathcal{R}. So, (b𝐱,d𝐲)E(b_{\mathbf{x^{\prime}}},d_{\mathbf{y}})\in E, therefore N𝖪(a𝐱)=N𝖪(b𝐱)N_{\mathsf{K}}(a_{\mathbf{x}})=N_{\mathsf{K}}(b_{\mathbf{x^{\prime}}}). Hence, by Lemma 8.5, (𝖪,a𝐱)(𝖪,b𝐱)(\mathsf{K}_{\mathcal{R}},a_{\mathbf{x}})\cong(\mathsf{K}_{\mathcal{R}},b_{\mathbf{x^{\prime}}}).

Let i[2]i\in[2], by the definition of 𝖪\mathsf{K}_{\mathcal{R}}, if a𝐱Ai,1a_{\mathbf{x}}\in A^{\prime}_{i,1} and c𝐳Ai,2c_{\mathbf{z}}\in A^{\prime}_{i,2} then there exists d𝐲d_{\mathbf{y}} such that (d𝐲,c𝐳)E(d_{\mathbf{y}},c_{\mathbf{z}})\in E, but (a𝐱,d𝐲)E(a_{\mathbf{x}},d_{\mathbf{y}})\not\in E. Hence, by Lemma 8.5, (𝖪,a𝐱)≇(𝖪,c𝐳)(\mathsf{K}_{\mathcal{R}},a_{\mathbf{x}})\not\cong(\mathsf{K}_{\mathcal{R}},c_{\mathbf{z}}). ∎

We need one more ingredient before proving Proposition 8.4. We need to show that the pp-reduced form of 𝖪\mathsf{K}_{\mathcal{R}} is not trivial. Let πi,j\pi_{i,j} be an automorphism of 𝖪\mathsf{K}_{\mathcal{R}} such that πi,j(x)=x\pi_{i,j}(x)=x for all xAi,jx\not\in A^{\prime}_{i,j} and it is a permutation on Ai,jA^{\prime}_{i,j}. Since Ai,jA^{\prime}_{i,j} is protected, any pp-automorphism on Ai,jA^{\prime}_{i,j} has a fixed point. Let Ai,j~\widetilde{A^{\prime}_{i,j}} denote the set Ai,jA^{\prime}_{i,j} after removing all automorphisms of order pp from 𝖪\mathsf{K}_{\mathcal{R}}. Clearly |Ai,j~||Ai,j|0(modp)|\widetilde{A^{\prime}_{i,j}}|\equiv|A^{\prime}_{i,j}|\not\equiv 0\pmod{p}. Thus, the reduced form 𝖪\mathsf{K}_{\mathcal{R}} is not trivial, and in fact, based on the properties of 𝖪\mathsf{K}_{\mathcal{R}}, it is not a complete bipartite graph.

Thus, the following lemma can be concluded by Theorem 1.2.

Lemma 8.7.

The problem #p𝖧𝗈𝗆(𝖪)\#_{p}\mathsf{Hom}(\mathsf{K}_{\mathcal{R}}) is #pP\#_{p}P-hard.

Now, we are ready to prove the key lemma of this section.

Lemma 8.8.

Let \mathcal{H} have a standard hardness gadget (,A1,1,A1,2,A2,1,A2,2)(\mathcal{R},A_{1,1},A_{1,2},A_{2,1},A_{2,2}). Then #p𝖧𝗈𝗆(𝖪)#p𝖢𝖲𝖯()\#_{p}\mathsf{Hom}(\mathsf{K}_{\mathcal{R}})\leq\#_{p}\mathsf{CSP}(\mathcal{H}).

Proof.

Let 𝖦\mathsf{G} be an instance of the problem #p𝖧𝗈𝗆(𝖪)\#_{p}\mathsf{Hom}(\mathsf{K}_{\mathcal{R}}). We define the following instance 𝒫=(V,𝒞)\mathcal{P}=(V,\mathcal{C}) of 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}). Note that in this instance, we only use the pp-mpp-definable relation \mathcal{R} from the standard hardness gadget.

  • For each uLu\in L, we define 𝐱u=(𝐱u,1,,𝐱u,s)\mathbf{x}_{u}=(\mathbf{x}_{u,1},...,\mathbf{x}_{u,s}).

  • For each vRv\in R, we define 𝐲v=(𝐲v,1,,𝐲v,t)\mathbf{y}_{v}=(\mathbf{y}_{v,1},...,\mathbf{y}_{v,t}).

  • V=uL{𝐱u,1,,𝐱u,s}vR{𝐲v,1,,𝐲v,t}V=\bigcup_{u\in L}\{\mathbf{x}_{u,1},...,\mathbf{x}_{u,s}\}\cup\bigcup_{v\in R}\{\mathbf{y}_{v,1},...,\mathbf{y}_{v,t}\}.

  • For each (u,v)E(u,v)\in E, define C=(𝐱u,1,,𝐱u,s,𝐲v,1,,𝐲v,t),C=\langle(\mathbf{x}_{u,1},...,\mathbf{x}_{u,s},\mathbf{y}_{v,1},...,\mathbf{y}_{v,t}),\mathcal{R}\rangle.

We show that each solution ψ\psi for 𝒫\mathcal{P} gives rise to a homomorphism from 𝖦\mathsf{G} to 𝖧\mathsf{H}. Let ψ\psi be a solution for 𝒫\mathcal{P}, then ((ψ(𝐱u,1),,ψ(𝐱u,s),ψ(𝐲v,1),,ψ(𝐲v,t)))((\psi(\mathbf{x}_{u,1}),...,\psi(\mathbf{x}_{u,s}),\psi(\mathbf{y}_{v,1}),...,\psi(\mathbf{y}_{v,t})))\in\mathcal{R}. For all uLu\in L, set φ(u)=(ψ(𝐱u,1),,ψ(𝐱u,s))\varphi(u)=(\psi(\mathbf{x}_{u,1}),...,\psi(\mathbf{x}_{u,s})), and for all vRv\in R, set φ(v)=(ψ(𝐲v,1),,ψ(𝐲v,t))\varphi(v)=(\psi(\mathbf{y}_{v,1}),...,\psi(\mathbf{y}_{v,t})). Clearly, if (u,v)EG(u,v)\in E_{G}, then (φ(u),φ(v))E𝖪(\varphi(u),\varphi(v))\in E_{\mathsf{K}} since ψ\psi is a solution for 𝒫\mathcal{P}.

Conversely, let φ\varphi be a homomorphism from 𝖦\mathsf{G} to 𝖪\mathsf{K}. Define the following solution for 𝒫\mathcal{P}: ψ(𝐱u,i)=𝔉1(φ(u))[i]\psi(\mathbf{x}_{u,i})=\mathfrak{F}^{-1}(\varphi(u))[i]. Since φ𝖧𝗈𝗆(𝖦,𝖪)\varphi\in\mathsf{Hom}(\mathsf{G},\mathsf{K}_{\mathcal{R}}), if (u,v)E𝖦(u,v)\in E_{\mathsf{G}}, then (φ(u),φ(v))E𝖪(\varphi(u),\varphi(v))\in E_{\mathsf{K}_{\mathcal{R}}}. Note that φ(u),φ(v)\varphi(u),\varphi(v) are nodes in 𝖪\mathsf{K}_{\mathcal{R}}. So, we can apply the reverse mapping of 𝔉\mathfrak{F}. Hence, we will have (𝔉1(φ(u)),𝔉1(φ(v)))(\mathfrak{F}^{-1}(\varphi(u)),\mathfrak{F}^{-1}(\varphi(v)))\in\mathcal{R}. Thus, ψ\psi is also a solution for 𝒫\mathcal{P}.

Therefore, the number of solutions of 𝖦\mathsf{G} in 𝗁𝗈𝗆(𝖦,𝖪)\mathsf{hom}(\mathsf{G},\mathsf{K}_{\mathcal{R}}) is the same as the number of solutions of 𝒫\mathcal{P}. The result follows. ∎

Proof of Proposition 8.4.

By Lemma 8.8, we have the reduction #p𝖧𝗈𝗆(𝖪)#p𝖢𝖲𝖯()\#_{p}\mathsf{Hom}(\mathsf{K}_{\mathcal{R}})\leq\#_{p}\mathsf{CSP}(\mathcal{H}). Additionally, from Lemma 8.7, we know that #p𝖧𝗈𝗆(𝖪)\#_{p}\mathsf{Hom}(\mathsf{K}_{\mathcal{R}}) is #pP\#_{p}P-hard. Therefore, if \mathcal{H} possesses a rectangularity obstruction, it is #pP\#_{p}P-complete. ∎

Standard hardness gadgets provide a fairly limited condition for the hardness of #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}). In fact, it is possible to prove that #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) is #pP\#_{p}P-complete whenever \mathcal{H} 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 \mathcal{H} to a one consisting of binary rectangular relations. This transformation, although hugely increasing the sizes of domains, preserves many of the useful properties of \mathcal{H} including certain types of polymorphisms and automorphisms. Also, the counting CSP over the new language is parsimoniously interreducible with that over \mathcal{H}. The hope therefore is that such transformation reduces a complexity classification of #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) 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 𝖺𝗋()\mathsf{ar}(\mathcal{R}) we denote the arity of relation \mathcal{R}.

Let ={{Hi}i[k];𝒬1,,𝒬n)\mathcal{H}=\{\{H_{i}\}_{i\in[k]};\mathcal{Q}_{1},\dots,\mathcal{Q}_{n}) be a finite multi-sorted relational structure. We assume that every HiH_{i} is among 𝒬1,,𝒬n\mathcal{Q}_{1},\dots,\mathcal{Q}_{n} as a unary relation. The structure b()b(\mathcal{H}) is constructed as follows:

  • The domains are 𝒬1,,𝒬n\mathcal{Q}_{1},\dots,\mathcal{Q}_{n}, the relations from \mathcal{H}.

  • For 𝒬i,𝒬j\mathcal{Q}_{i},\mathcal{Q}_{j}, iji\leq j, and s[𝖺𝗋(𝒬i)],t[𝖺𝗋(𝒬j)]s\in[\mathsf{ar}(\mathcal{Q}_{i})],t\in[\mathsf{ar}(\mathcal{Q}_{j})], the structure b()b(\mathcal{H}) contains the binary relation stij𝒬i×𝒬j\mathcal{R}^{ij}_{st}\subseteq\mathcal{Q}_{i}\times\mathcal{Q}_{j} given by stij={(𝐚,𝐛)𝐚𝒬i,𝐛𝒬j,as=bt}.\mathcal{R}^{ij}_{st}=\{(\mathbf{a},\mathbf{b})\mid\mathbf{a}\in\mathcal{Q}_{i},\mathbf{b}\in\mathcal{Q}_{j},a_{s}=b_{t}\}.

First we show that the 𝖢𝖲𝖯\mathsf{CSP} over b()b(\mathcal{H}) is interreducible with that over \mathcal{H}.

Proposition 9.1 (see also Theorem 4,[9]).

(1) For any structure \mathcal{H}, #𝖢𝖲𝖯()\mathsf{\#CSP}(\mathcal{H}) is parsimoniously interreducible with #𝖢𝖲𝖯(b())\mathsf{\#CSP}(b(\mathcal{H})).
(2) For any structure \mathcal{H}, #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) is parsimoniously interreducible with #p𝖢𝖲𝖯(b())\#_{p}\mathsf{CSP}(b(\mathcal{H})).

Proof.

We use the standard definition of the CSP. Let 𝒫\mathcal{P} be any instance of #𝖢𝖲𝖯()\mathsf{\#CSP}(\mathcal{H}), with variable set VV and constraint set 𝒞\mathcal{C}. We assume that for every vVv\in V with domain AHA\in H, 𝒫\mathcal{P} contains a constraint (v),A\langle(v),A\rangle. We construct an instance 𝒫\mathcal{P}^{\prime} of #𝖢𝖲𝖯(b())\mathsf{\#CSP}(b(\mathcal{H})), which has variable set VV^{\prime} and constraint set 𝒞\mathcal{C}^{\prime}, as follows.
(i) For each C𝒞C\in\mathcal{C}, we introduce a variable vCVv_{C}\in V^{\prime}. Thus V=𝒞V^{\prime}=\mathcal{C}.
(ii) For all C1,C2𝒞C_{1},C_{2}\in\mathcal{C}, C1=(v11,,vk1),i,C2=(v12,,v2),jC_{1}=\langle(v^{1}_{1},\dots,v^{1}_{k}),\mathcal{R}_{i}\rangle,C_{2}=\langle(v^{2}_{1},\dots,v^{2}_{\ell}),\mathcal{R}_{j}\rangle, such that vs1=vt2v^{1}_{s}=v^{2}_{t} we introduce a constraint (vC1,vC2),stij𝒞\langle(v_{C_{1}},v_{C_{2}}),\mathcal{R}^{ij}_{st}\rangle\in\mathcal{C}^{\prime}.

Let φ:Vi[k]Hi\varphi:V\to\bigcup_{i\in[k]}H_{i} be any solution of 𝒫\mathcal{P}. Then define φ:V\varphi^{\prime}:V^{\prime}\to\bigcup_{\mathcal{R}\in\mathcal{H}}\mathcal{R} as follows. For every vCVv_{C}\in V^{\prime} with C=(s1,,sk),C=\langle(s_{1},\dots,s_{k}),\mathcal{R}\rangle, set φ(vC)=(φ(s1),,φ(sk))\varphi^{\prime}(v_{C})=(\varphi(s_{1}),\dots,\varphi(s_{k})). As is easily seen, φ\varphi^{\prime} is a solution of 𝒫\mathcal{P}^{\prime}. Conversely, if φ\varphi^{\prime} is a solution of 𝒫\mathcal{P}^{\prime}, then, as every AHA\in H is a relation from \mathcal{H}, the action of φ\varphi^{\prime} on the domains from HH is well defined, let us denote it φ\varphi. We would like to argue now that the action of φ\varphi^{\prime} on relations i\mathcal{R}_{i} coincides with the component-wise action of φ\varphi. In other words that for any 𝐚i\mathbf{a}\in\mathcal{R}_{i}, where 𝐚=(a1,,ak)\mathbf{a}=(a_{1},\dots,a_{k}), it holds that φ(𝐚)=(φ(a1),,φ(ak))\varphi^{\prime}(\mathbf{a})=(\varphi(a_{1}),\dots,\varphi(a_{k})). Let the \ellth coordinate of i\mathcal{R}_{i} be HjH_{j}, which is also the jjth domain for b()b(\mathcal{H}). Then φ\varphi^{\prime} preserves the relation 1ij\mathcal{R}^{ij}_{\ell 1}, which means that for any (𝐚,b)1ij(\mathbf{a},b)\in\mathcal{R}^{ij}_{\ell 1} we have a=ba_{\ell}=b and

φ(𝐚b)=(φ(𝐚)φ(b))1ij.\varphi^{\prime}\left(\begin{array}[]{c}\mathbf{a}\\ b\end{array}\right)=\left(\begin{array}[]{c}\varphi^{\prime}(\mathbf{a})\\ \varphi(b)\end{array}\right)\in\mathcal{R}^{ij}_{\ell 1}.

Then if φ(𝐚)=(c1,,ck)\varphi^{\prime}(\mathbf{a})=(c_{1},\dots,c_{k}), then c=φ(b)c_{\ell}=\varphi(b), proving the result.

Conversely, suppose 𝒫\mathcal{P}^{\prime} is any instance of #𝖢𝖲𝖯(b())\mathsf{\#CSP}(b(\mathcal{H})) with variable set VV^{\prime} and constraint set 𝒞\mathcal{C}^{\prime}. We construct an instance 𝒫\mathcal{P} of #𝖢𝖲𝖯()\mathsf{\#CSP}(\mathcal{H}), with variable set VV and constraint set 𝒞\mathcal{C}, as follows. Recall that every variable vVv\in V^{\prime} has an associated domain v\mathcal{R}^{v}\in\mathcal{H}. Let rvr_{v} be the arity of v\mathcal{R}^{v}. We now create a relation \sim on the set V=vV({v}×[rv])V^{*}=\bigcup_{v\in V^{\prime}}(\{v\}\times[r_{v}]), as follows. For u,vVu,v\in V^{\prime}, let (u,s)(v,t)(u,s)\sim^{\prime}(v,t) if there is a constraint (u,v),stij𝒞\langle(u,v),\mathcal{R}^{ij}_{st}\rangle\in\mathcal{C}^{\prime}, where the domain of uu is i\mathcal{R}_{i}, the domain of vv is j\mathcal{R}_{j}, and s[ru],t[rv]s\in[r_{u}],t\in[r_{v}]. Then \sim is the symmetric-transitive closure of \sim^{\prime}. Clearly, \sim is an equivalence relation, which “identifies” the variables (u,s)(u,s) and (v,t)(v,t). Now, suppose φ\varphi^{\prime} is any solution of 𝒫\mathcal{P}^{\prime}. Then, for any vVv\in V^{\prime}, we have φ(v)=(a1,,arv)v\varphi^{\prime}(v)=(a_{1},\dots,a_{r_{v}})\in\mathcal{R}^{v}. Let us write φs(v)=as\varphi^{\prime}_{s}(v)=a_{s} (s[rv]s\in[r_{v}]). Now, define φ:Vi[k]Hi\varphi:V^{*}\to\bigcup_{i\in[k]}H_{i} from φ\varphi^{\prime} by φ(v,s)=φs(v)\varphi(v,s)=\varphi^{\prime}_{s}(v) for all (v,s)V(v,s)\in V^{*}, s[rv]s\in[r_{v}]. We will write φ=ζ(φ)\varphi=\zeta(\varphi^{\prime}) for this function. If, for any u,vVu,v\in V^{\prime}, we have (u,s)(v,t)(u,s)\sim(v,t), then we must have (φ(u),φ(v))stij(\varphi^{\prime}(u),\varphi^{\prime}(v))\in\mathcal{R}^{ij}_{st}. This implies that φs(u)=φt(v)\varphi^{\prime}_{s}(u)=\varphi^{\prime}_{t}(v), and hence φ(u,s)=φ(v,t)\varphi(u,s)=\varphi(v,t), where φ=ζ(φ)\varphi=\zeta(\varphi^{\prime}). Let the variable set VV of 𝒫\mathcal{P} will be the set of equivalence classes V/V^{*}/\sim. For any (v,s)V(v,s)\in V^{*}, we write (v,s)¯\overline{(v,s)} for its equivalence class. Let φ:Vi[k]Hi\varphi:V^{*}\to\bigcup_{i\in[k]}H_{i} be such that φ=ζ(φ)\varphi=\zeta(\varphi^{\prime}) for some φ:V{H1,,Hk}\varphi^{\prime}:V\to\{H_{1},\dots,H_{k}\}. Then we can define φ¯:Vi[k]Hi\overline{\varphi}:V\to\bigcup_{i\in[k]}H_{i} by φ¯((v,s)¯)=φ(v,s)\overline{\varphi}(\overline{(v,s)})=\varphi(v,s) for all (v,s)(v,s)¯(v,s)\in\overline{(v,s)}. Thus we have constructed a bijection between the mappings φ¯:V{H1,,Hk}\overline{\varphi}:V\to\{H_{1},\dots,H_{k}\} and mappings φ:VH\varphi^{\prime}:V^{\prime}\to\bigcup H that may potentially be solutions of 𝒫\mathcal{P}^{\prime}. We will write φ¯=ξ(φ)\overline{\varphi}=\xi(\varphi^{\prime}) for this bijection. Now, 𝒫\mathcal{P} will have constraint set

𝒞={𝐯,𝐯=((v,1)¯,,(v,rv)¯),vV, and Hi1××Hirv is the domain of v}.\mathcal{C}=\{\langle\mathbf{v},\mathcal{R}\rangle\mid\mathbf{v}=(\overline{(v,1)},\dots,\overline{(v,r_{v})}),v\in V^{\prime},\text{ and $\mathcal{R}\subseteq H_{i_{1}}\times\dots\times H_{i_{r_{v}}}$ is the domain of $v$}\}.

Then, φ¯=ξ(φ)\overline{\varphi}=\xi(\varphi^{\prime}) is a solution of 𝒫\mathcal{P} if and only if φ\varphi^{\prime} is a solution of 𝒫\mathcal{P}^{\prime}, and we have a parsimonious reduction from #𝖢𝖲𝖯(b()\mathsf{\#CSP}(b(\mathcal{H}) to #𝖢𝖲𝖯()\mathsf{\#CSP}(\mathcal{H}). ∎

The structure b()b(\mathcal{H}) inherits other properties of \mathcal{H}.

Proposition 9.2.

Let ={{Hi}i[k];𝒬1,,𝒬n)\mathcal{H}=\{\{H_{i}\}_{i\in[k]};\mathcal{Q}_{1},\dots,\mathcal{Q}_{n}) be a multi-sorted structure. Then
(1) \mathcal{H} has a Mal’tsev polymorphism if and only if b()b(\mathcal{H}) does;
(2) \mathcal{H} is pp-rigid if and only if b()b(\mathcal{H}) is;
(3) If \mathcal{H} is strongly pp-rectangular then so is b()b(\mathcal{H}).

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 \mathcal{H} has a Mal’tsev polymorphism ff. Then for any \mathcal{R}\in\mathcal{H} and any 𝐚1,𝐚2,𝐚3\mathbf{a}_{1},\mathbf{a}_{2},\mathbf{a}_{3}\in\mathcal{R}, the tuple f(𝐚1,𝐚2,𝐚3)f(\mathbf{a}_{1},\mathbf{a}_{2},\mathbf{a}_{3})\in\mathcal{R}, and this action defines an operation fbf^{b} on the domains of b()b(\mathcal{H}) (i.e. relations from \mathcal{H}). Moreover, fbf^{b} is Mal’tsev, because in the notation above f(𝐚1,𝐚1,𝐚2)=f(𝐚2,𝐚1,𝐚1)=𝐚2f(\mathbf{a}_{1},\mathbf{a}_{1},\mathbf{a}_{2})=f(\mathbf{a}_{2},\mathbf{a}_{1},\mathbf{a}_{1})=\mathbf{a}_{2}. It remains to make sure that fbf^{b} preserves stij\mathcal{R}^{ij}_{st}. Let (𝐚1,𝐛1),(𝐚2,𝐛2),(𝐚3,𝐛3)stij(\mathbf{a}_{1},\mathbf{b}_{1}),(\mathbf{a}_{2},\mathbf{b}_{2}),(\mathbf{a}_{3},\mathbf{b}_{3})\in\mathcal{R}^{ij}_{st}, where 𝐚i=(ai1,,aik),𝐛i=(bi1,,bi)\mathbf{a}_{i}=(a_{i1},\dots,a_{ik}),\mathbf{b}_{i}=(b_{i1},\dots,b_{i\ell}). Then we have a1s=b1t,a2s=b2t,a3s=b3ta_{1s}=b_{1t},a_{2s}=b_{2t},a_{3s}=b_{3t}, and therefore, for

(𝐜𝐝)=fb((𝐚1𝐛1),(𝐚2𝐛2),(𝐚3𝐛3))\left(\begin{array}[]{c}\mathbf{c}\\ \mathbf{d}\end{array}\right)=f^{b}\left(\left(\begin{array}[]{c}\mathbf{a}_{1}\\ \mathbf{b}_{1}\end{array}\right),\left(\begin{array}[]{c}\mathbf{a}_{2}\\ \mathbf{b}_{2}\end{array}\right),\left(\begin{array}[]{c}\mathbf{a}_{3}\\ \mathbf{b}_{3}\end{array}\right)\right)

we obtain cs=dtc_{s}=d_{t}, and so (𝐜,𝐝)stij(\mathbf{c},\mathbf{d})\in\mathcal{R}^{ij}_{st}.

Suppose now that there is a Mal’tsev polymorphism ff of b()b(\mathcal{H}). Since Hi{𝒬1,,𝒬m}H_{i}\in\{\mathcal{Q}_{1},\dots,\mathcal{Q}_{m}\} for each i[k]i\in[k], the action of ff on the domains from HH is well defined, let us denote it ff^{\prime}. We would like to argue now that the action of ff on relations i\mathcal{R}_{i} coincides with the component-wise action of ff^{\prime}. In other words that for any 𝐚1,𝐚2,𝐚3i\mathbf{a}_{1},\mathbf{a}_{2},\mathbf{a}_{3}\in\mathcal{R}_{i}, where 𝐚j=(aj1,,ajk)\mathbf{a}_{j}=(a_{j1},\dots,a_{jk})

f(𝐚1,𝐚2,𝐚3)=(f(a11,a21,a31)f(a1k,a2k,a3k)).f(\mathbf{a}_{1},\mathbf{a}_{2},\mathbf{a}_{3})=\left(\begin{array}[]{c}f^{\prime}(a_{11},a_{21},a_{31})\\ \vdots\\ f^{\prime}(a_{1k},a_{2k},a_{3k})\end{array}\right).

Let the \ellth coordinate of i\mathcal{R}_{i} be HjH_{j}, which is also the jjth domain for b()b(\mathcal{H}). Then ff preserves the relation 1ij\mathcal{R}^{ij}_{\ell 1}, which means that for any (𝐚1,b1),(𝐚2,b2),(𝐚3,b3)1ij(\mathbf{a}_{1},b_{1}),(\mathbf{a}_{2},b_{2}),(\mathbf{a}_{3},b_{3})\in\mathcal{R}^{ij}_{\ell 1} we have a1=b1,a2=b2,a3=b3a_{1\ell}=b_{1},a_{2\ell}=b_{2},a_{3\ell}=b_{3} and

f((𝐚1b1),(𝐚2b2),(𝐚3b3))=(f(𝐚1,𝐚2,𝐚3)f(b1,b2,b3)).f\left(\left(\begin{array}[]{c}\mathbf{a}_{1}\\ b_{1}\end{array}\right),\left(\begin{array}[]{c}\mathbf{a}_{2}\\ b_{2}\end{array}\right),\left(\begin{array}[]{c}\mathbf{a}_{3}\\ b_{3}\end{array}\right)\right)=\left(\begin{array}[]{c}f(\mathbf{a}_{1},\mathbf{a}_{2},\mathbf{a}_{3})\\ f^{\prime}(b_{1},b_{2},b_{3})\end{array}\right).

Denoting 𝐜=f(𝐚1,𝐚2,𝐚3)\mathbf{c}=f(\mathbf{a}_{1},\mathbf{a}_{2},\mathbf{a}_{3}), we obtain c=f(b1,b2,b3)c_{\ell}=f^{\prime}(b_{1},b_{2},b_{3}), implying that ff acts as ff^{\prime} coordinate-wise.

(2) Let π\pi be a pp-automorphism of \mathcal{H}. Then π\pi is a unary polymorphism of \mathcal{H}, and therefore as in item (1) πb\pi^{b} is a unary polymorphism of b()b(\mathcal{H}). That it is a pp-automorphism is straightforward. The reverse claim is as in (1), as well.

(3) Suppose that b(Γ)p\langle b(\Gamma)\rangle_{p} is not p-rectangular. This means that there is 𝒬(𝐱)=2𝐲Φ(𝐱,𝐲)\mathcal{Q}^{\prime}(\mathbf{x})=\exists^{2}\mathbf{y}\Phi^{\prime}(\mathbf{x},\mathbf{y}), where Φ\Phi^{\prime} is a conjunctive formula, such that 𝒬\mathcal{Q}^{\prime} is not rectangular. We consider Φ\Phi^{\prime} as an instance of #𝖢𝖲𝖯(b())\mathsf{\#CSP}(b(\mathcal{H})) and apply the transformation from the proof of Proposition 9.1 (from a #𝖢𝖲𝖯(b())\mathsf{\#CSP}(b(\mathcal{H})) instance to a #𝖢𝖲𝖯()\mathsf{\#CSP}(\mathcal{H}) instance). Let V=V1V2V^{\prime}=V^{\prime}_{1}\cup V^{\prime}_{2}, where V1={x1,,xk},V2={y1,,y}V^{\prime}_{1}=\{x_{1},\dots,x_{k}\},V^{\prime}_{2}=\{y_{1},\dots,y_{\ell}\}, and 𝐱=(x1,,xk),𝐲=(y1,,y)\mathbf{x}=(x_{1},\dots,x_{k}),\mathbf{y}=(y_{1},\dots,y_{\ell}). The set 𝒞\mathcal{C}^{\prime} of constraints is the set of all atoms in Φ\Phi^{\prime}. Let the set of variables VV and the set 𝒞\mathcal{C} of constraints be constructed as in the proof of Proposition 9.1. Let also V1={(x,s)¯xV1}V_{1}=\{\overline{(x,s)}\mid x\in V^{\prime}_{1}\}, V2=VV1V_{2}=V-V_{1}, denote V1={z1,,zm},V2={t1,,tn}V_{1}=\{z_{1},\dots,z_{m}\},V_{2}=\{t_{1},\dots,t_{n}\}. Set

Φ(z1,,zm,y1,,yn)=𝐬,𝒞(𝐬),\Phi(z_{1},\dots,z_{m},y_{1},\dots,y_{n})=\bigwedge_{\langle\mathbf{s},\mathcal{R}\rangle\in\mathcal{C}}\mathcal{R}(\mathbf{s}),

and

𝒬(z1,,zm)=2t1,,tnΦ(z1,,zm,t1,,tn).\mathcal{Q}(z_{1},\dots,z_{m})=\exists^{\equiv 2}t_{1},\dots,t_{n}\Phi(z_{1},\dots,z_{m},t_{1},\dots,t_{n}).

We prove that 𝒬\mathcal{Q} is not rectangular.

Without loss of generality we may assume that a witness of non-pp-rectangularity of 𝒬\mathcal{Q}^{\prime} is as follows: J[m],K=[m]JJ\subseteq[m],K=[m]-J, φ1,φ2𝗉𝗋J𝒬,ψ1,ψ2𝗉𝗋K𝒬\varphi_{1},\varphi_{2}\in\mathsf{pr}_{J}\mathcal{Q}^{\prime},\psi_{1},\psi_{2}\in\mathsf{pr}_{K}\mathcal{Q}^{\prime} are such that (φ1,ψ1),(φ1,ψ2),(φ2,ψ1)𝒬(\varphi_{1},\psi_{1}),(\varphi_{1},\psi_{2}),(\varphi_{2},\psi_{1})\in\mathcal{Q}^{\prime}, but (φ2,ψ2)𝒬(\varphi_{2},\psi_{2})\not\in\mathcal{Q}^{\prime}. Let W1V1W_{1}\subseteq V_{1} be given by W1={(v,s)¯vJ}W_{1}=\{\overline{(v,s)}\mid v\in J\} and W2=V1W1W_{2}=V_{1}-W_{1}. We first observe that W2W_{2}\neq\emptyset. Indeed, by construction if (v,s)(u,t)(v,s)\sim(u,t) then for any solution φ:VΓ\varphi:V^{\prime}\to\bigcup\Gamma, where φ(v)=(a1,,ak),φ(u)=(b1,,b)\varphi(v)=(a_{1},\dots,a_{k}),\varphi(u)=(b_{1},\dots,b_{\ell}) we have as=bta_{s}=b_{t}. That W2=W_{2}=\emptyset means that for any xiKx_{i}\in K and any s[rxi]s\in[r_{x_{i}}] it holds that (xi,s)(xj,t)(x_{i},s)\sim(x_{j},t) for some xjJx_{j}\in J and t[rxj]t\in[r_{x_{j}}]. Therefore for any φ𝒬\varphi\in\mathcal{Q}, the assignment 𝗉𝗋Kφ\mathsf{pr}_{K}\varphi is determined by the assignment 𝗉𝗋Jφ\mathsf{pr}_{J}\varphi, a contradiction with the choice of a counterexample of pp-rectangularity.

That (φ1,ψ1),(φ1,ψ2),(φ2,ψ1)𝒬(\varphi_{1},\psi_{1}),(\varphi_{1},\psi_{2}),(\varphi_{2},\psi_{1})\in\mathcal{Q}, but (φ2,ψ2)𝒬(\varphi_{2},\psi_{2})\not\in\mathcal{Q} means that the first three assignments have the number of extensions to an assignment VΓV^{\prime}\to\bigcup\Gamma not divisible by pp, while (φ2,ψ2)(\varphi_{2},\psi_{2}) has a number of such extensions that is a multiple of pp (including zero). Observe now that we can apply the bijection ξ\xi to assignments φi,ψi\varphi_{i},\psi_{i} as follows: take any σ\sigma^{\prime} that extends one of them to an assignment VΓV^{\prime}\to\bigcup\Gamma, take σ=ξ(σ)\sigma=\xi(\sigma^{\prime}) and set σ=𝗉𝗋W1σ\sigma^{*}=\mathsf{pr}_{W_{1}}\sigma or σ=𝗉𝗋W2σ\sigma^{*}=\mathsf{pr}_{W_{2}}\sigma depending on whether we deal with φ1,φ2\varphi_{1},\varphi_{2} or ψ1,ψ2\psi_{1},\psi_{2}. Then since ξ\xi is a bijection, the number of extensions of (ξ(φi),ξ(ψj))(\xi(\varphi_{i}),\xi(\psi_{j})) to an assignment of VV equals that of (φi,ψj)(\varphi_{i},\psi_{j}) to an assignment of VV^{\prime}. Thus, (ξ(φ1),ξ(ψ1)),(ξ(φ1),ξ(ψ2)),(ξ(φ2),ξ(ψ1))(\xi(\varphi_{1}),\xi(\psi_{1})),(\xi(\varphi_{1}),\xi(\psi_{2})),(\xi(\varphi_{2}),\xi(\psi_{1})) have the number of extensions not divisible by pp and so belong to 𝒬\mathcal{Q}, while (ξ(φ2),ξ(ψ2))(\xi(\varphi_{2}),\xi(\psi_{2})) has the number of extensions divisible by pp, and so does not belong to 𝒬\mathcal{Q}, witnessing that 𝒬\mathcal{Q} 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 k4k_{4}-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 nn-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 p\mathcal{H}^{*p}

The goal of this subsection is to prove Proposition 2.1.

Proposition A.1.

Let \mathcal{H} be a multi-sorted structure and pp a prime. Then up to an isomorphism there exists a unique pp-rigid multi-sorted structure p\mathcal{H}^{*p} such that pp\mathcal{H}\rightarrow_{p}^{*}\mathcal{H}^{*p}.

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 (𝒢,𝐚)(\mathcal{G},\mathbf{a}) with distinguished vertices can be viewed as an expansion of 𝒢\mathcal{G} with kk 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 σ\sigma-multi-sorted structures ,𝒢\mathcal{H},\mathcal{G}, denoted ×𝒢\mathcal{H}\times\mathcal{G} is the σ\sigma-multi-sorted-structure with the base set {Hi×Gi}i[k]\{H_{i}\times G_{i}\}_{{i\in[k]}} and such that the interpretation of σ\mathcal{R}\in\sigma is given by ×𝒢((a1,b1),,(ak,bk))=1\mathcal{R}^{\mathcal{H}\times\mathcal{G}}((a_{1},b_{1}),\dots,(a_{k},b_{k}))=1 if and only if (a1,,ak)=1\mathcal{R}^{\mathcal{H}}(a_{1},\dots,a_{k})=1 and 𝒢(b1,,bk)=1\mathcal{R}^{\mathcal{G}}(b_{1},\dots,b_{k})=1. By \mathcal{H}^{\ell} we will denote the \ellth power of \mathcal{H}, that is, the direct product of \ell copies of \mathcal{H}. The direct product (𝒢,𝐱)×(,𝐲)(\mathcal{G},\mathbf{x})\times(\mathcal{H},\mathbf{y}) of structures (𝒢,𝐱),(,𝐲)(\mathcal{G},\mathbf{x}),(\mathcal{H},\mathbf{y}) is defined to be (𝒢×,(x1,y1),,(xr,yr))(\mathcal{G}\times\mathcal{H},(x_{1},y_{1}),\dots,(x_{r},y_{r})).

Two rr-tuples 𝐱\mathbf{x} and 𝐲\mathbf{y} have the same equality type if (xi,𝗍𝗒𝗉𝖾(xi))=(xj,𝗍𝗒𝗉𝖾(xj))(x_{i},\mathsf{type}(x_{i}))=(x_{j},\mathsf{type}(x_{j})) if and only if (yi,𝗍𝗒𝗉𝖾(yi))=(yj,𝗍𝗒𝗉𝖾(yj))(y_{i},\mathsf{type}(y_{i}))=(y_{j},\mathsf{type}(y_{j})) for i,j[r]i,j\in[r]. Let (𝒢,𝐱)(\mathcal{G},\mathbf{x}) and (,𝐲)(\mathcal{H},\mathbf{y}) be multi-sorted structures with rr distinguished vertices and such that 𝐱\mathbf{x} and 𝐲\mathbf{y} have the same equality type. Then (𝒢,𝐱)(,𝐲)(\mathcal{G},\mathbf{x})\odot(\mathcal{H},\mathbf{y}) denotes the structure that is obtained by taking the disjoint union of 𝒢\mathcal{G} and \mathcal{H} and identifying every xix_{i} with yiy_{i}, i[r]i\in[r]. The distinguished vertices of the new structure are x1,,xrx_{1},\dots,x_{r}.

The following statement is straightforward.

Proposition A.2.

Let (𝒢,𝐱),(,𝐲),(𝒦,𝐳)(\mathcal{G},\mathbf{x}),(\mathcal{H},\mathbf{y}),(\mathcal{K},\mathbf{z}) be similar multi-sorted relational structures with rr distinguished vertices. Then

𝗁𝗈𝗆((𝒢,𝐱)(,𝐲),(𝒦,𝐳))\displaystyle\mathsf{hom}((\mathcal{G},\mathbf{x})\odot(\mathcal{H},\mathbf{y}),(\mathcal{K},\mathbf{z})) =𝗁𝗈𝗆((𝒢,𝐱),(𝒦,𝐳))𝗁𝗈𝗆((,𝐲),(𝒦,𝐳));\displaystyle=\mathsf{hom}((\mathcal{G},\mathbf{x}),(\mathcal{K},\mathbf{z}))\cdot\mathsf{hom}((\mathcal{H},\mathbf{y}),(\mathcal{K},\mathbf{z}));
𝗁𝗈𝗆((𝒦,𝐳),((𝒢,𝐱)×(,𝐲))\displaystyle\mathsf{hom}((\mathcal{K},\mathbf{z}),((\mathcal{G},\mathbf{x})\times(\mathcal{H},\mathbf{y})) =𝗁𝗈𝗆((𝒦,𝐳),(𝒢,𝐱))𝗁𝗈𝗆((𝒦,𝐳),(,𝐲)).\displaystyle=\mathsf{hom}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x}))\cdot\mathsf{hom}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y})).

Moreover, φ𝖧𝗈𝗆((𝒦,𝐳),((𝒢,𝐱)×(,𝐲))\varphi\in\mathsf{Hom}((\mathcal{K},\mathbf{z}),((\mathcal{G},\mathbf{x})\times(\mathcal{H},\mathbf{y})) if and only if there exist φ1𝖧𝗈𝗆((𝒦,𝐳),(𝒢,𝐱))\varphi_{1}\in\mathsf{Hom}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x})) and φ2𝖧𝗈𝗆((𝒦,𝐳),(,𝐲))\varphi_{2}\in\mathsf{Hom}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y})) such that φ(v)=(φ1(v),φ2(v))\varphi(v)=(\varphi_{1}(v),\varphi_{2}(v)) for vKv\in K.

We will also need another simple observation. By 𝗂𝗇𝗃((𝒢,𝐱),(,𝐲))\mathsf{inj}((\mathcal{G},\mathbf{x}),(\mathcal{H},\mathbf{y})) we denote the number of injective homomorphisms from (𝒢,𝐱)(\mathcal{G},\mathbf{x}) to (,𝐲)(\mathcal{H},\mathbf{y}).

Lemma A.3 (cf. [24]).

Let (𝒢,𝐱)(\mathcal{G},\mathbf{x}) and (,𝐲)(\mathcal{H},\mathbf{y}) be similar multi-sorted relational structures with rr distinguished vertices. If 𝐱,𝐲\mathbf{x},\mathbf{y} do not have the same equality type, then 𝗂𝗇𝗃((𝒢,𝐱),(,𝐲))=0\mathsf{inj}((\mathcal{G},\mathbf{x}),(\mathcal{H},\mathbf{y}))=0.

Proof.

If there are i,j[r]i,j\in[r], where rr is the arity of 𝐱\mathbf{x} and 𝐲\mathbf{y}, such that (xi,𝗍𝗒𝗉𝖾(xi))=(xj,𝗍𝗒𝗉𝖾(xj))(x_{i},\mathsf{type}(x_{i}))=(x_{j},\mathsf{type}(x_{j})) but (yi,𝗍𝗒𝗉𝖾(yi))(yj,𝗍𝗒𝗉𝖾(yj))(y_{i},\mathsf{type}(y_{i}))\neq(y_{j},\mathsf{type}(y_{j})), then there are no homomorphisms (injective or otherwise) from (𝒢,𝐱)({\mathcal{G}},\mathbf{x}) to (,𝐲)({\mathcal{H}},\mathbf{y}), since xix_{i} cannot be mapped simultaneously to both yiy_{i} and yjy_{j}. Otherwise, there must be i,j[r]i,j\in[r] such that (xi,𝗍𝗒𝗉𝖾(xi))(xj,𝗍𝗒𝗉𝖾(xj))(x_{i},\mathsf{type}(x_{i}))\neq(x_{j},\mathsf{type}(x_{j})) but (yi,𝗍𝗒𝗉𝖾(yi))=(yj,𝗍𝗒𝗉𝖾(yj))(y_{i},\mathsf{type}(y_{i}))=(y_{j},\mathsf{type}(y_{j})). Then no homomorphism φ\varphi can be injective because we must have φ(xi)=φ(xj)=yi\varphi(x_{i})=\varphi(x_{j})=y_{i}. ∎

Finally, we will use factor structures. Let \mathcal{H} be a σ\sigma-multi-sorted structure and θ={θi}i[k]\theta=\{\theta_{i}\}_{{i\in[k]}} a collection of equivalence relations on H={Hi}i[k]H=\{H_{i}\}_{{i\in[k]}}, such that θiHi2\theta_{i}\subseteq H_{i}^{2} for all i[k]i\in[k]. By /θ\mathcal{H}/_{\theta} we denote the factor structure defined as follows.

  • /θ\mathcal{H}/_{\theta} is a σ\sigma-multi-sorted structure.

  • Let Hi/θi={a/θiaHi}H_{i}/_{\theta_{i}}=\{a/_{\theta_{i}}\mid a\in H_{i}\}, where a/θia/_{\theta_{i}} denotes the θi\theta_{i}-class containing aa. The base set of /θ\mathcal{H}/_{\theta} is H/θ={H/θi}i[k]H/_{\theta}=\{H/_{\theta_{i}}\}_{{i\in[k]}}

  • For any σ\mathcal{R}\in\sigma, say, ss-ary, /θ={(a1/θ1,,as/θs)(a1,,as)}\mathcal{R}^{\mathcal{H}/_{\theta}}=\{(a_{1}/_{\theta_{1}},\dots,a_{s}/_{\theta_{s}})\mid(a_{1},\dots,a_{s})\in\mathcal{R}^{\mathcal{H}}\}.

Factor structures often appear in relation with homomorphisms. If φ\varphi is a homomorphism from a multi-sorted structure 𝒢\mathcal{G} to a multi-sorted structure \mathcal{H}, then the kernel θ\theta of φ\varphi, denoted ker(φ)\ker(\varphi), is a collection of equivalence relations on G={Gi}i[k]G=\{G_{i}\}_{{i\in[k]}} given by

For a,bGi,(a,b)θi if and only if φi(a)=φi(b).\text{For }a,b\in G_{i},\;(a,b)\in\theta_{i}\text{ if and only if }\varphi_{i}(a)=\varphi_{i}(b).

For an equivalence relation θ\theta on G={Gi}i[k]G=\{G_{i}\}_{{i\in[k]}} by 𝗁𝗈𝗆θ(𝒢,)\mathsf{hom}_{\theta}(\mathcal{G},\mathcal{H}) and 𝖧𝗈𝗆θ((𝒢,𝐱),(,𝐲))\mathsf{Hom}_{\theta}((\mathcal{G},\mathbf{x}),(\mathcal{H},\mathbf{y})) we denote the number of homomorphisms from 𝒢\mathcal{G} to \mathcal{H} (from (𝒢,𝐱)(\mathcal{G},\mathbf{x}) to (,𝐲)(\mathcal{H},\mathbf{y})) with kernel θ\theta. The homomorphism φ\varphi gives rise to a homomorphism φ/θ\varphi/_{\theta} from 𝒢/θ\mathcal{G}/_{\theta} to \mathcal{H}, where φi/θi(a/θi)=φi(a)\varphi_{i}/_{\theta_{i}}(a/_{\theta_{i}})=\varphi_{i}(a), aGia\in G_{i}. The homomorphism φ/θ\varphi/_{\theta} is always injective since all φi/θi\varphi_{i}/_{\theta_{i}} are injective.

We also define factor structures for structures with distinguished vertices as follows. Let (,𝐚)(\mathcal{H},\mathbf{a}) be a structure with ss distinguished vertices and θ\theta an equivalence relation on HH. Then (,𝐚)/θ=(/θ,(a1/θ𝗍𝗒𝗉𝖾(a1),,as/θ𝗍𝗒𝗉𝖾(as)))(\mathcal{H},\mathbf{a})/_{\theta}=(\mathcal{H}/_{\theta},(a_{1}/_{\theta_{\mathsf{type}(a_{1})}},\dots,a_{s}/_{\theta_{\mathsf{type}(a_{s})}})), where a/θ=(a1/θ𝗍𝗒𝗉𝖾(a1),,as/θ𝗍𝗒𝗉𝖾(as))a/_{\theta}=(a_{1}/_{\theta_{\mathsf{type}(a_{1})}},\dots,a_{s}/_{\theta_{\mathsf{type}(a_{s})}}).

Lemma A.4.

Let (𝒢,𝐱)(\mathcal{G},\mathbf{x}) and (,𝐲)(\mathcal{H},\mathbf{y}) be similar pp-rigid multi-sorted relational structures with rr distinguished vertices. Then, (𝒢,𝐱)(,𝐲)(\mathcal{G},\mathbf{x})\cong(\mathcal{H},\mathbf{y}) if and only if

𝗁𝗈𝗆((𝒦,𝐳),(𝒢,𝐱))𝗁𝗈𝗆((𝒦,𝐳),(,𝐲))(modp)\mathsf{hom}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x}))\equiv\mathsf{hom}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y}))\pmod{p} (5)

for all relational structures (𝒦,𝐳)(\mathcal{K},\mathbf{z}) with rr distinguished vertices.

Proof.

The proof goes along the same lines as that in [25]. If (𝒢,𝐱)(\mathcal{G},\mathbf{x}) and (,𝐲)(\mathcal{H},\mathbf{y}) are isomorphic, then (5) obviously holds for all multi-sorted relational structures (𝒦,𝐳)(\mathcal{K},\mathbf{z}).

For the other direction, suppose that (5) is true for all (𝒦,𝐳)(\mathcal{K},\mathbf{z}). First, we claim that this implies that 𝐱=(x1,,xr)\mathbf{x}=(x_{1},\ldots,x_{r}) and 𝐲=(y1,,yr)\mathbf{y}=(y_{1},\ldots,y_{r}) have the same equality type. Indeed, if they do not, then without loss of generality there are i,j[r]i,j\in[r] such that (xi,𝗍𝗒𝗉𝖾(xi))=(xj,𝗍𝗒𝗉𝖾(xj))(x_{i},\mathsf{type}(x_{i}))=(x_{j},\mathsf{type}(x_{j})) but (yi,𝗍𝗒𝗉𝖾(yi))(yj,𝗍𝗒𝗉𝖾(yj))(y_{i},\mathsf{type}(y_{i}))\neq(y_{j},\mathsf{type}(y_{j})). Let s=𝗍𝗒𝗉𝖾()s=\mathsf{type}(\mathcal{H}), X={x1,,xr}X=\{x_{1},\ldots,x_{r}\}, and 𝒦\mathcal{K} be the relational structure with the base multi-sorted set K={Ki}i[k]K=\{K_{i}\}_{{i\in[k]}} where Ki={xX|𝗍𝗒𝗉𝖾(x)=i}K_{i}=\{x\in X|\mathsf{type}(x)=i\} with empty predicates, and (x1,,xr)(x_{1},\dots,x_{r}) as distinguished vertices. Note that there might exists ii such that KiK_{i} is empty. Then 𝗁𝗈𝗆((𝒦,𝐱),(𝒢,𝐱))=10=𝗁𝗈𝗆((𝒦,𝐱),(,𝐲))\mathsf{hom}((\mathcal{K},\mathbf{x}),(\mathcal{G},\mathbf{x}))=1\neq 0=\mathsf{hom}((\mathcal{K},\mathbf{x}),(\mathcal{H},\mathbf{y})), a contradiction with the assumption that (5) holds for all (𝒦,𝐱)(\mathcal{K},\mathbf{x}).

We show by induction on the number of vertices in 𝒦\mathcal{K} that

𝗂𝗇𝗃((𝒦,𝐳),(𝒢,𝐱))𝗂𝗇𝗃((𝒦,𝐳),(,𝐲))(modp),\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x}))\equiv\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y}))\pmod{p}, (6)

for all (𝒦,𝐳)(\mathcal{K},\mathbf{z}). Let n0=|{(x1,𝗍𝗒𝗉𝖾(x1)),,(xr,𝗍𝗒𝗉𝖾(xr))}|=|{(y1,𝗍𝗒𝗉𝖾(y1)),,(yr,𝗍𝗒𝗉𝖾(yr))}|n_{0}=|\{(x_{1},\mathsf{type}(x_{1})),...,(x_{r},\mathsf{type}(x_{r}))\}|=|\{(y_{1},\mathsf{type}(y_{1})),...,(y_{r},\mathsf{type}(y_{r}))\}| be the number of distinct elements in 𝐱,𝐲\mathbf{x},\mathbf{y}. For the base case of the induction, consider a relational structure (𝒦,𝐳)(\mathcal{K},\mathbf{z}) such that |K|n0|K|\leq n_{0}. If 𝐳\mathbf{z} does not have the same equality type as 𝐱,𝐲\mathbf{x},\mathbf{y}, then 𝗂𝗇𝗃((𝒦,𝐳),(𝒢,𝐱))=𝗂𝗇𝗃((𝒦,𝐳),(,𝐲))=0\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x}))=\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y}))=0. If 𝐱\mathbf{x} has the same equality type as 𝐱,𝐲\mathbf{x},\mathbf{y}, the only homomorphisms from (𝒦,𝐳)(\mathcal{K},\mathbf{z}) to (𝒢,𝐱),(,𝐲)(\mathcal{G},\mathbf{x}),(\mathcal{H},\mathbf{y}) are the ones that map ziz_{i} to xi,yix_{i},y_{i}, respectively. Therefore, 𝗂𝗇𝗃((𝒦,𝐳),(𝒢,𝐱))=𝗂𝗇𝗃((𝒦,𝐳),(,𝐲))\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x}))=\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y})).

For the inductive step, let n>n0n>n_{0} and assume that (6) holds for all (𝒦,𝐳)(\mathcal{K},\mathbf{z}) with |K|<n|K|<n. Let (𝒦,𝐳)(\mathcal{K},\mathbf{z}) be a relational structure with |K|=n|K|=n, and let θ={θi}i[k]\theta=\{\theta_{i}\}_{{i\in[k]}} be a collection od equivalence relations on KK. Then, as is easily seen

𝗁𝗈𝗆θ((𝒦,𝐳),(𝒢,𝐱))\displaystyle\mathsf{hom}_{\theta}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x})) =𝗂𝗇𝗃((𝒦,𝐳)/θ,(𝒢,𝐱)),\displaystyle=\mathsf{inj}((\mathcal{K},\mathbf{z})/_{\theta},(\mathcal{G},\mathbf{x})),
𝗁𝗈𝗆θ((𝒦,𝐳),(,𝐲))\displaystyle\mathsf{hom}_{\theta}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y})) =𝗂𝗇𝗃((𝒦,𝐳)/θ,(,𝐲)).\displaystyle=\mathsf{inj}((\mathcal{K},\mathbf{z})/_{\theta},(\mathcal{H},\mathbf{y})).

Then

𝗁𝗈𝗆((𝒦,𝐳),(𝒢,𝐱))\displaystyle\mathsf{hom}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x})) =𝗂𝗇𝗃((𝒦,𝐳),(𝒢,𝐱))+θ𝖯𝖺𝗋𝗍(K){0¯}𝗂𝗇𝗃((𝒦,𝐳)/θ,(𝒢,𝐱)),\displaystyle=\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x}))+\sum_{\theta\in\mathsf{Part}(K)-\{{\underline{0}}\}}\mathsf{inj}((\mathcal{K},\mathbf{z})/_{\theta},(\mathcal{G},\mathbf{x})),
𝗁𝗈𝗆((𝒦,𝐳),(,𝐲))\displaystyle\mathsf{hom}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y})) =𝗂𝗇𝗃((𝒦,𝐳),(,𝐲))+θ𝖯𝖺𝗋𝗍(K){0¯}𝗂𝗇𝗃((𝒦,𝐳)/θ,(,𝐲)).\displaystyle=\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y}))+\sum_{\theta\in\mathsf{Part}(K)-\{{\underline{0}}\}}\mathsf{inj}((\mathcal{K},\mathbf{z})/_{\theta},(\mathcal{H},\mathbf{y})).

Since

𝗁𝗈𝗆((𝒦,𝐳),(𝒢,𝐱))𝗁𝗈𝗆((𝒦,𝐳),(,𝐲))(modp),\mathsf{hom}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x}))\equiv\mathsf{hom}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y}))\pmod{p},

and

𝗂𝗇𝗃((𝒦,𝐳)/θ,(𝒢,𝐱))𝗂𝗇𝗃((𝒦,𝐳)/θ,(,𝐲))(modp),\mathsf{inj}((\mathcal{K},\mathbf{z})/_{\theta},(\mathcal{G},\mathbf{x}))\equiv\mathsf{inj}((\mathcal{K},\mathbf{z})/_{\theta},(\mathcal{H},\mathbf{y}))\pmod{p},

for all θ𝖯𝖺𝗋𝗍(K){0¯}\theta\in\mathsf{Part}(K)-\{{\underline{0}}\}, it implies

𝗂𝗇𝗃((𝒦,𝐳),(𝒢,𝐱))𝗂𝗇𝗃((𝒦,𝐳),(,𝐲))(modp).\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{G},\mathbf{x}))\equiv\mathsf{inj}((\mathcal{K},\mathbf{z}),(\mathcal{H},\mathbf{y}))\pmod{p}.

Finally, we prove that (6) for (𝒦,𝐳)=(𝒢,𝐱)(\mathcal{K},\mathbf{z})=(\mathcal{G},\mathbf{x}) implies (𝒢,𝐱)(,𝐲)(\mathcal{G},\mathbf{x})\cong(\mathcal{H},\mathbf{y}). An injective homomorphism from a relational structure to itself is an automorphism. Since (𝒢,𝐱)(\mathcal{G},\mathbf{x}) is pp-rigid, |𝖠𝗎𝗍(𝒢,𝐱)|=𝗂𝗇𝗃((𝒢,𝐱),(𝒢,𝐱))0(modp)|\mathsf{Aut}(\mathcal{G},\mathbf{x})|=\mathsf{inj}((\mathcal{G},\mathbf{x}),(\mathcal{G},\mathbf{x}))\not\equiv 0\pmod{p}. Therefore, 𝗂𝗇𝗃(𝒢,𝐱),(,𝐲))0(modp)\mathsf{inj}(\mathcal{G},\mathbf{x}),(\mathcal{H},\mathbf{y}))\not\equiv 0\pmod{p}, meaning there is an injective homomorphism from (𝒢,𝐱)(\mathcal{G},\mathbf{x}) to (,𝐲)(\mathcal{H},\mathbf{y}). In a similar way, there is an injective homomorphism from (,𝐲)(\mathcal{H},\mathbf{y}) to (𝒢,𝐱)(\mathcal{G},\mathbf{x}). Thus, the two structures are isomorphic. ∎

Proof of Proposition 2.1.

Suppose the contrary, that 1\mathcal{H}_{1} and 2\mathcal{H}_{2} are two different non-isomorphic pp-reduced forms of \mathcal{H}. By Proposition 2.3 for any structure 𝒢\mathcal{G}

𝗁𝗈𝗆(𝒢,1)𝗁𝗈𝗆(𝒢,)𝗁𝗈𝗆(𝒢,2)(modp).\mathsf{hom}(\mathcal{G},\mathcal{H}_{1})\equiv\mathsf{hom}(\mathcal{G},\mathcal{H})\equiv\mathsf{hom}(\mathcal{G},\mathcal{H}_{2})\pmod{p}.

By Lemma A.4 we can conclude 12\mathcal{H}_{1}\cong\mathcal{H}_{2}. The result follows. ∎

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 \mathcal{H} the indicator problem n()\mathcal{I}_{n}(\mathcal{H}) [32] is defined as follows. Let =({Hi}i[k];1,,m)\mathcal{H}=(\{H_{i}\}_{{i\in[k]}};\mathcal{R}_{1},\dots,\mathcal{R}_{m}) be a (multi-sorted) relational structure and nn\in\mathbb{N}. The nnth indicator problem n()\mathcal{I}_{n}(\mathcal{H}) for \mathcal{H} is defined to be an instance of 𝖢𝖲𝖯()\mathsf{CSP}(\mathcal{H}) given by:

  • The set of variables VV is the set V=i[k]HinV=\bigcup_{i\in[k]}H_{i}^{n};

  • The domains are from \mathcal{H};

  • For every (say, \ell-ary) relation sHi1××Hi\mathcal{R}_{s}\subseteq H_{i_{1}}\times\dots\times H_{i_{\ell}} of \mathcal{H} and every 𝐜j=(cj1,,cjn)Hijn\mathbf{c}^{j}=(c_{j1},\dots,c_{jn})\in H_{i_{j}}^{n}, j[]j\in[\ell], such that {𝐜1,,𝐜n}s\{\mathbf{c}_{1},\dots,\mathbf{c}_{n}\}\subseteq\mathcal{R}_{s}, 𝐜i=(c1i,,ci)\mathbf{c}_{i}=(c_{1i},\dots,c_{\ell i}), n()\mathcal{I}_{n}(\mathcal{H}) contains the constraint (𝐜1,,𝐜k),s\langle(\mathbf{c}^{1},\dots,\mathbf{c}^{k}),\mathcal{R}_{s}\rangle.

Let also RGn()RG_{n}(\mathcal{H}) denote the set of solutions of n()\mathcal{I}_{n}(\mathcal{H}).

Lemma B.1 ([4, 23, 32]).

(1) RGn()RG_{n}(\mathcal{H}) is the set of all nn-ary polymorphisms of \mathcal{H}.
(2) RGn()RG_{n}(\mathcal{H}) is conjuctive-definable in \mathcal{H}.
(3) \mathcal{H} has a Mal’tsev polymorphism if and only if RG3()RG_{3}(\mathcal{H}) contains a tuple φ\varphi such that φ(c1,c1,c2)=φ(c2,c1,c1)=c2\varphi(c_{1},c_{1},c_{2})=\varphi(c_{2},c_{1},c_{1})=c_{2} for any c1,c2Hic_{1},c_{2}\in H_{i} for every i[k]i\in[k].

of Theorem 2.6.

(1) Let 𝒫\mathcal{P} be an instance of #p𝖢𝖲𝖯(=)\#_{p}\mathsf{CSP}(\mathcal{H}^{=}). The goal is to eliminate all equality relations =Hi=_{H_{i}} for each domain HiH_{i}, where i[k]i\in[k]. To achieve this, we apply a straightforward procedure: For every constraint of the form =Hi(u,v)=_{H_{i}}(u,v) in 𝒫\mathcal{P}, we remove it from 𝒫\mathcal{P} and replace every occurrence of vv with uu.

The resulting problem instance, denoted as 𝒫\mathcal{P}^{*}, belongs to #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}). This reduction can clearly be executed in polynomial time. Additionally, although the set of solutions to 𝒫\mathcal{P}^{*} differs from the set of solutions to 𝒫\mathcal{P} (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 H={H}i[k]H=\{H\}_{{i\in[k]}}, where Hi={ai,1,,ai,i}H_{i}=\{a_{i,1},...,a_{i,\ell_{i}}\}, and let 𝒬={(φ1(a1,1),,,φ1(a1,1),,,φk(ak,1,,,φk(ak,k))φ𝖧𝗈𝗆(,)}\mathcal{Q}=\{(\varphi_{1}(a_{1,1}),\dots,,\varphi_{1}(a_{1,\ell_{1}}),,\dots,\varphi_{k}(a_{k,1},,\dots,\varphi_{k}(a_{k,\ell_{k}}))\mid\varphi\in\mathsf{Hom}(\mathcal{H},\mathcal{H})\} 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 \mathcal{H} has =H=_{H} and 𝒬\mathcal{Q} as its predicates.

Let 𝒫=(V;𝒞)\mathcal{P}=(V;\mathcal{C}) be an instance of #p𝖢𝖲𝖯(𝖼)\#_{p}\mathsf{CSP}(\mathcal{H}^{\mathsf{c}}). We construct an instance 𝒫=(V,𝒞)\mathcal{P}^{\prime}=(V^{\prime},\mathcal{C}^{\prime}) of #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}) as follows.

  • V=Vi[k]{vai,j|ai,jHi}V^{\prime}=V\cup\bigcup_{i\in[k]}\{v_{a_{i,j}}|a_{i,j}\in H_{i}\};

  • 𝒞\mathcal{C}^{\prime} consists of three parts: {C=𝐱,𝒞σ}\{C=\langle\mathbf{x},\mathcal{R}\rangle\in\mathcal{C}\mid\mathcal{R}\in\sigma\}, {(va1,,van),𝒬}\{\langle(v_{a_{1}},\dots,v_{a_{n}}),\mathcal{Q}\rangle\}, and{(x,vai,j),=Hi(x),CHi,ai,j𝒞}\{\langle(x,v_{a_{i,j}}),=_{H_{i}}\rangle\mid\langle(x),C_{H_{i},a_{i,j}}\rangle\in\mathcal{C}\}.

The number of solutions of 𝒫\mathcal{P} equals the number of solutions φ\varphi of 𝒫\mathcal{P}^{\prime} such that φi(vai,j)=ai,j\varphi_{i}(v_{a_{i,j}})=a_{i,j} for all ai,jHia_{i,j}\in H_{i} where i[j],j[i]i\in[j],j\in[\ell_{i}]. Let UU be the set of all such solutions of 𝒫\mathcal{P}^{\prime} and T=|U|T=|U|. Then TT can be computed in two stages.

Let again 𝖯𝖺𝗋𝗍(H)\mathsf{Part}(H) be the poset of partitions of H={Hi}i[k]H=\{H_{i}\}_{{i\in[k]}}. Note that each partition consists of collection of partitions as θ={θi}i[k]\theta=\{\theta_{i}\}_{{i\in[k]}} where each θi\theta_{i} is a partition for HiH_{i}. For every partition θ𝖯𝖺𝗋𝗍(H)\theta\in\mathsf{Part}(H) we define 𝒫θ\mathcal{P}^{\prime}_{\theta} as the instance (V,𝒞θ)(V^{\prime},\mathcal{C}_{\theta}), where

𝒞θ=𝒞{(vai,j,vai,j),=Hiai,j,ai,j}\mathcal{C}_{\theta}=\mathcal{C}^{\prime}\cup\{\langle(v_{a_{i,j}},v_{a_{i,j^{\prime}}}),=_{H_{i}}\rangle\mid a_{i,j},a_{i,j^{\prime}}\}

belong to the same class of θi}\theta_{i}\}). Note that if φ\varphi is a solution of 𝒫\mathcal{P}^{\prime}, then φ\varphi is a solution of 𝒫θ\mathcal{P}^{\prime}_{\theta} if and only if φi(vai,j)=φi(vai,j)\varphi_{i}(v_{a_{i,j}})=\varphi_{i}(v_{a_{i,j^{\prime}}}) for every ai,j,ai,ja_{i,j},a_{i,j^{\prime}} from the same class of θi\theta_{i}. Let us denote by M(θ)M(\theta) the number of solutions of 𝒫θ\mathcal{P}^{\prime}_{\theta}. The number M(θ)M(\theta) can be computed using the oracle #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}), since we assume that all =Hi=_{H_{i}}’s and 𝒬\mathcal{Q} are predicates of \mathcal{H}.

Next, we find the number of solutions φ\varphi of 𝒫\mathcal{P}^{\prime} that assign vai,jv_{a_{i,j}}, ai,jHia_{i,j}\in H_{i}, pairwise different values. Let WW be the set of all such solutions. Let us denote by N(θ)N(\theta) the number of all solutions φ\varphi of 𝒫θ\mathcal{P}^{\prime}_{\theta} such that φi(vai,j)=φi(vai,j)\varphi_{i}(v_{a_{i,j}})=\varphi_{i}(v_{a_{i,j^{\prime}}}) if and only if ai,j,ai,ja_{i,j},a_{i,j^{\prime}} belong to the same class of θi\theta_{i}. In particular, N(0¯)=|W|N({\underline{0}})=|W|. The number N(0¯)N({\underline{0}}) can be obtained using the Möbius inversion formula for the poset 𝖯𝖺𝗋𝗍(H)\mathsf{Part}(H). Let w:Hw:H\rightarrow\mathbb{Z} be Möbius-inversion function. Also, observe that for any θ𝖯𝖺𝗋𝗍(H)\theta\in\mathsf{Part}(H)

M(θ)=ηθN(η).M(\theta)=\sum_{\eta\geq\theta}N(\eta).

Therefore,

N(0¯)=θ𝖯𝖺𝗋𝗍(H)w(θ)M(θ).N({\underline{0}})=\sum_{\theta\in\mathsf{Part}(H)}w(\theta)M(\theta).

Thus N(0¯)N({\underline{0}}) can be found through a constant number of calls to #p𝖢𝖲𝖯()\#_{p}\mathsf{CSP}(\mathcal{H}).

Now, we express TT via N(0¯)N({\underline{0}}). Let G=𝖠𝗎𝗍()G=\mathsf{Aut}(\mathcal{H}) be the automorphism group of \mathcal{H}. We show that W={gφ|gG,φU}W=\{g\circ\varphi|g\in G,\varphi\in U\}. For every solution φ\varphi in UU and every gGg\in G, gφg\circ\varphi is also a solution of 𝒫\mathcal{P}^{\prime}. Moreover, since gg is one-to-one, gφg\circ\varphi is in WW. Conversely, for every ψW\psi\in W, there exists some gGg\in G such that g(a)=ψ(va)g(a)=\psi(v_{a}), aHa\in H. Note that g1Gg^{-1}\in G implies φ=g1ψU\varphi=g^{-1}\circ\psi\in U, which witnesses that ψ=gφ\psi=g\circ\varphi is of the required form. Finally, for every φ,φU\varphi,\varphi^{\prime}\in U and every g,gGg,g^{\prime}\in G, if φ|{va|aH}φ|{va|aH}\varphi|_{\{v_{a}|a\in H\}}\neq\varphi^{\prime}|_{\{v_{a}|a\in H\}} or ggg\neq g^{\prime} then gφgφg\circ\varphi\neq g^{\prime}\circ\varphi^{\prime}. Thus, N(0¯)=|G|TN({\underline{0}})=|G|\cdot T. Since \mathcal{H} is pp-rigid, |G|0(modp)|G|\not\equiv 0\pmod{p}. Therefore T|G|1N(0¯)(modp)T\equiv|G|^{-1}\cdot N({\underline{0}})\pmod{p}. ∎