The Complexity of the Counting Constraint
Satisfaction Problem
ANDREI A. BULATOV
Simon Fraser University
The Counting Constraint Satisfaction Problem (#CSP(H)) over a finite relational structure H
can be expressed as follows: given a relational structure G over the same vocabulary, determine
the number of homomorphisms from G to H. In this paper we characterize relational structures
H for which #CSP(H) can be solved in polynomial time and prove that for all other structures
the problem is #P-complete.
Categories and Subject Descriptors: F.4.1 [Mathematical Logic and Formal Languages]: Mathematical Logic—
Logic and constraint programming; G.2.1 [Discrete Mathematics]: Combinatorics—Combinatorial algorithms;
F.1.3 [Computation by Abstract Devices]: Complexity Measures and Classes—Reducibility and completeness
General Terms: Algorithms, Theory
Additional Key Words and Phrases: Constraint Satisfaction problem, counting problems, complexity, dichotomy theorem, homomorphism problem
1.
INTRODUCTION
In the Counting Constraint Satisfaction Problem, #CSP(H), over a finite relational structure H the objective is, given a finite relational structure G, to compute the number of
homomorphisms from G to H. Various particular cases of the #CSP arise and have been
extensively studied in a wide range of areas from logic and graph theory [Bubley et al.
1999; Creignou and Hermann 1996; Dyer and Greenhill 2000; Greenhill 2000; Hunt III
et al. 1998; Linial 1986; Provan and Ball 1983; Valiant 1979a; 1979b], to artificial intelligence [Orponen 1990; Roth 1996], to statistical physics [Brightwell and Winkler 1999;
Burton and Steif 1994; Lebowitz and Gallavotti 1971]. In different areas this problem
often appears in different equivalent forms: (1) the problem of finding the number of models of a conjunctive formula, (2) the problem of computing the size (number of tuples) of
the evaluation Q(D) of a conjunctive query (without projection) Q on a database D and
also (3) the problem of counting the number of assignments to a set of variables subject to
specified constraints.
Since the seminal papers [Schaefer 1978; Feder and Vardi 1998], the complexity of the
decision counterpart of #CSP, the Constraint Satisfaction Problem or CSP for short, has
been an object of intensive study. The ultimate goal of that research direction is to classify
finite relational structures with respect to the complexity of the corresponding CSP. We
shall refer to this research problem as the classification problem. A number of significant
results have been obtained, see e.g. [Schaefer 1978; Feder and Vardi 1998; Bulatov 2006b;
Permission to make digital/hard copy of all or part of this material without fee for personal or classroom use
provided that the copies are not made or distributed for profit or commercial advantage, the ACM copyright/server
notice, the title of the publication, and its date appear, and notice is given that copying is by permission of the
ACM, Inc. To copy otherwise, to republish, to post on servers, or to redistribute to lists requires prior specific
permission and/or a fee.
c 20YY ACM 0004-5411/YY/00-0001 $5.00
⃝
Journal of the ACM, Vol. V, No. N, 20YY, Pages 1–0??.
2
·
Andrei A. Bulatov
2003; Barto et al. 2008; Barto 2011], but a full classification is far from being completed.
Although the classification problem for the general #CSP has been tackled for the first
time very recently, a massive amount of work has been done in the study of the complexity of various particular counting CSPs. These particular problems include classical
combinatorial problems such as #C LIQUE , G RAPH R ELIABILITY, A NTICHAIN , P ERMA NENT etc. [Linial 1986; Provan and Ball 1983; Valiant 1979a; 1979b] expressible in the
form of #CSP; the counting S ATISFIABILITY and G ENERALIZED S ATISFIABILITY problems (in these problems the objective is to find the number of satisfying assignments to
a propositional formula) [Creignou and Hermann 1996; Roth 1996] which correspond to
#CSP(H) for 2-element structures H, counting the number of solution of equations over
finite semigroups [Nordh and Jonsson 2004; Klı́ma et al. 2006] and many others.
However, the main focus of research in this area has been the #H -C OLORING problem and its variants. In the #H -C OLORING problem the aim is to find the number of
homomorphisms from a given graph G to the fixed graph H. Thus, it is equivalent to
#CSP(H) where H is a graph. Dyer and Greenhill [Dyer and Greenhill 2000] proved
that, for every undirected graph H, its associated #H -C OLORING problem is either in FP
(we shall call such problems tractable) or is #P-complete. They also provided a complete
characterization of the tractable problems. This result has been extended to the counting
L IST #H -C OLORING problem [Donner 1992; Diaz et al. 2001], which allows additional
restrictions on possible images of a node. Recently, Dyer, Goldberg, and Paterson [Dyer
et al. 2007] obtained a similar classification for directed acyclic graphs. Furthermore, some
other variants of the #H -C OLORING problem for undirected graphs have been intensively
studied during the last few years [Diaz et al. 2004; 2005]. Another direction in this area
is the study of problems with restricted input, that is subproblems of the #H -C OLORING
problem in which the input graph G must be planar [Hunt III et al. 1998; Vadhan 2001], a
partial k-tree [Diaz et al. 2002], sparse or of low degree [Greenhill 2000; Hell and Nešetřil
2004], etc. Finally, we should mention the approach to counting problems using approximation and randomized algorithms, see e.g. [Jerrum and Sinclair 1996; Dyer et al. 2003;
Dyer et al. 2002; Dyer et al. 2010].
The counting CSP admits various generalizations. In one of them, Weighted #CSP every
tuple from relations is assigned a weight that is used to compute weights of mappings from
one relational structure to another, and the problem is to find the sum of the weights of
all mappings [Dyer et al. 2009]. A particular case of the Weighted #CSP, in which only
one binary relation is allowed, is often referred to as partition functions [Lovász 2006;
Freedman et al. 2007]. Partition functons are widely used in statistical phisics [Brightwell
and Winkler 1999; Burton and Steif 1994; Lebowitz and Gallavotti 1971]. Recently, further
generalizations of the counting CSPs attracted considerable attention in connection with
the study of holographic reductions, see e.g. [Cai et al. 2008; Cai and Lu 2011].
In [Bulatov and Dalmau 2007] we started a systematic study of the classification problem for the general #CSP. The main approach chosen was the algebraic approach which
has proved to be quite useful in the study of the decision CSP [Jeavons 1998; Jeavons et al.
1998; Bulatov 2003; 2006b; 2011; Barto et al. 2008; Barto 2011]. This approach uses
invariance properties of predicates definable in relational structures. Invariance properties
are usually expressed as polymorphisms of the predicates, that is (multi-ary) operations on
the universe of the relational structure compatible with the predicates.
In [Bulatov and Dalmau 2007], we proved that if #CSP(H) is tractable, then H has
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
3
a Mal’tsev polymorphism, that is a ternary operation m(x, y, z) satisfying the identities
m(x, y, y) = m(y, y, x) = x. Another observation was that the congruences, i.e. the
definable equivalence relations, of H play a very important role. In particular, these results
allowed us to come up with a simple proof of the result of [Dyer and Greenhill 2000]1 . In
[Bulatov and Grohe 2005], another necessary condition for the tractability of #CSP(H)
was identified. It imposes certain restrictions onto possible congruences of H, in terms of
cardinalities of their equivalence classes.
In this paper, after giving general definitions (Sections 2.1 and 2.2) and introducing the
basics of the algebraic approach (Sections 2.3, 2.4 and 2.5), we go deeper into the structure
of congruence lattices of relational structures with a Mal’tsev polymorphism (Sections 3.1
and 3.3), its connections with types of prime quotients (Section 3.2), and the structure of
relations with a Mal’tsev polymorphism (Section 3.4). In Section 4 we identify two more
conditions, again expressed in terms of properties of congruences, that are satisfied by any
structure that gives rise to a tractable problem. Then, in Section 5, several observations
are made in preparation to introducing an algorithm solving the problem #CSP(H) for
every relational structure H satisfying all the conditions obtained. The algorithm is then
described in details in Section 6. Thus, we completely solve the classification problem
for the general counting CSP. Finally, in Section 7 we compare our result with a recent
result of [Dyer et al. 2007] classifying the complexity of the #H -C OLORING problem for
directed acyclic graphs.
We intensively use methods and results from a number of areas of algebra: lattice theory,
tame congruence theory, commutator theory and ring theory. To make the paper available
for a wider audience we avoid excessive use of algebraic terminology. In spite of that,
some parts of the paper, Section 4 and especially proofs, may require from the reader some
familiarity with basic algebraic objects and ideas. The keen reader is referred to textbooks
[Burris and Sankappanavar 1981; Freese and McKenzie 1987; Grätzer 2003; Hobby and
McKenzie 1988]. The reader should be aware that to avoid yet another layer of objects
we use algebraic terminology for relational structures, while in the algebraic literature the
same concepts are used for “dual” objects, universal algebras.
2.
PRELIMINARIES
2.1
Relational structures and homomorphisms
Our notation concerning relations and relational structures is fairly standard. Let [n] denote the set {1, . . . , n}. The set of all n-tuples of elements from a set H is denoted by
H n . We denote tuples of elements in boldface, for instance, a, and their components by
a[1], a[2], . . .. For a subset I = {i1 , . . . , ik } ⊆ [n] and an n-tuple a, by prI a we denote
the projection of a onto I, the k-tuple (a[i1 ], . . . , a[ik ]). For an n-ary relation R ⊆ H n ,
its projection onto I is defined to be prI R = {prI a | a ∈ R}. If Di = pri R for
i ∈ [n] we say that R is a subdirect product of D1 , . . . , Dn . If D1 = . . . = Dn = H
then R is said to be an n-th (or n-ary) subdirect power of H. For a = (a[1], . . . , a[n])
and b = (b[1], . . . , b[m]), (a, b) denotes the tuple (a[1], . . . , a[n], b[1], . . . , b[m]), while
⟨a, b⟩ denotes the pair of tuples. Sometimes we need more complicated indexing. Let
I, J ⊆ [n] be disjoint, I = {i1 , . . . , ik }, J = {j1 , . . . , jℓ }, and assume that i1 < . . . < ik
1 Note
that the hardness results [Dyer and Greenhill 2000] remain true even for graphs of degree at most 3, and
so are stronger than those in [Bulatov and Dalmau 2007].
Journal of the ACM, Vol. V, No. N, 20YY.
4
·
Andrei A. Bulatov
and j1 < . . . < jℓ . Let also a = (a[i1 ], . . . , a[ik ]) and b = (b[j1 ], . . . , b[jℓ ]). Then
(a, b) denotes the tuple c whose entries are indexed by elements of the set I ∪ J such that
c[i] = a[it ] if i = it ∈ I and c[i] = b[jt ] if i = jt ∈ J.
A vocabulary is a finite set of relational symbols R1 , . . . , Rn each of which has a fixed
arity. A relational structure over vocabulary R1 , . . . , Rn is a tuple H = (H; R1H , . . . , RnH )
such that A is a non-empty set, called the universe of H, and each RiH is a relation on
H having the same arity as the symbol Ri . Let G, H be relational structures over the
same vocabulary R1 , . . . , Rn . A homomorphism from G to H is a mapping φ : G → H
from the universe G of G (the instance) to the universe H of H (the template) such that,
for every relation RG (say, m-ary) of G and every tuple (a1 , . . . , am ) ∈ RG , we have
(φ(a1 ), . . . , φ(am )) ∈ RH .
A relation R is said to be primitive positive definable (pp-) in H, if it can be expressed
using the predicates RiH of H together with the binary equality predicate on H (denoted
∆H ), conjunction, and existential quantification. We use def(H) to denote the set of all
pp-definable relations.
Example 2.1. Let H be a 3-element structure with the universe {a, b, c} and one binary
disequality relation R. Structure H can be thought of as a 3-element complete graph. Then
the pp-formula
Q(x, y, z) = ∃t, u, v, w(R(t, x) ∧ R(t, y) ∧ R(t, z) ∧ R(u, v) ∧ R(v, w)
∧R(w, u) ∧ R(u, x) ∧ R(v, y) ∧ R(w, z))
defines the relation
a a b a b b a a c a c c b b c b c c
Q = a b a b a b a c a c a c b c b c b c ,
b a a b b a c a a c c a c b b c c b
consisting of all triples containing exactly 2 different elements from {a, b, c} (triples are
written vertically). Fig. 1(a) shows the graph built from the pp-formula; the vertices of the
graph represent variables and edges show on which variables the relation R is applied.
Another useful way to represent relation Q is to view it as the set of restriction of homomorphisms from the graph shown in Fig. 1(b) to H, where homomorphisms are restricted
to {x, y, z}. Observe that this connection between pp-definitions and restrictions of homomorphisms is rather general.
u
Q
w
Q
Q
u
w
Q
v
a
v
Q
Q
x
y
Q
Q
Q
z
x
y
b
z
t
t
(b)
(a)
Fig. 1.
Journal of the ACM, Vol. V, No. N, 20YY.
c
The Complexity of the Counting CSP
2.2
·
5
Constraint Satisfaction Problem
The counting constraint satisfaction problem can be formulated in several ways (see Section 1). We use the model theoretic form of this problem.
Definition 2.2. Let H be a class of relational structures. In the counting constraint
satisfaction problem associated with H (#CSP(H)), the objective is, given a structure
H ∈ H and a structure G, to compute the number of homomorphisms from G to H. We
will refer to this problem as to a uniform #CSP.
If H consists of a single structure H, then we write #CSP(H) instead of CSP({H})
and refer to such problem as a non-uniform homomorphism problem, because the inputs
are just source structures.
Example 2.3 (#H -C OLORING, [Dyer and Greenhill 2000; Hell and Nešetřil 1990; Levin 1973]).
A graph H is a structure with a vocabulary consisting of one binary symbol R. Then
#CSP(H) is widely known as the #H -C OLORING Problem, in which the objective is to
compute the number of homomorphisms from a given graph into H.
Example 2.4 (#3-SAT, [Creignou and Hermann 1996; Creignou et al. 2001; Valiant 1979a; 1979b]).
An instance of the #3-SAT problem is specified by giving a propositional logic formula in
CNF each clause of which contains 3 literals, and asking how many assignments satisfy it.
Therefore, #3-SAT is equivalent to #CSP(S3 ), where S3 is the 2-element relational structure with the universe {0, 1} and the vocabulary R1 , . . . , R8 . Predicates R1S3 , . . . , R8S3 are
the 8 predicates expressible by 3-clauses.
Example 2.5 (Systems of linear equations). Let F be a finite field and let #L INEAR
E QUATIONS(F ) be the problem of finding the number of solutions to a system of linear equations over F . It is not hard to see that #L INEAR E QUATIONS(F ) is equivalent
to #CSP(L), where L is the class of relational structures with the universe F and the
relations corresponding to hyperplanes of finite-dimensional vector spaces over F .
In fact, #L INEAR E QUATIONS(F ) cannot be straightforwardly reduced to #CSP(L) in
polynomial time. The reason is that the representation of relations by linear equations is
much more concise than that by a list of tuples, see discussion after Example 2.6. However,
in this case a reduction to a problem in #CSP exists. It is carried out by first reducing
a system of linear equations to a system of equations each of which contains at most 3
variables; clearly, some new variables must be introduced at this step. Then such a system
is straightforwardly reduced to #CSP(L3 ), where L3 is the the relational structure from
L containing all ternary relations expressible by linear equations.
Example 2.6 (Equations over semigroups, [Nordh and Jonsson 2004; Klı́ma et al. 2006]).
Let S be a finite semigroup, that is, a set with a binary associative operation. An equation
over S is an expression of the form x1 · x2 · . . . · xm = y1 · y2 · . . . · ym where · is the semigroup operation, and xi , yj are either indeterminates or constants. Then #EQN∗S stands
for the problem of counting the number of solutions to a system of semigroup equations.
The problem #EQN∗S is equivalent to the problem #CSP(S) where S is the class of
structures with universe S and relations expressible as the set of solutions of a semigroup
equation.
In the last two examples, as well as for many other uniform problems, there is a minor
ambiguity concerning a representation of the input. We always assume that in uniform
problems the relations of the template are represented explicitly, by a list of tuples of the
Journal of the ACM, Vol. V, No. N, 20YY.
6
·
Andrei A. Bulatov
relation. In Examples 2.5, 2.6 such a representation is not the most natural one. However,
the class of relations admitting a succinct representation is rather limited (see, e.g. [Idziak
et al. 2007]), and thus such representations are unsuitable for the study of the general
problem.
Every counting CSP belongs to the class #P. However, the exact complexity of #CSP(H)
strongly depends on the structure H. We say that a relational structure H is #-tractable if
#CSP(H) is solvable in polynomial time; H is #P-complete if #CSP(H) is #P-complete.
Note that all reductions used in this paper are Turing reductions. The research problem we
deal with in this paper is the following one.
P ROBLEM 1 ( CLASSIFICATION PROBLEM ). Characterize #-tractable and #P-complete
relational structures.
Example 2.7. (1) Dyer and Greenhill [2000] proved that if H is an undirected graph
then #H -C OLORING can be solved in polynomial time if and only if every connected
component of H is either a complete bipartite graph, or a complete graph with all loops
present, or a single vertex. Otherwise the problem is #P-complete.
(2) A 2-element relational structure H is #-tractable if and only if every predicate of H
can be represented by a system of linear equations over the 2-element field [Creignou and
Hermann 1996; Creignou et al. 2001]. Otherwise, H is #P-complete.
(3) #CSP(L3 ) is solvable in polynomial time.
(4) The problem #EQN∗S is solvable in polynomial time if and only if S is a direct product
of a uniformly inflated Abelian group, inflated left-zero semigroup, and an inflated rightzero semigroup. Otherwise #EQN∗S is #P-complete. For details see [Klı́ma et al. 2006].
2.3 Polymorphisms, Algebras and Complexity
Any operation on a set H can be extended in a standard way to an operation on tuples over
H, as follows. For any (m-ary) operation f , and any collection of tuples a1 , . . . , am ∈ H n ,
define f (a1 , . . . , am ) to be (f (a1 [1], . . . , am [1]), . . . , f (a1 [n], . . . , am [n])), that is, f acts
on H n component-wise. Then f preserves an n-ary relation R (or R is invariant under f ,
or f is a polymorphism of R) if for any a1 , . . . , am ∈ R the tuple f (a1 , . . . , am ) belongs to
R. For a given set of operations, C, the set of all relations invariant under every operation
from C is denoted by Inv(C). For a relational structure H we use Pol(H) to denote the set
of all operations preserving every relation of H.
Example 2.8. Let R be the solution space of a system of linear equations over a field F .
Then the operation m(x, y, z) = x − y + z is a polymorphism of R. Indeed, let A · x = b
be the system defining R, and x, y, z ∈ R. Then
A · m(x, y, z) = A · (x − y + z) = A · x − A · y + A · z = b.
In fact, the converse can also be shown: if R is invariant under m, where m is defined in
a certain finite field F then it is the solution space of some system of linear equations over
F.
The following proposition links together polymorphisms and pp-definability of relations.
P ROPOSITION 2.9 [G EIGER 1968; B ODNARCHUK ET AL . 1969]. Let H be a finite
structure, and let R ⊆ H n be a non-empty relation. Then R is preserved by all polymorphisms of H if and only if R is pp-definable in H.
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
7
The connection between polymorphisms and the complexity of counting CSPs is provided by the following result.
P ROPOSITION 2.10 [B ULATOV AND DALMAU 2007]. Let H1 and H2 be relational
structures with the same universe. If Pol(H1 ) ⊆ Pol(H2 ) then #CSP(H2 ) is polynomial
time reducible to #CSP(H1 ).
Proposition 2.10 amounts to saying that all the information about the complexity of #CSP(H)
can be extracted from the family of polymorphisms of H. Sets of polymorphisms often
provide a more convenient and concise way of describing a class of constraint satisfaction problems. For example, in [Bulatov and Dalmau 2007], we used polymorphisms to
identify some conditions necessary for the #-tractability of a relational structure. A ternary
operation m(x, y, z) on a set H is said to be Mal’tsev if m(x, y, y) = m(y, y, x) = x for
all x, y ∈ H.
P ROPOSITION 2.11 [B ULATOV AND DALMAU 2007]. If H is a relational structure
which is invariant under no Mal’tsev operation then H is #P-complete.
Notice that if H has a Mal’tsev polymorphism then the decision CSP corresponding to H
can be solved in polynomial time [Bulatov 2002b; Bulatov and Dalmau 2006].
Example 2.12. Mal’tsev operation m(x, y, z) is a polymorphism of graph H1 shown
in Fig. 2, where m is given by
m(i1 j1 , i2 j2 , i3 j3 ) = ij,
i = i1 [j = j1 ] unless i1 = i2 [j1 = j2 ], in this case i = i3 [j = j3 ].
Graph H2 has no Mal’tsev polymorphisms. Indeed, if some f (x, y, z) is a Mal’tsev
operation, then
(( ) ( ) ( )) ( )
a
a
b
b
f
,
,
=
̸∈ E(H2 ).
c
d
d
c
01
a
11
c
b
00
10
d
H2
H1
Fig. 2.
In our algebraic definitions we follow [Burris and Sankappanavar 1981; McKenzie et al.
1987]. For algebraic notions and results concerning the decision CSP the reader is referred
to [Bulatov and Jeavons 2001; Bulatov et al. 2005].
A (universal) algebra is an ordered pair A = (A, F ) where A is a non-empty set and F
is a family of finitary operations on A. The set A is called the universe of A, operations
from F are called basic. An algebra with a finite universe is referred to as a finite algebra,
while the set of basic operations needs not to be finite.
Journal of the ACM, Vol. V, No. N, 20YY.
8
·
Andrei A. Bulatov
Any relational structure H with universe H can be converted into an algebra Alg(H) =
(H; Pol(H)). Conversely, every algebra A = (A; F ) corresponds to a class of structures
Str(A) with universe A and relations from Inv(F ). Using this correspondence we can
define #-tractable algebras. An algebra A is said to be #-tractable if every structure H ∈
Str(A) is #-tractable; it is said to be #P-complete if some H ∈ Str(A) is #P-complete.
We shall express the complexity of #CSP(H) in terms of Alg(H). For example, if an
algebra has a Mal’tsev operation, it is called a Mal’tsev algebra. Proposition 2.11 implies
that if #CSP(H) is tractable then Alg(H) is Mal’tsev.
2.4 Subalgebras and congruences
We shall use various constructions on algebras, but two of these constructions, subalgebras
and congruences, can be defined for relational structures, and are very useful and illustrative in this context.
A subalgebra of a structure H = (H; R1H , . . . , RkH ) is a unary relation pp-definable
in H, and a congruence of H is an equivalence relation pp-definable in H. For a subset
B ⊆ H, the substructure of H induced by B is defined to be H = (B; R1H , . . . , RkH ),
where RiH
B
B
B
B
= RiH ∩ B mi , Ri is mi -ary. For an equivalence relation α and a ∈ H,
the class of α containing a is denoted by aα and the set of all classes of α by H/α.
The quotient structure H/α is defined to be H/α = (H/α; R1H /α, . . . , RkH /α), where
α
H
RiH /α = {(aα
1 , . . . , ami ) | (a1 , . . . , ami ) ∈ Ri }.
Example 2.13. Let H = (V, E) be a digraph without sources and sinks, i.e. the indegree and out-degree of each vertex is non-zero. We define two binary relations, ξH
and ζH , on the vertex set H of H: ⟨a, b⟩ ∈ ξH if and only if a, b have a common outneighbour and ⟨a, b⟩ ∈ ζH if and only if a, b have a common in-neighbour; in other words,
ξH = {⟨a, b⟩ | (a, c), (b, c) ∈ E for a certain c ∈ H}, ζH = {⟨a, b⟩ | (c, a), (c, b) ∈ E for
a certain c ∈ H}. Relations ξH and ζH are pp-definable in H, as the following pp-formulas
show
ξH (x, y) = ∃z(E(x, z) ∧ E(y, z)),
ζH (x, y) = ∃z(E(z, x) ∧ E(z, y)).
In general, ξH , ζH are reflexive and symmetric relations. However, if H has a Mal’tsev
polymorphism m, they are also transitive. Indeed, suppose that ⟨a, b⟩ ∈ ξH , d ∈ H is their
common out-neighbour, and c is an out-neighbour of a. If c is not an out-neighbour of b,
then H contains H2 (see Fig. 2) as a subgraph and (b, c) is not an edge, which contradicts
the assumption that H has a Mal’tsev polymorphism. Therefore, the out-neighbourhoods
of a, b are equal whenever ⟨a, b⟩ ∈ ξH , which implies transitivity. Thus, ξH , ζH are congruences of H.
For the graph H3 shown in Fig. 3, the ξH3 -classes are {a, b, c}, {d, e}, {f, g}, {h}, {i},
and the ζH3 -classes are {a, b, d}, {c, e}, {f }, {g}, {h, i}.
P ROPOSITION 2.14 [B ULATOV AND DALMAU 2007]. Let H be a relational structure,
B and let α ibe a subalgebra and a congruence respectively.
(1) If H is #-tractable then so are H and H/α.
B
(2) If H or H/α is #P-complete then H is #P-complete.
B
In a similar way we define congruences of relations. Let R ∈ def(H) be an n-ary
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
9
g
f
a
·
b
c
h
e
d
H3
i
Fig. 3.
relation. It can be viewed as a subalgebra of an nth direct power of H. A congruence on R
is a 2n-ary relation Q ∈ def(H) such that pr{1,...,n} Q = pr{n+1,...,2n} Q = R, and, if Q is
treated as a binary relation on R, it is an equivalence relation. The set of all congruence of
relational structure H will be denoted by Con(H). An important example of a congruence
on R is the following. Let α be a congruence of H and denote by αn the relation on R
given by ⟨a, b⟩ ∈ αn if and only if ⟨a[i], b[i]⟩ ∈ α for all i ∈ [n]. As the following
pp-definition shows, αn is a congruence of R
αn (x1 , . . . , xn ; y1 , . . . , yn ) = R(x1 , . . . , xn ) ∧ R(y1 , . . . , yn ) ∧
n
∧
α(xi , yi ).
i=1
Example 2.15. We give an example of a nontrivial congruence of a ternary relation.
Let us reconsider relation Q on the 3-element set {a, b, c}, whose pp-definition is given in
Example 2.1. We show that the binary relation T on Q that relates triples with the same
set of entries is a congruence of Q. This can be done in two ways: we may verify that the
following pp-formula defines exactly that (6-ary on {a, b, c}) relation
T (x, y, z, x′ , y ′ , z ′ ) = ∃t, u, v, w, u′ , v ′ , w′ (R(t, x) ∧ R(t, y) ∧ R(t, z) ∧ R(u, v)
∧R(v, w) ∧ R(w, u) ∧ R(u, x) ∧ R(v, y) ∧ R(w, z) ∧ R(t, x′ ) ∧ R(t, y ′ ) ∧ R(t, z ′ )
∧R(u′ , v ′ ) ∧ R(v ′ , w′ ) ∧ R(w′ , u′ ) ∧ R(u′ , x′ ) ∧ R(v ′ , y ′ ) ∧ R(w′ , z ′ ),
or we may observe that the T is formed by restrictions of homomorphisms from the graph
shown in Fig. 4 to H onto {x, y, z, x′ , y ′ , z ′ }.
x’
z
a
y’
y
b
c
H
z’
x
Fig. 4.
The existence of a Mal’tsev polymorphism provides a necessary condition for the #tractability of a relational structure. However, it is not a sufficient condition, as Example 2.17 below shows. In Section 4 we prove two other conditions that are also necessary.
A particular case of one of them is that proved in [Bulatov and Grohe 2005].
Let α, β be congruences of H, and let
Journal of the ACM, Vol. V, No. N, 20YY.
10
·
Andrei A. Bulatov
A1 , . . . , Ak and B1 , . . . , Bℓ be the α- and β-classes respectively. Then M (α, β) denotes
the k × ℓ-matrix (mij ), where mij = |Ai ∩ Bj |.
P ROPOSITION 2.16 [B ULATOV AND G ROHE 2004]. Let H be a relational structure,
and let α, β be congruences of H. If rank(M (α, β)) > k, where k is the number of classes
of the smallest congruence containing both α and β, then #CSP(H) is #P-complete.
Classes of the smallest congruence γ containing both α and β can be easily represented
in terms of matrix M (α, β): This matrix (as well as any other matrix) after suitable permutations of rows and columns can be partitioned into a collection of rectangular cells sitting
on the diagonal, so that all entries outside the cells equal zero. The finest partition of this
kind gives the classes of γ.
Example 2.17. Let H be the graph H3 shown in Fig. 3, α = ξH3 and β = ζH3 (see
Example 2.13). We have A1 = {a, b, c}, A2 = {d, e}, A3 = {f, g}, A4 = {h}, A5 = {i},
and B1 = {a, b, d}, B2 = {c, e}, B3 = {f }, B4 = {g}, B5 = {h, i}. Thus
2 1 0 0 0
1 1 0 0 0
M (α, β) =
0 0 1 1 0 .
0 0 0 0 1
0 0 0 0 1
Graph H3 is similar to the graph considered in [Bulatov and Dalmau 2007, Example 5]. In
particular it can be straightforwardly verified that it has the same Mal’tsev polymorphism.
However, by Proposition 2.16, the problem #CSP(H3 ) is #P-complete.
2.5
Varieties and Complexity
It will be convenient for us to jump back and forth between model-theoretic and algebraic
views to the CSP. The language of relational structures is more convenient when describing
algorithms. On the other hand, standard algebraic constructions allow us to strengthen necessary conditions for #-tractability, and eventually formulate a criterion for #-tractability.
Definition 2.18. (1) Let A = (A; F ) be an algebra. The k-th direct power of A is the
algebra Ak = (Ak ; F ) where we treat each (say, n-ary) operation f ∈ F as acting on Ak
component-wise.
(2) Let A = (A; F ) be an algebra, and let B be a subset of A such that, for any (say,
n-ary) f ∈ F , and for any b1 , . . . , bn ∈ B, we have f (b1 , . . . , bn ) ∈ B. Then the algebra
B = (B; F ), where F consists of restrictions of operations f ∈ F onto B, is called a
B
B
subalgebra of A.
(3) Let A1 = (A1 ; F1 ) and A2 = (A2 ; F2 ) such that F1 = {fi1 | i ∈ I}, F2 = {fi2 |
i ∈ I}, and fi1 , fi2 are of the same arity ni , i ∈ I. A mapping φ : A1 → A2 is called
a homomorphism from A1 to A2 if φfi1 (a1 , . . . , ani ) = fi2 (φ(a1 ), . . . , φ(ani )) holds for
all i ∈ I and all a1 , . . . , ani ∈ A1 . If the mapping φ is onto then A2 is said to be a
homomorphic image of A1 .
A common way of constructing homomorphic images is through congruences and quotient algebras. A congruence of an algebra A = (A; F ) is an equivalence relation on
A invariant under all operations from F . Let θ be a congruence of A. The algebra
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
11
A/θ = (A/θ; F/θ), where F/θ = {f /θ | f ∈ F } and f /θ is given by f /θ(aθ1 , . . . , aθn ) =
(f (a1 , . . . , an ))θ is called a quotient algebra. Observe that an equivalence relation is a
congruence of a structure H if and only if it is a congruence of Alg(H).
T HEOREM 2.19 [B ULATOV AND DALMAU 2007]. Let A = (A; F ) be a finite algebra. Then
(1) if A is #-tractable then so is every subalgebra, homomorphic image, and direct power
of A.
(2) if A has a #P-complete subalgebra, homomorphic image, or direct power, then A is
#P-complete.
For an algebra A the class of algebras that are homomorphic images of subalgebras of
direct powers of A is called the variety generated by A, and is denoted by var(A). An
operation f on the universe of an algebra A = (A; F ) that preserves all relations invariant
under F is called a term operation of A. Every term operation of A can be obtained from
operations of F by means of superposition.
An operation f on a set A is said to be idempotent if the equality f (x, . . . , x) = x
holds for all x ∈ A. An algebra all of whose term operations are idempotent is said to
be idempotent. Let Kh denote the constant relation {(h)}, containing only one tuple,
namely (h), and let Hid denote the expansion of a relational structure H by unary relations
Kh , h ∈ H. It can be easily seen that all polymorphisms of Hid are idempotent. We
will need the following simple observation about relational structures with idempotent
polymorphisms.
L EMMA 2.20. Let H be a relational structure whose polymorphisms are idempotent,
R ∈ def(H) an n-ary relation, α a congruence of R, and B an α-class. Then B is a
relation pp-definable in H.
P ROOF. Let a ∈ B. Since every polymorphism of H is idempotent, the constant relations Ka[i] , i ∈ [n], are pp-definable in H. Then
B(x1 , . . . , xn ) = ∃y1 , . . . , yn (R(x1 , . . . , xn ) ∧ α(x1 , . . . , xn ; y1 , . . . , yn )
∧Ka[1] (y1 ) ∧ . . . ∧ Ka[n] (yn )).
The following theorem shows the connection between complexity and full idempotent
reducts.
T HEOREM 2.21 [B ULATOV AND DALMAU 2007]. A relational structure H is #-tractable [#P-complete] if and only if so is Hid .
If A is an idempotent algebra and the condition of Proposition 2.16 is true for every pair
of congruences of A then A is said to be congruence singular. If every finite algebra in
a variety is congruence singular then the variety is called congruence singular. We call
a relational structure H congruence singular if Alg(H) generates a congruence singular
variety. By Proposition 2.16 and Theorems 2.19, 2.21, every structure H that is not #Pcomplete is congruence singular. The main result of the paper is that this condition is
sufficient for #-tractability.
T HEOREM 2.22. A relational structure H [an algebra A], is #-tractable if and only if
Hid is congruence singular [Id(A) generates a congruence singular variety].
Journal of the ACM, Vol. V, No. N, 20YY.
12
·
Andrei A. Bulatov
Observe that the condition of having a Mal’tsev polymorphism (term operation) is not
included into the criterion. As we shall see later (Lemma 3.2) every congruence singular
structure has a Mal’tsev polymorphism.
We complete this section with a more combinatorial characterization of congruence singular relational structures. Let H be a relational structure, R a relation pp-definable in H,
and α, β, δ congruences of R such that δ ⊆ α, β. By M (R; α, β; δ) we denote the matrix
M (α, β) computed for R/δ . More precisely, let A1 , . . . , Ak and B1 , . . . , Bℓ be the α- and
β-classes respectively. Then M (R; α, β; δ) is the k × ℓ-matrix (mij ) where mij equals the
number of δ-classes in Ai ∩ Bj .
L EMMA 2.23. A relational structure H is congruence singular if and only if for any
relation R pp-definable in H and any congruences δ, α, β of R such that δ ≤ α, β, the
rank of the matrix M (R; α, β; δ) equals the number of classes in the smallest congruence
containing both α and β.
P ROOF. Let A = Alg(H). We show that for any finite algebra B from the variety
generated by A and congruences α, β of B there is a relation R pp-definable in H and
congruences δ, α′ , β ′ of R with δ ⊆ α, β such that M (α, β) = M (R; α′ , β ′ ; δ); and,
conversely, for any R, δ, α′ , β ′ , there are B and α, β satisfying the above equality.
Take B, α, and β. By the HSP-Theorem (see, e.g., [Burris and Sankappanavar 1981])
B is a homomorphic image of a subalgebra of (say, k-th) direct power of A. Let C denote
the subalgebra of the direct power, and let B be a homomorphic image of C, let φ be the
homomorphism, and let γ be the corresponding congruence of C, that is ⟨a, b⟩ ∈ γ if and
only if φ(a) = φ(b). The universe C of C can be viewed as a subset of H k — recall
that H is the universe of A — invariant under all polymorphisms of H. Thus C is a kary relation pp-definable in H. We choose R = C. Then the term operations of C are
the polymorphisms of H acting on R component-wise. Furthermore, γ is an equivalence
relation on C invariant under all operations of C, and therefore under all polymorphisms
of H. Hence γ is a congruence of R, and we set δ = γ. Finally, define α′ , β ′ as follows:
α′ = {⟨a, b⟩ ∈ R2 | ⟨φ(a), φ(b)⟩ ∈ α}, and β ′ = {⟨a, b⟩ ∈ R2 | ⟨φ(a), φ(b)⟩ ∈ β}.
Every α′ - or β ′ -class D corresponds to the α-, respectively, β-class φ(D) = {φ(a) | a ∈
D}, and this correspondence is one-to-one. The δ-classes inside D are also in a one-to-one
correspondence with the elements of φ(D). This implies the equality of the matrices.
Now take a k-ary relation R pp-definable in H and congruences δ, α′ , β ′ of R. First
we set C = (R; {f C | f ∈ Pol(H)}), where f C acts on k-tuples from R componentwise. Since R is invariant under all polymorphisms of H these operations are well-defined.
Algebra B can be defined as the quotient algebra C/δ , and congruences α, β as follows:
α = {⟨aδ , bδ ⟩ | ⟨a, b⟩ ∈ α′ } and β = {⟨aδ , bδ ⟩ | ⟨a, b⟩ ∈ β ′ }. As before, we have oneto one correspondences between α-, β- and α′ -, β ′ - classes, as well as, between δ-classes
and elements of B, which implies the result.
2.6 Outline of the proof
Since the hardness part of Theorem 2.22 follows from the previous result, we only need to
design an algorithm solving #CSP(H) whenever Hid is congruence singular.
The set of all congruences of structure H ordered by inclusion is denoted by Con(H),
and is called the congruence lattice of H (for more details see the next section). The least
element of Con(H) is the equality relation, denoted by ∆, and the greatest element is the
total relation, denoted by ▽. We start with choosing a chain ∆ = θ0 ≤ θ1 ≤ . . . ≤ θk = ▽
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
13
in Con(H). For an instance G of #CSP(H) and s ∈ {0, . . . , k}, let τ be a mapping from
G to H/θ . By Φ(G, H; τ ) we denote the set of homomorphisms φ from G to H (that is,
s
elements of Φ(G, H)) such that φ(g)θs = τ (g) (we say that φ agrees with τ ).
Obviously, if s = k then there is only one mapping τ : G → H/θ , as H/θ is 1-element
s
s
structure. So in this case Φ(G, H; τ ) = Φ(G, H). On the other hand, if s = 0 then any
homomorphism τ : G → H/θ is a homomorphism of G to H and thus |Φ(G, H; τ )| =
s
1. The algorithm reduces finding the number |Φ(G, H; τ )| for τ : G → H/θ to finding
s
|Φ(G, H; τi )| for τi : G → H/θ , i ∈ [r], for a small number r. As we shall see, r is
s−1
bounded from above by a linear polynomial in |G|. Since the depth of recursion depends
only on H, and therefore is constant, this gives a polynomial time algorithm for finding
|Φ(G, H)|.
In the next section we show that the chain ∆ = θ0 ≤ θ1 ≤ . . . ≤ θk = ▽ can be
chosen such that every interval θs−1 ≤ θs has one of the two types: Boolean or affine. The
reduction to lower level mappings mentioned above is carried out differently depending on
the type of the interval θs−1 ≤ θs .
If the type of θs−1 ≤ θs is Boolean then for any homomorphism τ : G → H/θ the
i
numbers |Φ(G, H; φ)| for homomorphisms φ : G → H/θ
that agree with τ can be
s−1
arranged into a multidimensional array of rank 1. The number |Φ(G, H; τ )| is then the sum
of all entries in this array, and can be found using linear dependencies between rows of this
array without finding all its entries.
If the type of θs−1 ≤ θs is affine then, for any homomorphism φ : G → H/θ
that
s−1
agrees with τ , the number |Φ(G, H; φ)| is the same. Therefore we only need to find the
number of homomorphisms φ : G → H/θ
agreeing with τ . This is done by a modifis−1
cation of the algorithm for the decision CSP from [Bulatov and Dalmau 2006].
3.
CONGRUENCE LATTICES AND THE STRUCTURE OF RELATIONS
3.1 Lattices and congruence lattices
In this section we look closer at the family of congruences of a relational structure H.
All definitions and results given here were originally introduced for algebras. As our algorithms are described in terms of relational structures, we reformulate them in terms of
structures, replacing congruences of algebras with congruences of structures, and term operations of an algebra with polymorphisms of a structure. However, the notions we arrive
to for a structure H are exactly the same as those defined for the algebra Alg(H).
The set of all congruences of structure H is denoted by Con(H). Let α, β ∈ Con(H).
The intersection of α and β is again a congruence of H and is denoted α ∧ β. As is well
known, the smallest equivalence relation containing both α and β is the transitive closure
of α ∪ β. It can be shown that this equivalence relation is a congruence of H, denoted
by α ∨ β. The set Con(H) together with the operations ∧ (meet) and ∨ (join) is called
the congruence lattice of H. The set Con(H) is naturally ordered by inclusion. The least
element of Con(H) is the equality relation, denoted by ∆, and the greatest element is the
total relation, denoted by ▽.
If R is a relation pp-definable in H, then Con(R) denotes the set of all congruences of
R. This set depends on H as well as on R, but usually H is clear from the context. The set
Con(R) is also a lattice.
Journal of the ACM, Vol. V, No. N, 20YY.
14
·
Andrei A. Bulatov
Lattices can as well be introduced in an abstract way, as a set along with operations ∧
and ∨ satisfying certain conditions, see [Grätzer 2003]. The structure of a lattice allows
one to define a partial order ≤ on L: a ≤ b if and only if a ∧ b = a, or, equivalently, a ≤ b
if and only if a ∨ b = b. Note that a ∧ b and a ∨ b are the greatest lower and the least upper
bound of a, b, respectively, in terms of this order.
We will deal with lattices of several particular types. A lattice L is said to be (a) modular
if, for any a, b, c ∈ L such that b ≤ a, the equality a ∧ (b ∨ c) = b ∨ (a ∧ c) holds; (b) meet
semi-distributive if, for any a, b, c ∈ L such that a∧b = a∧c, the equality a∧b = a∧(b∨c)
holds; (c) distributive if for any a, b, c ∈ L, the equality a∧(b∨c) = (a∧b)∨(a∧c) holds.
Modular and distributive lattices are very well studied, see, e.g., [Grätzer 2003, Ch. II,
IV]. We will use the following folklore observation: Every modular meet semidistributive
lattice is distributive (it is mentioned, for example, in [Jonsson and Rival 1971]2 ).
One particularly useful property of modular lattices is the following. A pair a, b of
elements from a lattice L is called a prime quotient, denoted a ≺ b, if a ≤ b and there is
no c ∈ L such that a ≤ c ≤ b and c ̸= a, b. Suppose a ≤ b. A sequence a = c0 ≺ c1 ≺
. . . ≺ ck = b is called a maximal chain from a to b. Observe that such a chain is maximal
in the sense that there are no other elements between the ci . Number k is called the length
of the chain.
P ROPOSITION 3.1 (T HE J ORDAN -H ÖLDER C HAIN C ONDITION , [G R ÄTZER 2003], T H . 1, C H . II.2).
For any two elements a ≤ b of a finite modular lattice, all maximal chains from a to b have
the same length.
For elements a, b of a lattice L such that a ≤ b, the interval [a, b] is the set of all c with
a ≤ c ≤ b. Intervals [a, b] and [c, d] are said to be perspective if b ∨ c = d, b ∧ c = a or
a ∨ d = b, a ∧ d = c (see Fig. 5(a)). Thus perspectivity is a binary relation on the set of
intervals of L. Two intervals that belong to the transitive closure of this relation are said to
be projective to each other.
1 1
0
0
0 1
1
0
d
1
0 1
0
c
01
01
join−irreducible
b 1
1
0
0
1 1
0
0
a 1
0
1
0
01
1
0 1
0
(a)
Fig. 5.
01
meet−irreducible
1
0
1
0 1
0
(b)
1
0
1
0 1
0
(c)
Perspective intervals [a, b] and [c, d] (a), join-irreducible (b), and meet-irreducible elements (c)
3.2 Congruence lattices and types of prime quotients
As usual, by ◦ we denote the product of binary relations: (a, b) ∈ R ◦ Q iff there is c such
that (a, c) ∈ R and (c, b) ∈ Q. If H has a Mal’tsev polymorphism, the set Con(H) cannot
be just an arbitrary collection of equivalence relations. In particular, any two members
α, β of Con(H) must be permutable, that is α ◦ β = β ◦ α. This means that, for any
2 In that paper the observation stated in a different but equivalent way:
The intersection of the varieties of modular
and meet semidistributive lattices is the variety of distributive lattices.
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
15
α-class A and any β-class B belonging the same α ∨ β-class, A ∩ B is non-empty Since
α ∨ β = α ◦ β ◦ α ◦ . . . (sufficiently many times), congruences α, β are permutable if and
only if α ◦ β = β ◦ α = α ∨ β.
L EMMA 3.2. If a relational structure H is congruence singular [an algebra A generates a congruence singular variety], then it has a Mal’tsev polymorphism [a Mal’tsev term
operation].
Therefore for any relation R pp-definable in H its congruence lattice Con(R) is modular.
P ROOF. By the well known result of Mal’tsev [Burris and Sankappanavar 1981, Theorem 12.1] an algebra A has a Mal’tsev term operation if and only if any two congruences
of any algebra in the variety generated by A are permutable. Therefore it suffices to prove
that if the variety generated by Alg(H) for a structure H is congruence singular then it is
congruence permutable.
Suppose H is congruence singular, B ∈ var(Alg(H)), and α, β ∈ Con(B). If α ⊆ β
or β ⊆ α then they are obviously permutable. If the congruences are incomparable then
rank(M (α, β)) = k where k is the number of α ∨ β-classes. If we group the rows and
columns of matrix M (α, β) according to the α ∨ β-classes, all the non-zero entries of
M (α, β) concentrate in rectangular blocks, the cells of the matrix. Although in general
cells can contain zero entries, the equality rank(M (α, β)) = k implies, in particular, that
all entries in a cell are non-zero. Therefore, for any a, b from the same α ∨ β-class, say,
a belongs to α-class A1 and β-class B1 , and b belongs to α-class A2 and β-class B2 , we
have A1 ∩ B2 ̸= ∅ and A2 ∩ B1 ̸= ∅, as the corresponding entries of M (α, β) must be
non-zero. Then ⟨a, b⟩ ∈ α ◦ β, as any c ∈ A1 ∩ B2 witnesses, and ⟨a, b⟩ ∈ β ◦ α, as any
d ∈ A2 ∩ B1 witnesses. Thus α ◦ β = β ◦ α = α ∨ β.
The second part of the lemma follows from the observation that Con(R) is the congruence lattice of certain algebra in the variety generated by Alg(H) and the fact that the
congruence lattice of a congruence permutable algebra is modular.
A pair of congruences ⟨α, β⟩ is said to be a prime quotient if they form a prime quotient
in the congruence lattice.
We shall use some notions and results of tame congruence theory [Hobby and McKenzie
1988]. Tame congruence theory is a tool to study a local structure of universal algebras
through certain properties of prime quotients of the congruence lattice. We apply this
theory to relational structures that give rise from algebras. In general, this theory identifies
five possible types of such quotients defined in a fairly sophisticated way. Fortunately, in
our case of relational structures with a Mal’tsev polymorphism, only two of those types
can occur, and the definition of these possible types can be significantly simplified.
A prime quotient α ≺ β is said to be of the affine type, if, for any β-class B, there
is a module MB with the base set B/α over a ring RB such that for any f (x1 , . . . , xn ,
y1 , . . . , ym ) ∈ Pol(H) and a1 , . . . , am ∈ H, if the operation g(x1 , . . . , xn ) = f (x1 , . . . , xn ,
a1 , . . . , am ) preserves B, then it can be represented as an operation of the module MB :
(g (x1 , . . . , xn ))/α = c1 x1 + . . . + cn xn + a.
B
In all other cases, α ≺ β has the Boolean type. While this definition does not match the
one in tame congruence theory, [Gumm 1979] implies that they are equivalent.
Example 3.3. Let L2 be a 2-element relational structure whose relational symbols are
interpreted as solution spaces of systems of linear equations. Then L2 has only two conJournal of the ACM, Vol. V, No. N, 20YY.
16
·
Andrei A. Bulatov
11
00
00{1,2,3,4}
11
00
11
{1,2,4}
00
11
00
λ11
3
00
11
1{1,2,3}
0
0
1
11
00
κ3
1{1,3}
0
{1,2}
{1}
1
0
1
0
1
0
0
1
3
00
11
4
11λ 2
00
00
11
2
00κ 2
11
11
00
1
11
00
(a)
(b)
Fig. 6.
gruences: ∆2 , the equality relation, and ∇2 , the total binary relation. If L2 has at least
one nontrivial relation (which is not a direct product of unary relations, equalities, and
disequalities), the prime quotient ∆2 ≺ ∇2 is of the affine type, see, e.g., [Szendrei 1986,
Chapter 2]. Thus, the affine type corresponds to some kind of “linearity” in a broad sense.
Prime quotients α1 ≺ β1 and α2 ≺ β2 are said to be perspective [projective] if the intervals
[α1 , β1 ] and [α2 , β2 ] are perspective [projective] in Con(H).
L EMMA 3.4 ([H OBBY AND M C K ENZIE 1988], L EMMA 6.2). If α1 ≺ β1 and α2 ≺
β2 are projective quotients in Con(H), then they have the same type.
3.3 Congruence lattices of relational structures with a Mal’tsev polymorphism
We will often distinguish two cases: when the congruence lattice of our relational structure
omits the affine type, and when the affine type occurs in this lattice. Note that, since
by Lemma 3.2 we need to consider only structures with a Mal’tsev polymorphism, all
congruence lattices we consider are modular
3.3.1 Distributive lattices and structures omitting the affine type. If H omits the affine
type then, by Theorem 9.15(4) of [Hobby and McKenzie 1988], Con(H) is meet semidistributive, and therefore it is distributive. We will need several properties of distributive
lattices. An element a of a lattice L is said to be join-irreducible if it is not the least element
of the lattice, and for any b, c ∈ L such that a = b ∨ c either b = a or c = a (see Fig, 5(b)).
Element a is said to be meet-irreducible if it is not the greatest element of the lattice, and
for any b, c ∈ L such that a = b ∧ c either b = a or c = a (see Fig, 5(c))
P ROPOSITION 3.5 ([G R ÄTZER 2003], T HEOREM 9, C OROLLARY 11, C OROLLARY 14, C H . II.1).
(1) For any finite distributive lattice L there is a finite set, Z, and a injective mapping
J : L → 2Z (the set of all subsets) such that J (a ∨ b) = J (a) ∪ J (b) and J (a ∧ b) =
J (a) ∩ J (b).
(2) Set Z can be chosen to be J(L), the set of all join irreducible elements of L, and
J (a) to be the set of all b ∈ J(L) with b ≤ a.
(3) If Z is a smallest set representing L, then every maximal chain of L has length |Z|.
Example 3.6. The lattice shown in Fig. 6(a) is distributive. Its representation as a lattice
of subsets is shown.
It will be convenient for us to use a particular set representation of elements of Con(H)
when it is distributive. For a relational structure H and its congruence lattice Con(H) we
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
17
use the following notation. Let C be a maximal chain ∆H = θ0 ≺ θ1 ≺ . . . ≺ θℓ = ▽H .
The set Z is defined to be the set of the prime quotients of this chain. The bottom end of a
prime quotient ω ∈ Z will be denoted by ω− , and the top one by ω+ .
For a congruence θ ∈ Con(H) let Z(θ) denote the set of quotients from Z that are
projective to quotients of the form γ ≺ β ≤ θ. The following proposition comprises
properties of Con(H) that follow easily from the representation of this lattice as a lattice
of subsets.
P ROPOSITION 3.7. (1) Every prime quotient α ≺ β in Con(H) is projective to one
and only one interval ω of C, and this interval satisfies the condition J (ω+ ) − J (ω− ) =
J (β) − J (α).
(2) Mapping Z is a representation of Con(H) by subsets of Z.
(3) For any ω ∈ Z, that is, any prime quotient in C, there is a greatest prime quotient
κω ≺ λω projective to ω; that is, for any α ≺ β projective to ω we have α ≤ κω and
β ≤ λω .
(4) For any ω ∈ Z, the congruence κω is meet-irreducible.
P ROOF. Let J denote the set of join-irreducible elements of Con(H), and let mapping
J : Con(H) → 2J be the set representation of Con(H) by J.
(1) Observe first that any prime quotient α ≺ β in Con(H) can be extended to a maximal
chain. Since all elements of this chain are different by Proposition 3.5(2), |J (β)−J (α)| =
1. Let J (β) − J (α) = {a} ⊆ J. Then there is ω ∈ [k] such that J (ω+ ) − J (ω− ) = {a}.
Set η = α ∨ ω− and θ = β ∨ ω− . Clearly, J (θ) = J (η) ∪ {a}, so β ∧ η = α, β ∨ η = θ
and η ∧ ω+ = ω− , η ∨ ω+ = θ. Intervals [α, β] and [ω− , ω+ ] are projective.
On the other hand, if two intervals [α, β] and [γ, δ] are perspective, that is, α = β ∧ γ,
δ = β∨γ, then J (δ) = J (γ)∪J (β) = J (α)∪(J (β)−J (α))∪J (γ) = J (γ)∪(J (β)−
J (α)), and J (β)−J (α) and J (γ) are disjoint. Therefore J (β)−J (α) = J (δ)−J (γ).
Since for all ω ∈ Z the sets J (ω+ ) − J (ω− ) are different, this implies that for any prime
quotient α ≺ β in Con(H) there is at most one ω ∈ Z projective to α ≺ β.
(2) From the proof of part (1) it follows that there is a bijection φ : Z → J such that
J (ω+ ) − J (ω− ) = {φ(ω)}. It suffices to show that J (α) = {φ(ω) | ω ∈ Z(α)}.
Let β ∈ J (α), that is, β is a join-irreducible element and β ≤ α. Let also β ′ be the
only element with β ′ ≺ β. Then J (β) − J (β ′ ) = {β}. By part (1) β ′ ≺ β is projective
to ω− ≺ ω+ with β = φ(ω), and so ω ∈ Z(α).
Conversely, if ω ∈ Z(α) then there is a prime quotient β ′ ≺ β ≤ α such that J (β) −
J (β ′ ) = {φ(ω)}. Hence φ(ω) ∈ J (α).
(3) Let κω be the join of all α ∈ Con(H) such that ω ̸∈ Z(α). By parts (2) and (3) of the
proposition ω ̸∈ Z(κω ). Then set λω = κω ∨ ω+ . Since ω ̸∈ Z(ω− ), we have ω− ≤ κω
and Z(λω ) = Z(κω ) ∪ Z(ω− ) ∪ {ω} = Z(κω ) ∪ {ω}.
Let α ≺ β be a prime quotient projective to ω, that is Z(β) − Z(α) = {ω}. Then
ω ̸∈ Z(α), so α ≤ κω . As Z(β) − Z(α) = Z(λω ) − Z(κω ), we have β ≤ λω , and by
part (1) α ≺ β and κω ≺ λω are projective.
(4) Suppose κω = α ∧ β. Then ω ̸∈ Z(α) or ω ̸∈ Z(β). By the choice of κω , either
α ≤ κω or β ≤ κω .
3.3.2 Relational structures admitting the affine type. Let us again consider the congruence lattice Con(H). A congruence β is said to be solvable over α if there are α =
Journal of the ACM, Vol. V, No. N, 20YY.
18
·
Andrei A. Bulatov
11
00
00
11
00
11
0011
11
00
11
00
00
11
00
11
00
11
00
11
0011
11
00
11
00
00
11
00
11
00
11
00
11
00 Con(H )
11
11
00
00
11
00
11
00
11
00
11
00
11
11
00
00
11
Con(H )/~s
s
Fig. 7. Congruence lattice and its quotient lattice modulo ∼. Prime quotients of the affine type are shown by
s
thick lines; the greatest elements in the classes of ∼ are encircled
θ1 ≺ . . . ≺ θk = β such that all the prime quotients θi ≺ θi+1 have the affine type. Then
s
s
∼ denotes the binary relation on Con(H) defined as follows: α ∼ β if and only if α ∨ β is
solvable over α ∧ β.
s
P ROPOSITION 3.8. (1) ∼ is an equivalence relation and, moreover, a congruence of
s
s
Con(H); that is, for any α1 , α2 , β1 , β2 ∈ Con(H) such that α1 ∼ α2 , β1 ∼ β2 , we have
s
s
(α1 ∨ β1 ) ∼ (α2 ∨ β2 ), (α1 ∧ β1 ) ∼ (α2 ∧ β2 ).
s
(2) Every class S of ∼ has a greatest αS and a least βS elements (with respect to ≤), and
equals the interval [βS , αS ]. Every prime quotient inside S has the affine type.
s is distributive (see Fig. 7).
(3) The quotient lattice LH = Con(H)/∼
P ROOF. (1) is Lemma 7.4 of [Hobby and McKenzie 1988].
(2) The first part follows from the well known fact (see [Grätzer 2003, Chapter 3]) that
every class of any congruence of a finite lattice is an interval, and therefore every class has
s
a least and a greatest elements. Let α ≺ β be a prime quotient in S. We have α ∼ β, that
is α = α ∧ β and α ∨ β = β are connected with a chain of prime quotients of the affine
type. However, Con(H) is modular, hence α ≺ β is the only such chain.
(3) Theorem 7.7(2) from [Hobby and McKenzie 1988] shows that LH is meet semidistributive. Since Con(H) is modular, so is any its quotient lattice such as LH (see
[Grätzer 2003, Chapter 4]), and therefore LH is distributive.
s
The ∼-class containing congruence α will be denoted by α∼ .
Proposition 3.8(2) implies that LH can be represented as a lattice of subsets of a finite
set Z. Similar to Subsection 3.3.1, Z can be chosen to be the set of prime quotients of a
maximal chain C in LH . Note that the endpoints of ω ∈ Z are sets S1 , S2 of congruences
from Con(H) (S1 corresponds to the bottom end of ω). By ω− we denote the greatest
element of S1 , and by ω+ the least element of S2 such that ω− ≤ ω+ . Let β ≺ γ be the
greatest quotient in LH projective to ω. Again, elements β and γ of LH represent sets
T1 , T2 of congruences from Con(H) (T1 corresponds to β). By κω we denote the greatest
element of T1 , and λω the least element in T2 such that κω ≤ λω (see Fig. 8).
P ROPOSITION 3.9. (1) Intervals [ω− , ω+ ] and [κω , λω ] are prime quotients.
(2) Prime quotient ω− ≺ ω+ is projective to κω ≺ λω .
(3) Prime quotients ω− ≺ ω+ and κω ≺ λω have the Boolean type.
(4) Congruence κω is meet-irreducible.
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
19
λω
κω
T2
S2
ω
T1
+
ω
ω
−
S1
Fig. 8. Congruence lattice and congruences κω , λω . Solid lines represent prime intervals of the Boolean type,
s
ovals represent ∼-classes
P ROOF. (1) Let ω− ≤ α ≤ ω+ . Since (ω− )∼ ≺ (ω+ )∼ , congruence α belongs to one
s
of the two ∼-classes. It cannot be the case that α ∈ (ω− )∼ and α ̸= ω− , because ω− is
the greatest element in (ω− )∼ . If α ∈ (ω+ )∼ then α = ω+ , as ω− ≤ α and ω+ is the least
element in (ω+ )∼ with this property.
For κω and λω the argument is the same.
(2) Since (ω− )∼ ≤ (κω )∼ and κω is the greatest element in (κω )∼ , it follows that
ω− ≤ κω . Then (κω ∧ ω+ )∼ = (κω )∼ ∧ (ω+ )∼ = (ω− )∼ , hence, as ω− is the greatest
element in (ω− )∼ , we obtain ω− ≤ κω ∧ ω+ ≤ ω− , that is, κω ∧ ω+ = ω− . Next, (κω ∨
ω+ )∼ = (κω )∼ ∨ (ω+ )∼ = (λω )∼ . Since κω ≤ κω ∨ ω+ , it follows that κω ∨ ω+ ≥ λω .
Thus intervals [ω− , ω+ ] and [κω , κω ∨ ω+ ] are projective. By the Isomorphism Theorem
for modular lattices, see Theorem 2, Chapter IV of [Grätzer 2003], they are isomorphic.
Hence, as ω− ≺ ω+ is a prime quotient, [κω , κω ∨ ω+ ] is also a prime quotient, which
implies κω ∨ ω+ = λω .
s
(3) If ω− ≺ ω+ or κω ≺ λω had the affine type, the ∼-classes (ω− )∼ and (ω+ )∼ ,
∼
∼
or (κω ) and (λω ) , respectively, would be equal. A contradiction with the assumptions
made.
(4) Suppose κω = α ∧ β, then α∼ ∧ β ∼ = (κω )∼ . By Proposition 3.7 (κω )∼ is meet∼
∼
∼
∼
irreducible, therefore α∼ = κ∼
ω or β = κω . If, say, α = (κω ) then α = κω .
3.4 Structure of relations invariant under a Mal’tsev operation
3.4.1 Basic properties. The following proposition contains some basic properties of
relations invariant under a Mal’tsev operation, which will be constantly used.
P ROPOSITION 3.10. Let H be a structure with a Mal’tsev polymorphism m and let R
be an n-ary relation pp-definable in H. Then for any I ⊆ [n] the following properties hold.
(1) R is rectangular, that is if a, b ∈ prI R, c, d ∈ pr[n]−I R and (a, c), (a, d), (b, c) ∈
R, then (b, d) ∈ R.
(2) The relation θI = {⟨a, b⟩ ∈ (prI R)2 | there is d ∈ pr[n]−I R such that (a, d), (b, d) ∈ R}
is a congruence of prI R.
(3) There is a one-to-one correspondence π between θI - and θ[n]−I -classes such that R
is a disjoint union of sets of the form B × C, where B and C is a θI - and θ[n]−I -class,
respectively, related by π.
Journal of the ACM, Vol. V, No. N, 20YY.
20
·
Andrei A. Bulatov
P ROOF. (1) It suffices to observe that
(( ) ( ) ( )) ( )
a
b
b
a
m
,
,
=
.
d
c
c
d
(2) It is straightforward that θI is reflexive and symmetric. If ⟨a, b⟩, ⟨b, c⟩ ∈ θI , say,
(a, d), (b, d) ∈ R and (b, e), (c, e) ∈ R, then by rectangularity (a, e) ∈ R implying
⟨a, c⟩ ∈ θI . Finally, if, say, I = {1, . . . , k} and [n] − I = {k + 1, . . . , n} then θI is
defined by the pp-formula
θI (x1 , . . . , xk , y1 , . . . , yk ) = ∃xk+1 , . . . , xn (R(x1 , . . . , xk , xk+1 , . . . , xn )
∧R(y1 , . . . , yk , xk+1 , . . . , xn )).
(3) Let B be a θI -class and C a θ[n]−I -class such that (a, b) ∈ R for some a ∈ B,
b ∈ C. Then for any c ∈ C there is d ∈ prI R with (d, b), (d, c) ∈ R. By rectangularity
we get (a, c) ∈ R. Repeating the same argument for tuples from B we conclude B ×
C ⊆ R. Finally, if for some a ∈ B there is b ∈ pr[n]−I R − C with (a, b) ∈ R then,
as (a, c) ∈ R for any c ∈ C, we have ⟨b, c⟩ ∈ θ[n]−I , contradicting the assumption
b ∈ pr[n]−I R − C.
Binary relations invariant with respect to a Mal’tsev operation have particularly simple
form. Let B1 , B2 be subalgebras of H and let α1 ∈ Con(B1 ), α2 ∈ Con(B2 ) be such that
|B1 /α | = |B2 /α |. Let also φ be a one-to-one mapping from B1 /α to B2 /α . The thick
1
2
1
2
mapping corresponding to φ is the binary relation R = {(a, b) ∈ B1 × B2 | φ(aα1 ) =
bα2 }. Any congruence α is the thick mapping corresponding to the identity mapping on
H/α. Proposition 3.10(3) implies the following
C OROLLARY 3.11. Let H be a relational structure with a Mal’tsev polymorphism.
Then every binary relation R pp-definable in H is a thick mapping.
Indeed, let R be a subdirect product of B1 and B2 , and let α1 = θ{1} , α2 = θ{2} . Then
by Proposition 3.10(3) there is a one-to-one correspondence φ between α1 - and α2 -classes
such that R is a disjoint union of sets of the form B × φ(B), B is an α1 -class. Thus R is
the thick mapping corresponding to φ.
We shall use thick mappings throughout the paper. Somewhat related to thick mappings
is the following relation on the set of coordinate positions of a relation. Let R be a k-ary
subdirect power of H, and α an equivalence relation on H. By α∗ we denote a relation on
the set [k] defined as follows: i, j are not in α∗ if there are a, b ∈ R such that ⟨a[i], b[i]⟩ ∈
α, but ⟨a[j], b[j]⟩ ̸∈ α, or ⟨a[j], b[j]⟩ ∈ α, but ⟨a[i], b[i]⟩ ̸∈ α.
3.4.2 The Boolean type and rectangularity properties. Let A be a finite algebra. Algebra A is called subdirectly irreducible if there is a congruence µ, the monolith of A, such
that ∆A ≺ µ and for any congruence γ ̸= ∆A we have µ ≤ γ. Similarly, we call a relational structure H subdirectly irreducible if Con(H) has a monolith, that is a congruence
µ satisfying the conditions above. Observe that Con(H) has a monolith if and only if the
least element of this lattice is meet-irreducible.
Let R ∈ def(H), where H is a subdirectly irreducible structure with a Mal’tsev polymorphism, be a k-ary subdirect power of H. The equivalence relation µ∗ is defined in the
same way as before. If the prime quotient ∆H ≺ µ has the Boolean type, Lemma 2.7 from
[Bulatov 2006a] characterizes µ∗ -classes in terms of so-called coherent sets. It shows that
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
21
in this case µ∗ -classes are the coherent sets. Then Lemma 2.6 of [Bulatov 2006a] can be
restated as follows.
L EMMA 3.12 [B ULATOV 2006 A , L EMMA 2.6]. Let R be an n-ary subdirect power of
H and the structure H is subdirectly irreducible. Let also µ be its monolith, let prime quotient ∆H ≺ µ have the Boolean type, and let I1 , . . . , Iℓ be the µ∗ -classes (or, equivalently,
the coherent sets). Let also B1 , . . . , Bn be µ-classes such that R ∩ (B1 × . . . × Bn ) ̸= ∅,
and
∏
RIj = prIj R ∩
Bi .
i∈Ij
Then R ∩ (B1 × . . . × Bn ) = RI1 × . . . × RIℓ .
Recall that for a congruence α ∈ Con(H), we denote by αn the congruence of R consisting of pairs ⟨a, b⟩ of tuples such that ⟨a[i], b[i]⟩ ∈ α for all i ∈ [n].
C OROLLARY 3.13. Let H be a structure with a Mal’tsev polymorphism, let M be a
maximal chain in Con(H), let R be an n-ary subdirect power of H and ω ∈ M . Let also
B1 , . . . , Bn be some classes of λω and I1 , . . . , Iℓ the classes of λ∗ω . Let also R′ = R/κn ,
ω
where R/κn = {((a[1])κω , . . . , (a[n])κω ) | a ∈ R}, and Bi′ = Bi /κ for i ∈ [n]. Then
ω
ω
either R ∩ (B1 × . . . × Bn ) = ∅, or
where RI′ j
R′ ∩ (B1′ × . . . × Bn′ ) = RI′ 1 × . . . × RI′ ℓ ,
∏
= prIj R′ ∩ i∈Ij Bi′ .
P ROOF. Relation R′ can be treated as a subdirect power of H/κ . Since κω is meetω
irreducible by Proposition 3.9(4), the congruence lattice of structure H/κ has a monolith,
ω
λω , and therefore is subdirectly irreducible. Now the result follows straightforwardly from
Proposition 3.9(3) and Lemma 3.12.
R EMARK 3.14. Another way to state Corollary 3.13 is the following. Let i1 , . . . , iℓ be
representatives of the λ∗ω -classes. Then for any choice of κω -classes a′im ∈ Bi′m , m ∈ [ℓ],
there is a ∈ R such that a[im ] ∈ a′im for all m ∈ [ℓ].
4.
CONSEQUENCES OF CONGRUENCE SINGULARITY
In this section we prove two further conditions for #-tractability that follow from congruence singularity, Proposition 2.16. They help us to design an algorithm for #CSP.
If the algebra corresponding to a structure H does not omit the affine type, then we have
a stronger necessary condition for the tractability of #CSP(H).
P ROPOSITION 4.1. If H is congruence singular then for any congruences δ ≤ α <
s
β ∈ Con(H) such that α ∼ β, any n-ary relation R ∈ def(H), and any sequences
A1 , . . . , An and B1 , . . . , Bn of α-classes such that Ai , Bi belong to the same β-class for
each i ∈ [n], if R1 = R ∩ (A1 × . . . × An ) ̸= ∅ and R2 = R ∩ (B1 × . . . × Bn ) ̸= ∅,
then |R1 /δ n | = |R2 /δ n |.
Suppose that Proposition 4.1 is proved in the case α ≺ β, that is, the following lemma
is true (we prove it later).
Journal of the ACM, Vol. V, No. N, 20YY.
22
·
Andrei A. Bulatov
L EMMA 4.2. If H is congruence singular then for any congruences δ ≤ α ≺ β ∈
Con(H) such that α ≺ β has the affine type, any n-ary relation R ∈ def(H), and any
sequences A1 , . . . , An and B1 , . . . , Bn of α-classes such that Ai , Bi belong to the same βclass for all i ∈ [n], if R1 = R∩(A1 ×. . .×An ) ̸= ∅ and R2 = R∩(B1 ×. . .×Bn ) ̸= ∅,
then |R1 /δ n | = |R2 /δ n |.
Then the general case follows.
P ROOF OF P ROPOSITION 4.1. We proceed by induction on the length of a maximal
chain α = α1 ≺ . . . ≺ αk = β. Lemma 4.2 provides the base case of induction. Suppose
that the proposition is proved for δ ≤ α < γ where γ ≺ β. That is for any sequences
A′1 , . . . , A′n and B1′ , . . . , Bn′ of α-classes such that Ai , Bi belong to the same γ-class for
each i ∈ [n], if R1′ = R ∩ (A′1 × . . . × A′n ) ̸= ∅ and R2′ = R ∩ (B1′ × . . . × Bn′ ) ̸= ∅,
then |R1′ /δ n | = |R2′ /δ n |.
Let A′′i , Bi′′ be the γ-classes containing Ai , Bi , respectively, and R1′′ = R ∩ (A′′1 ×
. . . × A′′n ), R2′′ = R ∩ (B1′′ × . . . × Bn′′ ). Since γ ≺ β and this prime quotient has
the affine type, we can apply Lemma 4.2 to the triple of congruences δ ≤ γ ≺ β to
obtain |R1′′ /δ n | = |R2′′ /δ n |. Then we apply Lemma 4.2 to the triple of congruences α ≤
γ ≺ β, and obtain the equality |R1′′ /αn | = |R2′′ /αn |; denote this number by N . By the
induction hypothesis, every αn -class inside R1′′ (and inside R2′′ ) contains the same number
of δ n -classes. Therefore |R1′′ /δ n | = N · |R1 /δ n | and |R2′′ /δ n | = N · |R2 /δ n |. Equality
|R1 /δ n | = |R2 /δ n | follows.
To prove Lemma 4.2 we make use of some basics of commutator theory in congruence
modular varieties (see [Freese and McKenzie 1987]). As usual we introduce all required
notions for relational structures rather than for algebras. Let H be a relational structure
with a Mal’tsev polymorphism m, R ∈ def(H) a k-ary relation, and α, β, γ congruences
of R. Congruence α centralizes β modulo γ, denoted C(α, β; γ), if, for any (n-ary) polymorphism f of H, any ⟨u, v⟩ ∈ α and any ⟨a1 , b1 ⟩, . . . , ⟨an−1 , bn−1 ⟩ ∈ β,
⟨f (u, a1 , . . . , an−1 ), f (u, b1 , . . . , bn−1 )⟩ ∈ γ
⇐⇒
⟨f (v, a1 , . . . , an−1 ), f (v, b1 , . . . , bn−1 )⟩ ∈ γ.
The smallest congruence γ such that C(α, β; γ) is called the commutator of α, β, denoted
[α, β].
Example 4.3. We illustrate the definition above with the following example. Let H
be a 3-element structure with the universe H = {0, 1, 2} and 4-ary relation R defined as
follows. Let A0 = {0} and A1 = {1, 2}. Then
∪
Aa × Ab × Ac × Ad .
R=
a+b≡c+d (mod 2)
Consider unary relation H. Set β = ▽H , and set α to be the congruence with classes
A0 , A1 . Observe that α is a congruence, since it is given by the following pp-formula
α(x, y) = ∃zR(x, y, z, z).
It is not hard to show that the polymorphisms of H are the operations f (x1 , . . . , xn )
satisfying the following condition: there is an operation g(y1 , . . . , yn ) on {0, 1} such that
(a) g(y1 , . . . , yn ) = e1 y1 + . . . + en yn + e (mod 2), and (b) if xi ∈ Ayi for i ∈ [n] then
f (x1 , . . . , xn ) ∈ Ag(y1 ,...,yn ) .
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
23
We show that [β, β] ≤ α. Let f (x1 , . . . , xn ) be a polymorphism of H and g(y1 , . . . , yn ) =
e1 y1 +. . .+en yn +e the corresponding linear operation on {0, 1}. Let also u, v, a1 , . . . , an−1 ,
b1 , . . . , bn−1 ∈ H be such that ⟨u, v⟩ ∈ β and ⟨ai , bi ⟩ ∈ β (as β is the total relation,
′
′
′
′
these are just any elements of H). Let u ∈ Au , v ∈ Av and ai ∈ Aai , bi ∈ Abi for
i ∈ [n − 1]. If ⟨f (u, a1 , . . . , an−1 ), f (u, b1 , . . . , bn−1 )⟩ ∈ α then g(u′ , a′1 , . . . , a′n−1 ) =
g(u′ , b′1 , . . . , b′n−1 ). Using the linearity of g we have e2 a′1 + . . . + en a′n−1 + e = e2 b′1 +
. . . + en b′n−1 + e (mod 2). Therefore g(v ′ , a′1 , . . . , a′n−1 ) = g(v ′ , b′1 , . . . , b′n−1 ), and
so ⟨f (v, a1 , . . . , an−1 ), f (v, b1 , . . . , bn−1 )⟩ ∈ α. The converse implication is similar.
The next proposition follows from Proposition 4.3 and Theorem 4.9 of [Freese and
McKenzie 1987], Theorem 7.2 of [Hobby and McKenzie 1988]
P ROPOSITION 4.4. Let H be a relational structure with a Mal’tsev polymorphism, R ∈
def(H) a (k-ary) relation, and α, β congruences of R. Then
(1) [α, β] = [β, α] (follows from [Freese and McKenzie 1987, Proposition 4.3]);
(2) if α ≺ β, then this prime quotient has the affine type if and only if [β, β] ≤ α (follows
from [Hobby and McKenzie 1988, Theorem 7.2]);
(3) if α ≤ β and [β, β] ≤ α, there is a congruence θ of β (where β is considered as a
2k-ary relation from def(H)) such that the set {(a, b) | ⟨a, b⟩ ∈ α} is a class of θ. (Using
the notation from [Freese and McKenzie 1987, Theorem 4.9], θ = ∆θ,θ ∨ α2 .)
Now we are in a position to prove Lemma 4.2.
P ROOF OF L EMMA 4.2. By switching to the quotient structure H/δ we may assume
that δ is the equality relation. To prove Lemma 4.2 we consider several congruences of
R, including αn and β n . As we are concerned about α-classes within some β-classes,
we can restrict R to a single β n -class. By Lemma 2.20 every β n class of R is a relation
pp-definable in H, so let R′ be an arbitrary such class.
C LAIM 1. [β n , β n ] ≤ αn .
Let f be a (k-ary) polymorphism of H, and let ⟨u, v⟩ ∈ β n and ⟨a1 , b1 ⟩, . . . , ⟨ak−1 , bk−1 ⟩ ∈
n
β where u, v, ai , bi ∈ R′ for i ∈ [k − 1]. If ⟨f (u, a1 , . . . , ak−1 ), f (u, b1 , . . . , bk−1 )⟩ ∈
αn then ⟨f (u[i], a1 [i], . . . , ak−1 [i]), f (u[i], b1 [i], . . . , bk−1 [i])⟩ ∈ α for each i ∈ [n].
Since C(β, β; α), this implies ⟨f (v[i], a1 [i], . . . , ak−1 [i]), f (v[i], b1 [i], . . . , bk−1 [i])⟩ ∈
α for each index i ∈ [n]. Thus ⟨f (v, a1 , . . . , ak−1 ), f (v, b1 , . . . , bk−1 )⟩ ∈ αn .
Every αn -class of R′ has the form R′ ∩(A1 ×. . .×An ) for certain α-classes A1 , . . . , An .
Let C1 , . . . , Ck be the αn -classes of R′ , and |Ci | = ℓi . We have to prove that ℓi = ℓj for
any i, j ∈ [k].
We treat the congruence β n restricted onto R′ as a 2n-ary relation pp-definable in H; let
us denote it by Q. By the choice of R′ we have Q = R′2 . Proposition 4.4(3) implies that
there is a congruence γ of Q such that the set D of pairs of the form (a, b), a, b ∈ R′ and
⟨a, b⟩ ∈ αn , is a γ-class. Let γ ′ = γ ∨ α2n .
C LAIM 2. (1) Every class E of γ ′ is the union (C1 × CφE (1) ) ∪ . . . ∪ (Ck × CφE (k) ) for
a certain bijective mapping φE : [k] → [k].
(2) The set D is a class of γ ′ ; and for this class φD is the identity mapping.
Note that for any tuples a, b, c, d ∈ R such that a, c ∈ Ci and b, d ∈ Cj we have
⟨(a, b), (c, d)⟩ ∈ α2n .
Journal of the ACM, Vol. V, No. N, 20YY.
24
·
Andrei A. Bulatov
We start with (2). Clearly, D has the required form of a union for the identity mapping
φD . Since D is a class of γ and a union of α2n -classes, it is a class of γ ∨ α2n = γ ′ .
(1) It suffices to prove three claims: (a) for any Ci , Cj , if (Ci × Cj ) ∩ E ̸= ∅ then
Ci × Cj ⊆ E; (b) if (a, b), (c, d) ∈ E and ⟨a, c⟩ ∈ αn , then ⟨b, d⟩ ∈ αn ; and (c) for any
Ci there is Cj such that (Ci × Cj ) ∩ E ̸= ∅.
Property (a) follows from the inclusion α2n ≤ γ ′ .
To prove (b) suppose that there are (a, b), (c, d) ∈ E such that ⟨a, c⟩ ∈ αn , but ⟨b, d⟩ ̸∈
n
α . As α2n ≤ γ ′ , we may assume a = c. Since γ ′ is a congruence on Q, and therefore
is reflexive, (a, a, a, a), (a, b, a, b) ∈ γ ′ , considering γ ′ as a 4-ary relation on R′ . As
(b, b), (d, d) ∈ D and γ ≤ γ ′ , the tuple (b, b, d, d) is also from γ ′ . Finally, by (a)
(a, b, a, d) ∈ γ ′ . Then we have
b
a a b
b
a a b
a b b a
b a a b
′
′
m
a a d = d ∈ γ and m a a d = d ∈ γ ,
b
a
b a a
a d d
which implies that (b, d) ∈ D, and therefore ⟨b, d⟩ ∈ αn , a contradiction.
To prove (c) suppose that, for some Ci and for any Cj , (Ci ×Cj )∩E = ∅. Take a ∈ Ci
and (b, c) ∈ E. Then (b, c, b, c), (b, b, b, b), (a, a, b, b) ∈ γ ′ (the last tuple belongs to
γ ′ because (a, a), (b, b) ∈ D). We have
a
b b a
c b a d
m
b b b = b ∈ γ,
c
c b b
where d = m(c, b, a). Thus (a, d) ∈ E, a contradiction
Suppose that ℓi ̸= ℓj for some i, j ∈ [k]; clearly if such i, j exist we can choose i = 1.
Without loss of generality we also assume ℓ1 < ℓj . We present a pair of congruences of
Q that violate the condition of Proposition 2.16. One of them is γ ′ the other one is β ′
defined to be the congruence αn × β n . In other words, ⟨(a, b), (c, d)⟩ ∈ β ′ if and only if
⟨a, c⟩ ∈ αn . It is not hard to see that γ ′ ∨ β ′ = β n × β n and γ ′ ∧ β ′ = αn × αn . Indeed,
α2n ≤ γ ′ ∧ β ′ . If ⟨(a, b), (c, d)⟩ ∈ γ ′ ∧ β ′ then ⟨a, c⟩ ∈ αn , since ⟨(a, b), (c, d)⟩ ∈ β ′ ,
and by Claim 2 this implies ⟨b, d⟩ ∈ αn . Thus γ ′ ∧ β ′ ≤ αn × αn . Let (a, b), (c, d) ∈
Q. As β 2n is the total binary relation on Q these pairs are in the same β 2n -class. By
Claim 2 there is e ∈ R′ such that ⟨(a, b), (c, e)⟩ ∈ γ ′ . Since ⟨(c, e), (c, d)⟩ ∈ β ′ we have
⟨(a, b), (c, d)⟩ ∈ γ ′ ◦ β ′ ⊆ γ ′ ∨ β ′ .
Every class of αn × αn is the Cartesian product of two classes Ci , Cj of αn . Therefore,
its cardinality equals ℓi ℓj . Thus, the row of the matrix M (γ ′ , β ′ ) corresponding to a γ ′ class E looks as follows (observe that since M (γ ′ , β ′ ) is the matrix of a single congruence
class, all its entries are positive)
(
)
ℓ1 ℓφE (1) ℓ2 ℓφE (2) · · · ℓk ℓφE (k) .
The row corresponding to the class D is
( 2 2
)
ℓ1 ℓ2 · · · ℓ2k .
As Q = R′2 , there is a γ ′ -class E such that C1 × Cj ⊆ E (recall that ℓ1 < ℓj ). Since
H is congruence singular, the rows of M (γ ′ , β ′ ) corresponding to classes D and E are
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
25
proportional, that is
ℓ1
ℓφE (1)
=
ℓ2
ℓφE (2)
= ... =
ℓk
ℓφE (k)
.
Let j1 = 1, j2 = φE (1) = j, and jt = φE (jt−1 ) for t > 2. Let also m > 1 be the minimal
number such that jm = 1. We prove ℓjt > ℓjt−1 that leads to a contradiction, as it would
imply that ℓ1 < ℓjm = ℓ1 . By the assumption made ℓj1 = ℓ1 < ℓj = ℓj2 , which gives us
the base case. From the equalities above we have ℓ2jt = ℓjt−1 ℓjt+1 . Therefore if ℓjt−1 < ℓt
then ℓt < ℓjt+1 , which proves the induction step.
Example 4.3 (continued). Reconsider the relational structure H from Example 4.3. By
Proposition 4.1 the problem #CSP(H) is #P-complete. Indeed, consider congruences α
and β = ▽H of H. We showed that [β, β] ≤ α, therefore by Proposition 4.4, prime
quotient α ≺ β has the affine type. Setting δ = ∆H we see that α-classes A0 and A1
contain different number of elements.
The construction used in the proof of Proposition 4.1 in this case looks as follows. Congruence β is the binary relation H 2 . Congruence γ ′ of β such that D = {(0, 0), (1, 1),
(1, 2), (2, 1), (2, 2)} is its class can be chosen to be the congruence with classes D and
E = {(0, 1), (0, 2), (1, 0), (2, 0)}; and it is easy to see that we can use R defined in
Example 4.3 for that. Finally, the classes of β ′ = α × β are {(0, 0), (0, 1), (0, 2)} and
{(1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)}. Therefore
(
)
1 4
M (R; γ ′ , β ′ ; ∆H ) =
,
2 2
and its rank equals 2.
We will also need another corollary from Proposition 2.16. Let T be a k-dimensional
array, that is a collection of numbers T [i1 , . . . , ik ] indexed by tuples (i1 , . . . , ik ), where
1 ≤ ik ≤ mk . Array T has rank 1, denoted rank(T ) = 1, if for each ℓ ∈ [k] there are
numbers tℓ1 , . . . , tℓmk such that
T [i1 , . . . , ik ] = t1i1 · . . . · tkik .
Observe that if k = 2, and thus T is a matrix, T has rank 1 in the sense introduced above
if and only if T has the row- (column-) rank 1.
L EMMA 4.5. Array T has rank 1 if and only if for each ℓ ∈ [k], and any i1 , . . . , iℓ−1 ,
iℓ+1 , . . . , ik , j1 , . . . , jℓ−1 , jℓ+1 , . . . , jk with iu , ju ∈ [mu ], we have
T [i1 , . . . , iℓ−1 , 1, iℓ+1 , . . . , ik ]
T [i1 , . . . , iℓ−1 , mℓ , iℓ+1 , . . . , ik ]
= ... =
.
T [j1 , . . . , jℓ−1 , 1, jℓ+1 , . . . , jk ]
T [j1 , . . . , jℓ−1 , mℓ , jℓ+1 , . . . , jk ]
(1)
P ROOF. If rank(T ) = 1 then equations (1) are trivially true. To prove the converse we
observe that equations (1) implies that for any i1 , . . . , ik and ℓ ∈ [k]
T [i1 , . . . , ik ] = T [i1 , . . . , iℓ−1 , 1, iℓ+1 , . . . , ik ] ·
T [1, . . . , 1, iℓ , 1, . . . , 1]
.
T [1, . . . , 1]
Therefore
k
∏
T [1, . . . , 1, iℓ , 1, . . . , 1]
T [i1 , . . . , ik ] = T [i1 , 1, . . . , 1] ·
.
T [1, . . . , 1]
ℓ=2
Journal of the ACM, Vol. V, No. N, 20YY.
26
·
Andrei A. Bulatov
γ1 γ2 γ3
γ1
γ1 γ2
γ2
γ1 γ3
γ3
γ2 γ3
γ1 γ2 γ3
Fig. 9.
Congruences satisfying condition (2)
Choosing t1i = T [i, 1, . . . , 1] for i ∈ [mi ] and tji =
i ∈ [mj ] we obtain the result.
T [1,...,1,i,1,...,1]
T [1,...,1]
for 2 ≤ j ≤ k and
Now let R be a relation pp-definable in a structure H with a Mal’tsev polymorphism,
and let γ1 , . . . , γk be congruences on R such that for each i ∈ [k]
γi ∨ (γ1 ∧ . . . ∧ γi−1 ∧ γi+1 ∧ . . . ∧ γk ) = γ1 ∨ . . . ∨ γk
(2)
Condition (2) means that the sublattice of Con(H) generated by γ1 , . . . , γk is close to
the lattice of subsets of a k-element set (Fig. 9), and that each (γ1 ∨ . . . ∨ γk )-class of
Alg(H)/γ ∧ . . . ∧ γ is a direct product of Alg(H)/γ , i ∈ [k], see [Burris and Sankap1
k
i
panavar 1981]. Let also C be a class of γ = γ1 ∨ . . . ∨ γk , and let Ai1 , . . . , Aimi be the
classes of γi from C. Condition (2) means that for any j1 , . . . , jk the set A1j1 ∩ . . . ∩ Akjk
is a nonempty class of β = γ1 ∧ . . . ∧ γk . Indeed, let ℓ be the smallest number such that
for certain j1 , . . . , jℓ the set A1j1 ∩ . . . ∩ Aℓjℓ = ∅. Then for any a, b ∈ C we have
⟨a, b⟩ ∈ γℓ ∨ (γ1 ∧ . . . ∧ γℓ−1 ∧ γℓ+1 ∧ . . . ∧ γk ) ≤ γℓ ∨ (γ1 ∧ . . . ∧ γℓ−1 ).
Moreover, as congruences of R are permutable, ⟨a, b⟩ ∈ γℓ ◦ (γ1 ∧ . . . ∧ γℓ−1 ). Take
a ∈ Aℓj and b ∈ A1j1 ∩ . . . ∩ Aℓ−1
jℓ−1 , a class of γ1 ∧ . . . ∧ γℓ−1 . Then there exists c such that
c ∈ Aℓj and c ∈ A1j1 ∩ . . . ∩ Aℓ−1
jℓ−1 , a contradiction. It is also clear that any two classes of
this form are different. We consider a k-dimensional array M (C; γ1 , . . . , γk ), where
M (C; γ1 , . . . , γk )[i1 , . . . , ik ] = |A1i1 ∩ . . . ∩ Akik |.
P ROPOSITION 4.6. Let γ1 , . . . , γk be congruences of a structure H that has a Mal’tsev
polymorphism, let them satisfy condition (2), and let C be a class of γ1 ∨ . . . ∨ γk . Then,
if H is congruence singular then rank(M (C; γ1 , . . . , γk )) = 1.
P ROOF. We consider congruences γi and βi = γ1 ∧ . . . ∧ γi−1 ∧ γi+1 ∧ . . . ∧ γk . To simplify the notation we assume i = k. If H is congruence singular, then rank(M (C; γk , βk ; ∆H )) =
1. Let Aj1 , . . . , Ajmj be the classes of γj from C. The classes of βk have the form
A1i1 ∩ . . . ∩ Ak−1
ik−1 , the classes of γk ∧ βk are the classes of γ1 ∧ . . . ∧ γk . Therefore
every row of M (C; βk , γk ; ∆H ) is equal to
(M (C; γ1 , . . . , γk )[i1 , . . . , ik−1 , 1], . . . , M (C; γ1 , . . . , γk )[i1 , . . . , ik−1 , mk ])
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
27
for some i1 , . . . , ik−1 . Since rank(M (C; γk , βk )) = 1, we get
M (C; γ1 , . . . , γk )[i1 , . . . , ik−1 , 1]
M (C; γ1 , . . . , γk )[i1 , . . . , ik−1 , mk ]
= ... =
,
M (C; γ1 , . . . , γk )[j1 , . . . , jk−1 , 1]
M (C; γ1 , . . . , γk )[j1 , . . . , jk−1 , mk ]
for any j1 , . . . , jk−1 , js ∈ [ms ]. The proposition is proved.
An important example of a collection of congruences satisfying condition (2) is the
following (we prove it in Section 5.3). Let ω ∈ M , and let I1 , . . . , Ik be the classes of
κ∗ω . Congruence γj is given by: ⟨a, b⟩ ∈ γj if and only if ⟨a[i], b[i]⟩ ∈ ω− for i ∈ Ij and
⟨a[i], b[i]⟩ ∈ ω+ otherwise.
5.
ALGORITHMS: PREREQUISITES
5.1 Decision CSPs over structures with a Mal’tsev polymorphism.
If a relational structure H has a Mal’tsev polymorphism, then the decision CSP with the
template H can be solved in polynomial time [Bulatov 2002b; Bulatov and Dalmau 2006].
Here we shall use the algorithm presented in [Bulatov and Dalmau 2006], and we call it
M AL’ TSEV. This algorithm builds a sort of a succinct (polynomial size) representation for
the set of all solutions.
Let n be a positive integer, let H be a finite set, let a, b be n-tuples of elements of H,
and let (i, a, b) be any element in [n] × H 2 . We say that pair ⟨a, b⟩ witnesses (i, a, b) if
pr[i−1] a = pr[i−1] b, a[i] = a, and b[i] = b. We also say that a and b witness (i, a, b)
meaning that ⟨a, b⟩ witnesses (i, a, b).
Let R be any n-ary relation on H. The signature of R, SigR ⊆ [n] × H 2 , is defined to
be the set containing all triples (i, a, b) ∈ [n] × H 2 witnessed by tuples in R, that is
SigR = {(i, a, b) ∈ [n] × H 2 | there are a, b ∈ R such that ⟨a, b⟩ witnesses (i, a, b)}.
Note that in our notation (i, a, b) ∈ SigR if and only if ⟨a, b⟩ belongs to the relation θi
computed for the relation pr[i] R (see Section 3.4.1). In particular, as H has a Mal’tsev
polymorphism, relation pr[i] R is rectangular, and hence for any (i, a, b) ∈ SigR and any
a ∈ pr[i] R with a[i] = a, the tuple b such that pr[i−1] b = pr[i−1] a and b[i] = b also
belongs to pr[i] R.
A subset R′ of R is called a representation of R if SigR′ = SigR . If furthermore,
|R′ | ≤ 2|SigR | then R is called a compact representation of R. Observe that every relation
R has a compact representation.
Let H be a relational structure and R′ ⊆ H n for some n. By ⟨R′ ⟩H we denote the
relation generated by R′ , that is, the smallest relation R pp-definable in H and such
that R′ ⊆ R. Alternatively, ⟨R′ ⟩H can be constructed from R′ by adding every tuple
a that can be obtained as f (a1 , . . . , an ) where f is an (n-ary) polymorphism of H and
a1 , . . . , an ∈ R′ . Since H is usually clear from the context we shall omit this subscript.
The key lemma proved in [Bulatov and Dalmau 2006] states that if R is a relation ppdefinable in a relational structure with a Mal’tsev polymorphism, and R′ is a representation of R, then ⟨R′ ⟩ = R. Note that every member of ⟨R′ ⟩ in this case can be obtained
in a certain regular way by repeated applications of the Mal’tsev polymorphism. Given an
instance G of the constraint satisfaction problem CSP(H), m = |G|, the set of all solutions
Φ(G, H) to this problem can be thought of as an m-ary relation pp-definable in H. The
algorithm presented in [Bulatov and Dalmau 2006] finds a compact representation of this
set.
Journal of the ACM, Vol. V, No. N, 20YY.
·
28
Andrei A. Bulatov
We will need to know the unary and binary projections of the relation Φ(G, H), that is,
sets of the form Φg = {φ(g) | φ ∈ Φ(G, H)} for g ∈ G, and Φg,h = {(φ(g), φ(h)) | φ ∈
Φ(G, H)} for g, h ∈ G. Let R′ be a compact representation of Φ(G, H). If a ∈ Φg then
(g, a, a) ∈ SigΦ(G,H) , so Φg = pr{g} R′ . It is also not hard to see (see also [Bulatov and
Dalmau 2006]) that Φg,h is equal to ⟨prg,h R′ ⟩. Since the structure H is fixed, we assume
that we have all necessary information about H. This includes the relation ⟨R⟩ generated
by any set R ⊆ H2 . Therefore, we assume the relation Φg,h can be found using a compact
representation R′ in linear time.
5.2
Reduction to subdirect powers.
In general, for an instance G of #CSP(H) the sets Φg , g ∈ G, are subalgebras of H that
are not necessarily equal to H. For us, however, it is much more convenient to deal with
the case when Φ(G, H) is a subdirect power of H, that is Φg = H for all g ∈ G. We show
how to transform the problem so that Φg is H for all g ∈ G. To do this we borrow some
methods from the multi-sorted CSP, see, e.g. [Bulatov and Jeavons 2003].
Let D1 , . . . , Dℓ be the nonempty subalgebras of H (including H itself). We define a
relational structure χ(H) as follows. The universe of χ(H) is D = D1 × . . . × Dℓ ; the
ith component of an element a ∈ D is denoted by a[i]. For any (n-ary) relation R ppdefinable in H and such that prj R = Dij , we set (a1 , . . . , an ) ∈ χ(R) if and only if
(a1 [i1 ], . . . , an [in ]) ∈ R. In particular, each unary relation of χ(H) corresponding to a
relation of H contains all elements of D and, therefore, are redundant in the new structure
(however, they are still needed for reductions between #CSP(H) and #CSP(χ(H))) . For
any coordinate position i of any non-unary relation R, the set pri χ(R) equals D. Finally,
to define χ(H) formally, for each relational symbol R, we interpret it as Rχ(H) = χ(R).
It is sometimes useful to replace a relational structure H with its expansion. Let H be
a relational structure with vocabulary τ and universe H. Structure H′ is said to be an
expansion of H if it has the same universe H, and vocabulary τ ′ ⊇ τ , where every symbol
from τ is interpreted in H′ in the same way as in H. An expansion of a structure can be
thought of as throwing in some extra relations. If all the added relations are pp-definable
in H then #CSP(H′ ) is polynomial time reducible to #CSP(H). Therefore expanding a
structure by adding pp-definable relations does not change the complexity of the problem
[Bulatov and Dalmau 2007]. By taking an expansion of H if necessary, we shall assume
that along with every (n-ary) relational symbol R and any subalgebras Di1 , . . . , Din the
H
vocabulary of H contains a symbol R′ such that R′ = R ∩ (Di1 × . . . × Din ).
L EMMA 5.1. A relational structure H is congruence singular if and only if χ(H) is
congruence singular.
P ROOF. Suppose first that H is congruence singular. Let R be an n-ary relation over D.
It naturally defines an ℓn-ary relation fla(R) over H that we call flattening of R:
fla(R) = {fla(a) ∈ H ℓn | there is a ∈ R such that
(fla(a)[ℓ(j − 1) + 1], . . . , fla(a)[ℓj]) = a[j] for each j ∈ [n]}.
As is easily seen, fla is a one-to-one mapping between the set of n-tuples and the set of
ℓn-tuples, and also between n-ary and ℓn-ary relations.
C LAIM 1. |fla(R)| = |R|.
C LAIM 2. If R is pp-definable in χ(H) then fla(R) is pp-definable in H.
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
29
The following convention for indexing variables of predicates will be helpful. If R is
n-ary and R(x1 , . . . , xn ) is the corresponding predicate, we use fla(R)(x11 , . . . , xℓ1 , . . . ,
x1n , . . . , xℓn ) for the predicate corresponding to fla(R).
First, we prove the claim for a relation R = χ(R′ ) where R′ is a relation from H.
Suppose that R′ is n-ary and prj R′ = Dij for j ∈ [n]. It is not hard to see that
fla(R)(x11 , . . . , xℓ1 , . . . , x1n , . . . , xℓn ) = R′ (xi11 , . . . , xinn ) ∧
n ∧
ℓ
∧
Di (xij ).
j=1 i=1
Now we proceed by induction on the structure of a pp-definition of R. If R = R1 ∧ R2
then fla(R) = fla(R1 ) ∧ fla(R2 ). If R(x1 , . . . , xn ) = ∃yR′ (x1 , . . . , xn , y) then
fla(R)(x11 , . . . , xℓ1 , . . . , x1n , . . . , xℓn ) = ∃y 1 , . . . , y ℓ
fla(R′ )(x11 , . . . , xℓ1 , . . . , x1n , . . . , xℓn , y 1 , . . . , y ℓ ) ∧
ℓ
∧
Di (y i ).
i=1
C LAIM 3. Let R ∈ def(χ(H)) be an n-ary relation, α, β its congruences. Then (a) for
any binary relation θ on R and any a, b ∈ R, ⟨a, b⟩ ∈ θ if and only if ⟨fla(a), fla(b)⟩ ∈
fla(θ); (b) relations fla(α), fla(β) are congruences of fla(R), (c) equalities fla(α ∧ β) =
fla(α) ∧ fla(β), fla(α ∨ β) = fla(α) ∨ fla(β) hold, and (d) the number of α- [β-] classes
equals that of fla(α)- [respectively, fla(β)-] classes, and |B| = |fla(B)| for each α- [β-]
class B.
(a) follows from the observation that fla(a, b) = (fla(a), fla(b)) for any a, b ∈ R.
(b) To prove it use part (a) along with Claim 2.
(c) Note that if fla(a) = fla(b) then a = b. Hence, fla(α ∧ β) = fla(α ∩ β) =
fla(α) ∩ fla(β) = fla(α) ∧ fla(β). To prove fla(α ∨ β) = fla(α) ∨ fla(β) we can use (a) to
show that transitive closure is preserved by fla, that implies the result.
(d) For any α-class B by Claim 1 we have |B| = |fla(B)|. Using (a) we can also find
a one-to-one correspondence between α- and fla(α)-classes [respectively, β- and fla(β)classes].
Finally, let α, β, and δ with δ ≤ α, β be congruences of R, and let A1 , . . . , Am and
B1 , . . . , Bk be the α- and β-classes respectively. Then fla(A1 ), . . . , fla(Am ) and
fla(B1 ), . . . , fla(Bℓ ) are the fla(α)- and fla(β)-classes, respectively. Moreover, the number of δ-classes in each α ∧ β-class B is equal to that of fla(δ)-classes in fla(B), and
the number of α ∨ β-classes is equal to the number of fla(α) ∨ fla(β)-classes. Therefore
M (R; α, β; δ) = M (fla(R); fla(α), fla(β); fla(δ)).
Now we prove that if H is not congruence singular then so is χ(H). First observe
that if R is a relation and α its congruence, then, for any ⟨b, c⟩ ∈ α and any b′ ∈
χ(b), c′ ∈ χ(c) (here χ(b) is viewed as if b is a singleton relation), ⟨b′ , c′ ⟩ ∈ χ(α).
Therefore for any R and congruences α, β, γ of R, γ ≤ α, β, we have M (R; α, β; γ) =
M (χ(R); χ(α), χ(β); χ(γ)). If we prove that χ(R) is pp-definable in χ(H) and χ(α),
χ(β), and χ(γ) are congruences of χ(R), then χ(R), χ(α), χ(β), χ(γ) witness that χ(H)
is not congruence singular. Thus the following Claim completes the proof.
C LAIM 4. If R is pp-definable in H then χ(R) is pp-definable in χ(H).
We assume that along with any (n-ary) relation R and any subalgebras D1 , . . . , Dn
structure H also contains the relation R ∩ (D1 × . . . × Dn ). If R is a relation from H,
Journal of the ACM, Vol. V, No. N, 20YY.
30
·
Andrei A. Bulatov
Algorithm Subdirect
I NPUT: an instance G of #CSP(H)
O UTPUT: an instance G ′ of #CSP(χ(H)) with the same universe as G
Step 1 find a compact representation of Φ(G, H) using M AL’ TSEV
Step 2 for each g ∈ G find Φg
Step 3 for each (n-ary) relational symbol R do
Step 3.1
for each tuple (g1 , . . . , gn ) ∈ RG do
Step 3.1.1
let R′ be the relational symbol such that R′ H = RH ∩ (Φg1 × . . . × Φgn )
′
Step 3.1.2
include (g1 , . . . , gn ) into R′ G
endfor
endfor
Step 4 output G ′
Fig. 10.
then χ(R) is a relation of χ(H) by definition. We proceed by induction on the length of
pp-definitions. Suppose that the claim is true for all relations pp-definable in H whose
pp-definition is shorter than that of R. If R(x1 , . . . , xn ) = ∃y R′ (x1 , . . . , xn , y) then, as
is easily seen χ(R)(x1 , . . . , xn ) = ∃y χ(R′ )(x1 , . . . , xn , y).
So, let R = R1 ∧ R2 . Observe, first, that if for any i ∈ [n], pri R = pri R1 = pri R2
then χ(R) = χ(R1 ) ∧ χ(R2 ). Therefore, it suffices to consider the case when R2 is unary.
Indeed, for Rj′ (x1 , . . . , xn ) = Rj (x1 , . . . , xn ) ∧ pr1 R(x1 ) ∧ . . . ∧ prn R(xn ), j = 1, 2,
we have R = R1′ ∧ R2′ and pri R = pri R1 = pri R2 for i ∈ [n], so if χ(R1′ ), χ(R2′ ) are
pp-definable in χ(H) then so is χ(R).
Let R(x1 , . . . , xn ) = R1 (x1 , . . . , xn )∧R2 (xi ), and let R1 (x1 , . . . , xn ) = Ψ(x1 , . . . , xn )
be a pp-definition of R1 . Let Q(y1 , . . . , yk ) be an occurrence of a relation Q from H in
formula Ψ such that xi ∈ {y1 , . . . , yk }. Let also Q′ be the relation Q(y1 , . . . , yk )∧R2 (xi ),
which is also a relation from H. Replace in Ψ this occurrence of Q with Q′ (y1 , . . . , yk ). As
is easily seen the pp-definition Ψ′ (x1 , . . . , xn ) obtained by replacing all such occurrences
defines R(x1 , . . . , xn ), and has the same length as Ψ. Therefore χ(R) is pp-definable in
χ(H) by the induction hypothesis.
For an instance G of #CSP(H), the algorithm in Fig. 10 constructs an instance G ′ of
#CSP(χ(H)). The following lemma completes the reduction.
L EMMA 5.2. Let G be an instance of #CSP(H) and G ′ the instance of #CSP(χ(H))
constructed by algorithm Subdirect. Let also Φg = prg Φ(G, H) for g ∈ G. Then
Φ(G ′ , χ(H)) is a subdirect power of χ(H) and
∏ |D|
|Φ(G ′ , χ(H))| = |Φ(G, H)| ·
.
|Φg |
g∈G
Moreover, Subdirect is polynomial time.
P ROOF. Let φ ∈ Φ(G, H) be a homomorphism from G to H. Let a set of mappings
χ(φ) from G ′ to χ(H) be given by
χ(φ) = {ψ : G ′ → χ(H) | for any g ∈ G′ if Φg = Di and ψ(g) = a then a[i] = φ(g)}.
(Note that G and G ′ have a common universe.) We show that every ψ ∈ χ(φ) is a homoG′
morphism from G ′ to χ(H). Let R′ be a relational symbol and (g1 , . . . , gn ) ∈ R′ . Tuple
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
G′
·
31
H
(g1 , . . . , gn ) comes to R′ on Step 3.1.2 from some RG such that R′ = RH ∩ (Φg1 ×
H
H
. . . × Φgn ). Therefore (φ(g1 ), . . . , φ(gn )) ∈ R′ . Since pri R′ = Φgi for i ∈ [n], we
H
also have (ψ(g1 ), . . . , ψ(gn )) ∈ χ(R′ ). Thus ψ is a homomorphism.
For any g ∈ G′ and any a ∈ Φg there is φ ∈ Φ(G, H) such that φ(g) = a, hence, for
any ψ ∈ χ(φ) we have ψ(g)[i] = a. Since for any aj ∈ Dj , j ∈ [ℓ] − {i}, there exists
ψ ∈ χ(φ) with ψ(g)[j] = aj , this implies that Φ(G ′ , χ(H)) is a subdirect power of χ(H).
Let φ ∈ Φ(G ′ , χ(H)) be a homomorphism from G ′ to χ(H). Let us define a mapping
χ−1 (φ) from G to H as follows. For g ∈ G if φ(g) = a and Φg = Di then set χ−1 (φ)(g) =
a[i]. By the construction of χ(H) and G ′ , if we change the value a = φ(g) for some g ∈ G
with Φg = Di to any b such that b[i] = a[i], then the resulting mapping φ′ is still a
homomorphism from G ′ to χ(H) and χ−1 (φ′ ) = χ−1 (φ). For a fixed g this can be done
|D|
ways. Conversely, for any homomorphism ψ ∈ Φ(G, H), any mapping φ : G ′ →
in |Φ
g|
χ(H) such that χ−1 (φ) = ψ is a homomorphism of G ′ to χ(H). Therefore for each
∏
|D|
homomorphism ψ ∈ Φ(G, H) there are g∈G |Φ
homomorphisms φ ∈ Φ(G ′ , χ(H))
g|
such that χ−1 = ψ. The result follows.
Finally, since Step 3 makes only one pass over every tuple of relations in G, this step can
be done in linear time. Thus the time complexity of the algorithm is dominated by Step 1,
which is polynomial time, as so is algorithm M AL’ TSEV.
5.3 Structure of Mal’tsev instances
Let G be a #CSP(H) instance and |G| = m. In this section we study certain structural
properties of the set of homomorphisms Φ(G, H) from G to H. It will be convenient to
assume that the universe G of G equals [m]. Set Φ(G, H) can be thought of as an m-ary
relation pp-definable in H. By the results of the previous subsection we may assume that
R = Φ(G, H) is a subdirect power of H. Recall that for a congruence θ ∈ Con(H) by θm
we denote the congruence of R such that ⟨a, b⟩ ∈ θm if and only if ⟨a[g], b[g]⟩ ∈ θ for all
g ∈ G. For congruences β ≤ γ ∈ Con(H) and a mapping τ : G → H/β , by τ γ we denote
a mapping from G to H/γ given by τ γ (g) = τ (g)γ .
s . As before
Let Z be the set of prime quotients of a maximal chain in L = Con(H)/∼
we assume Z = {1, . . . , ℓ}. Let also ω ∈ Z. We use notation ω+ , ω− introduced in
Section 3.3. Take τ , an element of R/ω m . It can be thought of as a mapping from G
+
to H/ω . This mapping is always a homomorphism from G to H/ω , but not every
+
+
such homomorphism belongs to R/ω m . Indeed, if ω = ℓ and ω+ is the total relation, a
+
homomorphism from any G to H/ω , a 1-element structure, always exists, however, R can
+
be empty. By Φ(G, H; τ ) we denote the set of elements ϱ from R, that is, homomorphisms
from G to H, such that ϱω+ = τ .
We study the structure of Φ(G, H; τ ) up to ω− . More precisely, let E1 , . . . , Er be the
∗
ω−
-classes and h1 , . . . , hr representatives of these classes. For any homomorphism ϱ ∈
Φ(G, H; τ ) and any h ∈ Ei , the value ϱ(h)ω− is completely determined by the value
ϱ(hi ), so we may focus on possible values of such homomorphisms on h1 , . . . , hr . Our
goal is to show that these values are in some sense independent, meaning that for any
collection a1 ∈ τ (h1 )/ω , . . . , ar ∈ τ (hr )/ω (recall that τ (hi ) is a ω+ -class) there is
−
−
ϱ ∈ Φ(G, H; τ ) such that ϱ(hi )ω− = ai . Unfortunately, this statement is false in general,
however, in the end of this section we prove a result sufficiently close to this one. Note also
Journal of the ACM, Vol. V, No. N, 20YY.
32
·
Andrei A. Bulatov
that Φ(G, H; τ ) is considered as a part of Φ(G, H). Although, it is possible to restrict the
original instance so that its solutions are only members of Φ(G, H; τ ), it leads to several
complications. The most important of them is that under solutions from Φ(G, H; τ ) the
possible images of elements of G are restricted to a proper subset of H that destroys the
subdirect powers condition we worked so hard to achieve.
First we consider a similar problem for another prime quotient, κω ≺ λω . This will
help us because, since κω ∧ ω+ = ω− , values ϱ(hi )κω and τ (hi ) determine ϱ(hi )ω− . We
prove that the required property is true in this case. Let A1 , . . . , Ak be the κ∗ω -classes and
g1 , . . . , gk representatives of these classes. By C1u , . . . , Csuu we denote the κω -classes from
τ (gu )λω , u ∈ [k].
L EMMA 5.3. For any choice of iu ∈ [su ], u ∈ [k], there is a homomorphism ϱ ∈ R
such that for each u ∈ [k]
ϱ(gu )κω = Ciuu .
P ROOF. If we set Bg to be the λω -class containing τ (g) then τ witnesses that R ∩ (B1 ×
. . . × Bm ) ̸= ∅. Let R′ = R/κm and Bg′ = Bg /κ for g ∈ G. Then, by Corollary 3.13,
ω
ω
we have
′
where RA
u
′
′
′
R′ ∩ (B1′ × . . . × Bm
) = RA
× . . . × RA
,
1
k
∏
= prAu R′ ∩ g∈Au Bg′ The result follows.
m
m
If κm
ω ∨ (ω+ ) were equal to λω this would mean that Φ(G, H; τ ) intersects with every
m
κω -class, and since κω ∧ ω+ = ω− , this non-empty intersection would provide a homom
morphism with prescribed values modulo ω− . However in general κm
̸= λm
ω ∨ (ω+ )
ω,
m
m
m
m
so it is important to find κω ∨ (ω+ ) . To do that we describe the interval [κω , λω ] in the
congruence lattice Con(R). It will be more convenient to think of elements of R as tuples
rather than mappings.
m
L EMMA 5.4. Every prime quotient in the interval [κm
ω , λω ] of the congruence lattice
m
m
Con(R) has the Boolean type, the interval [κω , λω ] is a distributive lattice isomorphic to
the lattice 2[k] of subsets of a k-element set, where k is the number of κ∗ω -classes, and every
congruence in this interval can be represented as ηJ , J ⊆ [k], given by: ⟨a, b⟩ ∈ ηJ if and
only if ⟨a[gu ], b[gu ]⟩ ∈ κω whenever u ∈ [k] − J and ⟨a[gu ], b[gu ]⟩ ∈ λω when u ∈ J.
P ROOF. Replacing R with R/κm we may assume that κω = ∆H . Thus if tuples a, b ∈
ω
R are such that a[gu ] = b[gu ] for all u ∈ [k], then a = b. Therefore, it suffices to consider
relation R′ = pr{g1 ,...,gk } R. We study intervals of the form [ηJ , ηJ∪{v} ] for J ⊆ [k] and
v ∈ [k]−J. Any such interval is non-trivial, meaning ηJ < ηJ∪{v} . Indeed, by Lemma 5.3,
for any J ⊆ [k] and v ∈ [k] − J there are tuples a, b ∈ R such that a[gv ] ̸= b[gv ], but
a[gu ] = b[gu ] for all u ∈ [k] − {v}. By the same reason ∆kH < η{v} for any v ∈ [k].
First, we show that every such interval is a prime quotient. Note that interval [ηJ , ηJ∪{v} ]
is perspective to [∆kH , η{v} ]. Indeed, if ⟨a, b⟩ ∈ ηJ then a[gu ] = b[gu ] for u ∈ [k] − J,
and if ⟨a, b⟩ ∈ η{v} then a[gu ] = b[gu ] for all u ̸= v, implying ηJ ∧ η{v} = ∆kH . If
⟨a, b⟩ ∈ ηJ∪{v} , then by Lemma 5.3 there is a tuple c such that a[gu ] = c[gu ] for all
u ̸= v and c[gu ] = b[gu ] for all u ∈ [k] − J. Hence ηJ ∨ η{v} = ηJ∪{v} . It suffices
to show that the intervals of the form ∆kH < η{v} are prime quotients. To simplify the
notation we assume v = 1.
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
33
Let ∆kH < α ≤ η{1} . For any ⟨a, b⟩ ∈ α and any u ̸= 1, a[gu ] = b[gu ]. This means
that α is determined by the relation
β = {⟨a, b⟩ ∈ H 2 | there are a, b ∈ R′ such that ⟨a, b⟩ ∈ α, a[g1 ] = a, b[g1 ] = b,
and a[gu ] = b[gu ] for all u ̸= 1}.
By the rectangularity of R′ relation β is a congruence of H and ∆H < β ≤ λω . As
∆H ≺ λω , we get β = λω , and the rectangularity of R implies α = η{1} .
Let us now check that quotient ∆kH ≺ η{1} has the Boolean type. By Proposition 3.9(3)
∆H ≺ λω has the Boolean type, which means that there is a polymorphism f (x1 , . . . , xn )
of H and elements c, d, a1 , . . . , an−1 , b1 , . . . , bn−1 such that ⟨c, d⟩ ∈ λω , ⟨ai , bi ⟩ ∈ λω
for i ∈ [n − 1], and f (c, a1 , . . . , an−1 ) = f (c, b1 , . . . , bn−1 ) but f (d, a1 , . . . , an−1 ) ̸=
f (d, b1 , . . . , bn−1 ). By Lemma 5.3 there are c, d and ai , bi , i ∈ [n − 1], from R′ such
that c[g1 ] = c, d[g1 ] = d, ai [g1 ] = ai , bi [g1 ] = bi , and c[gu ] = d[gu ], ai [gu ] = bi [gu ]
for i ∈ [n − 1] and u ∈ [k] − {1}. Observe that ⟨c, d⟩, ⟨a1 , b1 ⟩, . . . , ⟨an−1 , bn−1 ⟩ ∈
η{1} . Then we have f (c, a1 , . . . , an−1 ) = f (c, b1 , . . . , bn−1 ) but f (d, a1 , . . . , an−1 ) ̸=
f (d, b1 , . . . , bn−1 ), that implies that η{1} does not centralize itself modulo ∆kH , and so
by Proposition 4.4(2) ∆H ≺ η{1} has the Boolean type.
We have proved that any interval of the form [ηJ , ηJ∪{v} ] is a prime quotient, and, by
Lemma 3.4, it has the Boolean type. Next we show that every prime quotient α ≺ β with
∆kH ≤ α ≺ β ≤ λkω is projective to one of such intervals, and therefore has the Boolean
type. Suppose the contrary, and let β ≤ λkω be a maximal congruence such that, for some
α ≺ β, [α, β] is projective to [ηJ , ηJ∪{v} ] for no J ⊆ [k], and v ∈ [k] − J. Let J be
a maximal set such that ηJ ≤ α, and v any member of [k] − J. Then ηJ ≺ ηJ∪{v} .
Since α ∧ ηJ∪{v} = ηJ , if ηJ∪{v} ≤ β the interval [α, β] is perspective to [ηJ , ηJ∪{v} ], a
contradiction with the assumption made. Otherwise, by the modularity of Con(R), [α, β]
is perspective to [α ∨ ηJ∪{v} , β ∨ ηJ∪{v} ], a contradiction with the maximality of β. Thus,
every prime quotient from interval [∆kH , λkω ] has the Boolean type.
Finally, by Lemma 6.6 of [Hobby and McKenzie 1988], this implies that this interval
does not contain a diamond, and, as Con(R) is modular, [∆kH , λkω ] is distributive. Since the
congruences η{1} , . . . , η{ℓ} are join-irreducible elements of this lattice, and η1 ∨ . . . ∨ ηℓ =
λm
ω , every element θ of this interval can be represented in the form
∨
θ=
ηu = ηJ
u∈J
for some J ⊆ [k].
Now we obtain a result similar to Lemma 5.3 for homomorphisms modulo ω− . Note
∗
that ω−
-classes cannot be used, because, in general, they have nothing in common with
∗
κω -classes. Indeed, a pair ⟨g, g ′ ⟩ belongs to α∗ for some congruence α if, for any mappings
ϱ1 , ϱ2 , ⟨ϱ1 (g), ϱ2 (g)⟩ ∈ α if and only if ⟨ϱ1 (g ′ ), ϱ2 (g ′ )⟩ ∈ α. For different congruences
α such conditions are incomparable. However, if some homomorphism τ ∈ R/ω m is
+
fixed, inside τ classes of ω− and of κ∗ω are much stronger related to each other. Since
κω ∧ ω+ = ω− , homomorphism τ and a choice of values for g1 , . . . , gk (provided they are
taken from τ (gu )λω ) determine a mapping ϱ : G → H/ω . For any g ∈ G, the values
−
of g1 , . . . , gk determine the κω -class ϱ(g) belongs to, and τ (g) determines the ω+ -class
of ϱ(g). Therefore every homomorphism from Φ(G, H; τ ) up to ω− can be defined by a
Journal of the ACM, Vol. V, No. N, 20YY.
·
34
Andrei A. Bulatov
certain choice of values for g1 , . . . , gk . The difficulty is that some choices do not define
any homomorphism. The next lemma shows which combinations of values for g1 , . . . , gk
correspond to elements of Φ(G, H; τ ).
L EMMA 5.5. There is Jω ⊆ [k] such that for any τ ∈ R/ω m (we use notation for
+
κω -classes introduced before Lemma 5.3), there are iu with iu ∈ [su ], u ∈ [k] − Jω ,
satisfying the following conditions. For any homomorphism ϱ ∈ R/ω m with ϱω+ = τ the
−
collection of iu , u ∈ [k] − Jω , can be completed by iu with iu ∈ [su ] for u ∈ Jω such that
ϱ(gu ) ∈ τ (gu ) ∩ Ciuu for u ∈ [k]; and, for any g ∈ Au , u ∈ [k], we have ϱ(g) = τ (g) ∩ C,
where C is the κω -class corresponding to the choice of Ciuu for gu .
Conversely, for any choice of Ciuu , u ∈ Jω , the mapping ϱ defined in this way is an
element of R/ω m , and ϱω+ = τ .
−
m
m
P ROOF. Observe that in the congruence lattice Con(R) we have κm
ω ∧ ω+ = ω− and
m
m
m
m
m
≤ κω ∨ ω+ ≤ λω . By Lemma 5.4, κω ∨ ω+ = ηJω for some Jω ⊆ [k]. This means
that there are fixed iu , u ∈ [k] − Jω , with iu ∈ [su ], such that for any ϱ ∈ R/(ω )m , with
−
ϱω+ = τ , we have ϱ(gu ) ∈ Ciuu for u ∈ [k] − Jω .
Take ϱ ∈ R/ω m with ϱω+ = τ . Clearly, ϱκω belongs to τ λω /κm , and by what we
κm
ω
−
ω
showed above ϱ(gu ) ∈ Ciuu for u ∈ [k] − Jω . The first part of the lemma follows.
To prove the converse statement, let us denote the ηJω -class containing τ by D. Since
m
m
m
′
′
κm
ω and ω+ permute, for any κω -class C ⊆ D and any ω+ -class C , the intersection C∩C
u
is nonempty. Therefore, for any φ ∈ R/κm such that φ(gu ) = Ciu for u ∈ [k] − Jω , there
ω
is ϱ ∈ R/ω m such that ϱκω = φ and ϱω+ = τ ; that is ϱ(g) = φ(g) ∩ τ (g). The lemma is
proved.
−
We complete this section by presenting a collection of congruences related to ω− , ω+
and satisfying condition (2), see p.26. Let A1 , . . . , Ak be the κ∗ω -classes, and let Jω ⊆ [k]
be the set defined in Lemma 5.5 for ω ∈ Z. Congruences γu , u ∈ ∪
Jω , are defined as
follows: ⟨a, b⟩ ∈ γu if and only if ⟨a[i], b[i]⟩ ∈ ω− for i ∈ Au ∪ v∈[k]−Jω Av , and
⟨a[i], b[i]⟩ ∈ ω+ otherwise. (Here again we treat elements of R as tuples.) Condition (2)
for the congruences γu means that every class of R/ω m can be thought of as a direct
+
product of γu -classes, u ∈ Jω . Therefore the number of elements in it can be represented
using a |Jω |-dimensional array, and can be evaluated (modulo ω− ) using Proposition 4.6.
L EMMA 5.6. Congruences γu , u ∈ Jω , satisfy condition (2).
P ROOF. Again we use notation introduced before Lemma 5.3. Without loss of generalm
m
ity we assume Jω = {1, . . . , q}. First, observe that γ1 ∧ . . . ∧ γq = ω−
. Let
∪ βu = γu ∨ κω ,
that is, ⟨a, b⟩ ∈ βu if and only if ⟨a[i], b[i]⟩ ∈ κω for i ∈ Au ∪ v∈[k]−J Av and
⟨a[i], b[i]⟩ ∈ λω otherwise. Let also θ = γ1 ∨ . . . ∨ γq . It is not hard to see that
β1 ∧ . . . ∧ βq = κm
ω and βi ∨ βj = ηJω for any i, j ∈ [q]. Since lattice Con(R) is
m
modular, intervals [ω−
, θ] and [κm
ω , ηJ ] are isomorphic, where an isomorphism can be defined by φ(x) = x ∨ κm
ω , see [Grätzer 2003] Cha. IV, Theorem 2. Again by modularity
m
m
m
m
m
m
m
equalities θ ∨ κm
ω = ω+ ∨ κω = ηJω and θ ∧ κω = ω+ ∧ κω = ω− imply θ = ω+ .
Therefore we may consider β1 , . . . , βq instead of γ1 , . . . , γq , where we also may assume
that κω = ∆H . To simplify the notation we prove condition (2) for i = 1.
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
35
By Lemma 5.5, ⟨a, b⟩ ∈ β1 if and only if prA1 ∪Aq+1 ∪...∪Ak a = prA1 ∪Aq+1 ∪...∪Ak b,
tuples prA2 ∪...∪Aq a, prA2 ∪...∪Aq b belong to prA2 ∪...∪Aq R, and ⟨a[g], b[g]⟩ ∈ λω for
g ∈ A2 ∪ . . . ∪ Aq . Similarly, ⟨a, b⟩ ∈ β2 ∧ . . . ∧ βq if and only if prA1 a, prA1 b ∈ prA1 R,
⟨a[g], b[g]⟩ ∈ λω for g ∈ A1 , and prA2 ∪...∪Ak a = prA2 ∪...Ak b ∈ prA2 ∪...∪Ak R. Take
a, b ∈ R such that ⟨a, b⟩ ∈ λm
ω and a[g] = b[g] for g ∈ Aq+1 ∪. . .∪Ak , and define c to be
the tuple with c[g] = a[g] for g ∈ A1 and c[g] = b[g] for g ∈ A2 ∪. . .∪Ak . By Lemma 5.5,
c ∈ R and ⟨a, c⟩ ∈ β1 , ⟨c, b⟩ ∈ β2 ∧ . . . ∧ βq . Thus ⟨a, b⟩ ∈ β1 ∨ (β2 ∧ . . . ∧ βq ).
6. ALGORITHM: COMPUTING THE NUMBER OF SOLUTIONS
In this section we use the results proved in the previous sections to design an algorithm
solving counting CSPs for congruence singular structures.
Suppose that H is congruence singular. Let G be an instance of #CSP(H); assume that
the universe G of G is [m]. As before Z = {1, . . . , ℓ} is the set of prime quotients of a
s . If ℓ+ ̸= ▽H or 1− ̸= ∆H then we add extra
maximal chain in the lattice Con(H)/∼
elements (ℓ + 1)− or 0+ to the set of congruences ω− , ω+ , ω ∈ Z, see Fig 11. Otherwise
we assume (ℓ + 1)− = ℓ+ and 0+ = 1− , respectively. In Con(H) the chain corresponds
to a number of prime quotients of the form ω− ≺ ω+ that have the Boolean type, and
intervals [ω+ , (ω + 1)− ] such that every prime quotient from this interval has the affine
type, see Fig. 11. A mapping τ : G → H/θ for θ ∈ Con(H) will be called a mapping
of level θ. Recall that for a mapping τ of level θ, by Φ(G, H; τ ) we denote the set of all
homomorphisms ϱ ∈ Φ(G, H) with ϱθ = τ . For ω ∈ Z and a mapping τ from G to H/ω
+
or to H/ω , we show how to reduce computing the number |Φ(G, H, τ )| to computing
−
numbers |Φ(G, H, ϱ)| for certain ϱ, mappings from G to H/ω or to H/(ω − 1) , respec−
+
tively. The two cases, τ : G → H/ω and τ : G → H/ω will be considered in the next
+
−
two subsections.
( l +1)−
l+
l−
2
−
+
( l −1)
+
1
−
1
+
0
Fig. 11. The congruence lattice of H, a maximal chain in Con(H)/ s , the corresponding prime quotients, and
∼
s
s
∼-classes. Prime quotients ω− ≺ ω+ are shown by solid lines, ∼-classes by ovals, dashed lines represent chains
of the affine type (not to be confused with the dotted line).
Journal of the ACM, Vol. V, No. N, 20YY.
36
·
Andrei A. Bulatov
6.1 Prime quotients of the Boolean type
Let A1 , . . . , Ak be the κ∗ω -classes and g1 , . . . , gk their representatives. Let τ be a mapping
from Φ(G, H)/ω m , that is, τ (g) is a ω+ -class for g ∈ G. By Jω we denote the subset of [k]
+
identified in Lemma 5.5. Without loss of generality we assume Jω = [q]. Let C1u , . . . , Csuu
be the κω -classes from τ (gu )λω , the λω -class containing elements from τ (gu ), for u ∈ [k].
Recall that by definition g ∈ Au if and only if for any ϱ, ϱ′ ∈ Φ(G, H) if ⟨ϱ(gu ), ϱ′ (gu )⟩ ∈
κω then ⟨ϱ(g), ϱ′ (g)⟩ ∈ κω and vice versa. Therefore, for any g ∈ Au , u ∈ [k], and for any
ϱ ∈ Φ(G, H; τ ) the value ϱ(g)ω− is determined by ϱ(gu )ω− , and that ϱ(g)ω− = ϱ(g)κω ∩
τ (g). In other words, there is a one-to-one mapping φg from the set {C1u , . . . , Csuu } to the
set of κω -classes of τ (g)λω such that ϱ(g)ω− = φg (ϱ(gu )κω ) ∩ τ (g). Let iu , u ∈ [k] − Jω
and iu ∈ [su ], be the κω -classes corresponding to τ as in Lemma 5.5.
P ROPOSITION 6.1. (1) For any q-tuple r such that r[u] ∈ [su ], the mapping ϱr : G →
H/ω , where for each u ∈ [k]
−
{
ϱr (gu ) =
u
Cr[u]
∩ τ (gu ), if u ∈ Jω
Ciuu ∩ τ (gu ), otherwise,
and for each g ∈ Au , u ∈ [q], ϱr (g)ω− = φg (ϱr (gu )κω ) ∩ τ (g), belongs to R/(ω )m .
−
∑
(2) |Φ(G, H, τ )| =
|Φ(G, H, ϱr )|.
r
(3) Sets Φ(G, H, ϱr ) are the classes of congruence (ω− )m of the relation Φ(G, H, τ ).
P ROOF. (1) follows straightforwardly from Lemma 5.5.
(2) Every homomorphism ϱ from Φ(G, H; τ ) belongs to a certain set Φ(G, H, ϱr ), namely,
the one with r[u] = ju where ϱ(gu ) ∈ Cjuu for u ∈ [q]. On the other hand all sets of this
form are disjoint.
(3) Since κω ∧ ω+ = ω− , all elements from Φ(G, H, ϱr ) are (ω− )m -related. If ϱ ∈
Φ(G, H, ϱr ) and ϱ′ ∈ Φ(G, H, ϱr′ ) where r[u] ̸= r′ [u] then ⟨ϱ(gu ), ϱ′ (gu )⟩ ̸∈ ω− , and
therefore ⟨ϱ, ϱ′ ⟩ ̸∈ (ω− )m .
We use the congruences γ1 , . . . , γq introduced in Section 5.3: ⟨ϱ, ϱ′ ⟩ ∈ γu if and only if
⟨ϱ(g), ϱ′ (g)⟩ ∈ ω− if g ∈ Au or g ∈ Aq+1 ∪ . . . ∪ Ak , and ⟨ϱ(g), ϱ′ (g)⟩ ∈ ω+ otherwise.
By Lemma 5.6 congruences γ1 , . . . , γq satisfy condition (2), and (ω− )m = γ1 ∧ . . . ∧ γq .
m
Recall that τ can be treated as a ω+
-class and that M (τ, γ1 , . . . , γq ) denotes the qdimensional s1 × . . . × sq -array such that its entry indexed by r is equal to |Φ(G, H, ϱr )|.
By Proposition 4.6, M (τ, γ1 , . . . , γq ) has rank 1, that is, there are numbers tu1 , . . . , tusu , for
u ∈ [q], such that
|Φ(G, H, ϱr )| = t1r[1] · . . . · tqr[q] .
Journal of the ACM, Vol. V, No. N, 20YY.
·
The Complexity of the Counting CSP
37
If numbers tij are known, we have
∑
∑
Φ(G, H, τ ) =
Φ(G, H, ϱr ) =
t1r[1] · . . . · tqr[q]
r
∑
= t11
r
t2r[2] · . . . · tqr[q] + . . . + t1s1
r[2],...,r[q]
= ... =
sj
q ∑
∏
∑
t2r[2] · . . . · tqr[q]
r[2],...,r[q]
tij ,
i=1 j=1
that can be computed easily.
To find the numbers tij we use the approach from the proof of Lemma 4.5. Fix a tuple
r, say, r = (1, . . . , 1). By rij we denote the tuple, all entries of which are equal to the
corresponding entries of r, except for the i-th entry that is equal to j. Then set
t1j = |Φ(G, H, ϱr1j )| and
tij =
|Φ(G, H, ϱrij )|
|Φ(G, H, ϱr )|
for i ∈ {2, . . . , q}.
Thus, we have reduced computing the number |Φ(G, H, τ )|, where mapping τ is of level
ω+ , to computing numbers of the form |Φ(G, H, ϱrij )|, where ϱrij is of level ω− .
6.2
Quotients of the affine type
Let τ ∈ Φ(G, H)/(ω + 1)m for some ω ∈ Z − {ℓ}. Congruence (ω + 1)− is solvable over
−
ω+ , and we make use of the following implication of Proposition 4.1.
C OROLLARY 6.2. (1) Let ϱ1 , ϱ2 ∈ Φ(G, H, τ )/ω m . Then |Φ(G, H, ϱ1 )| = |Φ(G, H, ϱ2 )|.
(2) For any ϱ ∈ Φ(G, H, τ )/ω m ,
+
+
|Φ(G, H, τ )| = |Φ(G, H, ϱ)| · |Φ(G, H, τ )/ω m |.
+
Thus, to reduce computing |Φ(G, H, τ )|, where τ is of level (ω + 1)− , to computing
|Φ(G, H, ϱ)|, where ϱ is of level ω+ , it suffices to find the number |Φ(G, H, τ )/ω m |.
+
We consider first the case when ω+ is the equality relation, that is, ω = 0. In this case
the required number can be found using the signature SigR of the relation R = Φ(G, H, τ )
in a very simple way through the following lemma. Observe that it does not apply to the
case when 1− = ∆H .
L EMMA 6.3. Let SigR be the signature of Φ(G, H, τ ), and αg be the relation {⟨a, b⟩ |
(g, a, b) ∈ SigR }. Then
(1) αg is a congruence of τ (g);
(2) all αg classes have the same cardinality, denoted by vg ;
(3) |Φ(G, H, τ )| = v1 · . . . · vm .
P ROOF. (1) Relation αg is pp-definable in H as the following formula shows
αg (x, y) = ∃z1 , . . . , zg−1 , zg+1 , . . . , zm , ug+1 , . . . , um
(R(z1 , . . . , zg−1 , x, zg+1 , . . . , zm ) ∧ R(z1 , . . . , zg−1 , y, ug+1 , . . . , um )).
Journal of the ACM, Vol. V, No. N, 20YY.
38
·
Andrei A. Bulatov
Due to rectangularity of R this relation is an equivalence relation.
s
(2) follows straightforwardly from Proposition 4.1, as αg ≤ (ω+1)− , and so (ω+1)− ∼
αg .
(3) As every element of pr[m−1] Φ(G, H, τ ) can be extended to an element of Φ(G, H, τ )
by any member of a certain αm -class, the number of such extensions equals vm , and we
have |Φ(G, H, τ )| = |pr[m−1] Φ(G, H, τ )|· vm . Continuing this way we get |Φ(G, H, τ )| =
v1 · . . . · vm .
To find the signature of Φ(G, H, τ ) we can use algorithm M AL’ TSEV applied to the
instance modified in the following way. We shall assume that for each subalgebra B of
H
= B. Let
H the vocabulary of H contains a unary relational symbol RB such that RB
g1 , . . . , gk ∈ G, and let B1 , . . . , Bk be subalgebras of H. By G ∪ {⟨g1 , B1 ⟩, . . . , ⟨gk , Bk ⟩}
we denote the relational structure with the same universe as G, and such that the interpretation of every relational symbol R ̸∈ {RB1 , . . . , RBk } equals RG while the interpretation
G
of RB equals RB
∪ {gi | Bi = B}. Thus, the elements g1 , . . . , gk are forced to be mapped
to B1 , . . . , Bk respectively. It is not hard to check that Φ(G, H, τ ) is the set of solutions
for the instance G ∪ {⟨g, τ (g)⟩ | g ∈ [m]}.
Observe that if we know the signature of relation Φ(G, H, τ )/ω m , which is a relation
+
over H/ω , we still can use Lemma 6.3 to find the cardinality of |Φ(G, H, τ )/ω m |. In
+
+
order to do that we just have to replace H with H/ω . Therefore the problem we are
+
facing now is how to find the signature of this relation. Unfortunately, it is not clear at all
how to obtain this signature using the signature or a compact representation of Φ(G, H, τ ),
nor can we use algorithm M AL’ TSEV to compute the signature of Φ(G, H/ω , τ ), since
+
in general Φ(G, H/ω , τ ) ̸= Φ(G, H, τ )/ω m . Instead, to compute each member of the
+
+
required signature we find a compact representation of a certain modified problem using
algorithm M AL’ TSEV.
More specifically, we first find the ω+ -signature of the relation Φ(G, H, τ ). Let n be a
positive integer, let H be a finite set, let θ be an equivalence relation on H, let a, b be ntuples, and let (i, a, b) be any element in [n] × H 2 . We say that ⟨a, b⟩ θ-witnesses (i, a, b)
if (a[j], b[j]) ∈ θ for each j < i, a[i] = a, and b[i] = b. Let R be an n-ary relation on
H. The θ-signature of R, θSigR ⊆ [n] × H 2 , is defined to be the set containing all those
(i, a, b) ∈ [n] × H 2 θ-witnessed by tuples in R, that is
θSigR = {(i, a, b) ∈ [n] × H 2 | there are a, b ∈ R such that ⟨a, b⟩ θ-witnesses (i, a, b)}.
L EMMA 6.4. Let τ ∈ Φ(G, H)/(ω + 1)m .
−
(1) Algorithm ω-S IGNATURE (see Fig. 12) finds the ω+ -signature ω+ SigR of
R = Φ(G, H, τ ).
(2) The signature of Φ(G, H, τ )/ω m can then be found by replacing each (g, a, b) ∈
ω+ SigR by (g, aω+ , bω+ )
+
P ROOF. (1) For any g ∈ [m], a triple (g, a, b) is added to S only if there are ϱ, ϱ′ ∈
Φ(G, H, τ ) such that ϱ(g) = a, ϱ′ (g) = b, and ⟨ϱ(h), ϱ′ (h)⟩ ∈ ω+ for every h < g.
Therefore, S ⊆ ω+ SigR . If (g, a, b) ∈ ω+ SigR then a ∈ prg R. Hence there is ϱ ∈ R′
such that ϱ(g) = a. Suppose that ⟨ϱ′ , ϱ′′ ⟩ ω+ -witnesses the triple (g, a, b). We have to
show that there is ϱ′′′ such that the pair ⟨ϱ, ϱ′′′ ⟩ ω+ -witnesses (g, a, b). It is straightforward
that ϱ′′′ can be chosen to be m(ϱ, ϱ′ , ϱ′′ ), where m is a Mal’tsev polymorphism of H.
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
39
Algorithm ω-Signature
I NPUT: an instance G of #CSP(H), ω ∈ M , and τ ∈ Φ(G, H)/
(ω + 1)m
−
O UTPUT: a ω+ -signature of Φ(G, H, τ )
Step 1 find a compact representation R′ of Φ(G, H, τ ) using M AL’ TSEV
Step 2 set S := ∅ (the ω+ -signature of Φ(G, H, τ ))
Step 3 for each (g, a, b) ∈ [m] × H 2 do
Step 3.1 if there is ϱ ∈ R′ such that ϱ(g) = a then do
Step 3.1.1
find a compact representation R′′ of Φ(G ′ , H, τ ) where
G ′ = G ∪ {⟨1, ϱ(1)ω+ ⟩, . . . , ⟨g − 1, ϱ(g − 1)ω+ ⟩}
Step 3.1.2
if b ∈ prg R′′ then S := S ∪ {(g, a, b)}
endif
endfor
Step 5 return S
Fig. 12.
Algorithm Counting
I NPUT: an instance G of #CSP(H) such that Φ(G, H) is a subdirect power of H
O UTPUT: the number of homomorphisms from G to H, i.e. |Φ(G, H)|
Step 1 let τ be a (unique) mapping from G to H/
;
▽H
return Counting-mapping(G, (ℓ + 1)− , τ )
Fig. 13.
(2) By the definition, (g, a′ , b′ ) belongs to the signature of Φ(G, H, τ )/ω m if and only if
+
there are ϱ, ϱ′ ∈ Φ(G, H, τ ) such that ϱ(g)ω+ = a′ , ϱ′ (g)ω+ = b′ , and ⟨ϱ(h), ϱ′ (h)⟩ ∈ ω+
for all h < g. These conditions mean that the pair ⟨ϱ, ϱ′ ⟩ ω+ -witnesses that (g, ϱ(g), ϱ′ (g)) ∈
ω+ SigR.
6.3 The algorithm
We summarize results of the previous two subsections and present an algorithm solving
#CSP(H) for a congruence singular structure H, see Fig. 13, 14. The first of the presented algorithms just initiates a recursive process, while the second one implements the
method discussed in the two previous subsections. We assume that all information about
H required for the algorithm is known. This includes, for instance, congruences, types of
prime quotients, subalgebras generated by certain sets, etc. As usual, Z denotes the set of
s.
prime quotients of a maximal chain in Con(H)/∼
Comments on the algorithm. Classes of κ∗ω can be computed on Step 2.1 by exploring
a compact representation Q of Φ(G, H); such representation can be found by means of
the algorithm M AL’ TSEV. Equivalence relation κ∗ω is defined by binary projections of
Φ(G, H), that are relations generated by prg,h Q for g, h ∈ [m]. Set Jω contains those
κ∗ω -classes Au , for which projection prgu Φ(G, H, τ ) equals τ (gu ). Again, one can find a
compact representation of Φ(G, H, τ ) by applying algorithm M AL’ TSEV to the problem
G ∪ {⟨g, τ (g)⟩ | g ∈ [m]}. Finally, to find a solution ϱ ∈ Φ(G, H, τ )/ω ∗ on Step 3.1 it
+
suffices to compute a compact representation of Φ(G, H, τ ) in the same way as before, and
then for any member of the representation find the corresponding quotient mapping.
Journal of the ACM, Vol. V, No. N, 20YY.
40
·
Andrei A. Bulatov
Algorithm Counting-mapping
I NPUT: an instance G of #CSP(H) such that Φ(G, H) is a subdirect power of H,
a congruence θ ∈ {0+ , 1− , 1+ , . . . , ℓ+ , (ℓ + 1)− }, and a mapping τ of level θ
O UTPUT: the number |Φ(G, H, τ )|
Step 1 if θ = 0+ then return 1
Step 2 if θ = ω+ for some ω ∈ Z the do
Step 2.1 find the κ∗ω -classes A1 , . . . , Ak and choose their representatives g1 , . . . , gk ,
set Jω = {u1 , . . . , uq } ⊆ [k] as in Proposition 6.1, let C1u , . . . , Csuu be κω -classes
(we assume Jω = [q] and rename variables otherwise) belonging to τ (gu )λω for u ∈ J
Step 2.2 set r0 [1] := 1, . . . , r0 [q] := 1
Step 2.3 set t :=Counting-mapping(G, ω− , ϱr0 )
Step 2.4 for v = 1 to su1 do
Step 2.4.1
set r[1] := v and r[2] := 1, . . . , r[q] := 1
Step 2.4.2
t1v :=Counting-mapping(G, ω− , ϱr )
endfor
Step 2.5 for u = 2 to q do
Step 2.5.1
for v = 1 to su do
Step 2.5.1.1
set r[1] := 1, . . . , r[u − 1] := 1, r[u] := v, and r[u + 1] := 1, . . . , r[q] := 1
Step 2.5.1.2
set tu
v :=Counting-mapping(G, ω− , ϱr )
tu
v
Step 2.5.1.3
set tu
v :=
t
endfor
endfor(
)
q ∑
su
∏
Step 2.6 return
tu
v
u=1 v=1
endif
Step 3 else if θ = (ω + 1)− do
Step 3.1 find ϱ ∈ Φ(G, H, τ )/ m
ω+
Step 3.2 set t0 :=Counting-mapping(G, ω+ , ϱ)
Step 3.3 set S :=θ-Signature(G, τ, ω+ )
ω+ ω+
Step 3.4 set vg to
ηg -classes, ηg = {⟨a , b ⟩ | (g, a, b) ∈ S}
be the size of
m
∏
vg
Step 3.5 returnt0 ·
g=1
endif
Fig. 14.
Complexity. Observe that the depth of recursion of the algorithm is at most 2ℓ and does
not depend on the input. On each step considering a prime quotient of the Boolean case
the problem of finding the number |Φ(G, H, τ )| reduces to finding s1 + . . . + sk numbers
of the form |Φ(G, H, ϱ)|, where ϱ : G → H/ω . Since k ≤ m and each su does not
−
exceed |H|, every step of this kind requires solving at most |H|m smaller problems. On
each step considering an interval of the affine type computing |Φ(G, H, τ )| reduces to
solving a problem of the form |Φ(G, H, ϱ)|, ϱ : G → H/ω and finding the ω+ -signature
+
of Φ(G, H, τ ). To find the ω+ -signature the algorithm runs M AL’ TSEV at most m · |H|2
times. If the time complexity of algorithm M AL’ TSEV is bounded by a polynomial p(m)
(such a polynomial exists by [Bulatov and Dalmau 2006]), then the overall time complexity
of our algorithm is (|H|3 m2 · p(m))ℓ .
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
7.
·
41
#H -COLORING
Theorem 2.22 provides a complete classification of #P-complete and polynomial time solvable #H -C OLORING problems. However, it is difficult to express the criterion stated in the
theorem in terms of (di)graphs. By [Dyer and Greenhill 2000], an (undirected) graph H
gives rise to a polynomial time solvable #H -C OLORING problem if and only if every connected component of H is either trivial, or a complete bipartite graph, or a complete graph
with loops at all vertices. In [Bulatov and Dalmau 2007], we observed that an undirected
graph satisfies this condition if and only if it is invariant under a Mal’tsev operation.
In this section we compare the classification result from [Dyer et al. 2007] for directed
acyclic graphs (DAGs for short) with Theorem 2.22. We show that every congruence
singular DAG satisfies the Lovász-goodness condition introduced in [Dyer et al. 2007].
The two conditions must be equivalent, however, the converse implication probably uses
some nontrivial properties of pp-definitions in DAGs and remains an open problem. Note
that similar difficulties arise when we try to translate other general results on constraint
satisfaction problems for (di)graphs.
A DAG H = (V, E) is called layered if V can be partitioned into subsets V1 , . . . , Vℓ
such that for any (v, w) ∈ E we have v ∈ Vi , w ∈ Vi+1 for a certain i < ℓ. Let v ∈ Vi ,
w ∈ Vj , i < j. Then Hv∗ denotes the subgraph of H induced by the vertices u such that
there is a directed path from v to u; similarly, H∗w denotes the subgraph of H induced by
the vertices u such that there is a directed path from u to w; and Hvw = Hv∗ ∩ H∗w . The
vertex set of the graph Hxy Hx′ y′ , where Hxy = (V ′ , E ′ ) and Hx′ y′ = (V ′′ , E ′′ ), is the set
((V ′ ∩Vi )×(V ′′ ∩Vi ))∪. . .∪((V ′ ∩Vj )×(V ′′ ∩Vj )), a pair ((v, v ′ ), (w, w′ )) is an edge if
and only if (v, w) ∈ E ′ and (v ′ , w′ ) ∈ E ′′ . It is proved in [Dyer et al. 2007] that Hxy Hx′ y′
for x, x′ ∈ Vi and y, y ′ ∈ Vj has only one connected component that spans all layers from
i to j. If such main connected components of graphs Hxy Hx′ y′ and Hzt Hz′ t′ , z, z ′ ∈ Vi ,
t, t′ ∈ Vj , are isomorphic then we write Hxy Hx′ y′ ≡ Hzt Hz′ t′ . Finally a layered graph is
said to be Lovász-good if for any i, j, 1 ≤ i < j ≤ ℓ, and any x, x′ ∈ Vi , y, y ′ ∈ Vj we
have Hxy Hx′ y′ ≡ Hxy′ Hx′ y .
The key lemma for this result is a special case of the result of [Lovász 1967] that we
state in our notation.
L EMMA 7.1. If |Φ(G, H1 )| = |Φ(G, H2 )| for all graphs G then graphs H1 , H2 are
isomorphic.
We show that if H is congruence singular then |Φ(G, Hxy Hx′ y′ )| = |Φ(G, Hxy′ Hx′ y )|
for any x, x′ ∈ Vi , y, y ′ ∈ Vj , where 1 ≤ i < j ≤ ℓ, and any graph G. This implies
that Hxy Hx′ y′ and Hxy′ Hx′ y are isomorphic, and so Hxy Hx′ y′ ≡ Hxy′ Hx′ y . We use an
observation made in [Dyer et al. 2007] that |Φ(G, H1 H2 )| = |Φ(G, H1 )| · |Φ(G, H2 )|. If
G = (W, F ) is not layered then |Φ(G, Hxy Hx′ y′ )| = |Φ(G, Hxy′ Hx′ y )| = 0. Let W1 , W2
denote the set of vertices on the highest and on the lowest layers of G, respectively. As we
know, Φ(G, H) is a relation pp-definable in H. Now, let η1 , η2 be congruences of Φ(G, H)
such that ⟨φ, φ′ ⟩ ∈ ηi , i = 1, 2, iff φ(v) = φ′ (v) for all v ∈ Wi . It is not hard to see that
sets of the form Hu∗ are classes of η1 , sets of the form H∗w are classes of η2 , and sets of
the form Huw are classes of η1 ∧ η2 (although there are classes of those congruences not
representable in the form Hu∗ , H∗w , or Huw ). Since H is congruence singular, we have
Journal of the ACM, Vol. V, No. N, 20YY.
42
·
Andrei A. Bulatov
rank(M (η1 , η2 )) = k where k is the number of classes in η1 ∨ η2 . Hence
|Φ(G, Hxy )| |Φ(G, Hxy′ )| |Φ(G, Hx′ y )| |Φ(G, Hx′ y′ )| = 0,
or Φ(G, Hxy ), Φ(G, Hx′ y′ ) or Φ(G, Hxy′ ), Φ(G, Hx′ y ) are in different classes of η1 ∨ η2 .
In the latter case either |Φ(G, Hx′ y )| = |Φ(G, Hxy′ )| = 0 or |Φ(G, Hxy )| = |Φ(G, Hx′ y′ )| =
0. The result follows.
Observe that in this argument congruence singularity is used in a very restricted way:
only projection congruences of somewhat restricted type are used.
8.
CONCLUDING REMARKS AND OPEN PROBLEMS
The result obtained in the paper is rather general. It includes as particular case the results
of [Creignou and Hermann 1996; Dyer and Greenhill 2000; Diaz et al. 2001; Dyer et al.
2007; Klı́ma et al. 2006]. However, those results are stated in terms of particular problems,
and deriving them from Theorem 2.22 requires extra research.
P ROBLEM 2. Characterize congruence singular digraphs.
We also should note that in some cases, e.g., [Dyer and Greenhill 2000], the #P-completeness results obtained for particular problems are stronger than those which follow from
our result. For instance, #P-complete #H -C OLORING problems in the case of undirected
graphs remain #P-complete even when restricted to inputs of bounded degree.
P ROBLEM 3. Let H be a relational structure that is not congruence singular. Does
the problem #CSP(H) remains #P-complete when restricted to the class of structures of
bounded degree? a class of structures with other natural restrictions?
A major question left unanswered in this paper is how to check if a given relational structure is congruence singular. A solution to this problem was found in [Dyer and Richerby
2011] along with an alternative characterization of polynomial time solvable #CSPs: The
problem of deciding, given a relational structure H whether #CSP(H) is polynomial time,
belongs to NP.
REFERENCES
BARTO , L., KOZIK , M., AND N IVEN , T. 2008. Graphs, polymorphisms and the complexity of homomorphism
problems. In STOC. 789–796.
BARTO , L. 2008. The dichotomy for conservative constraint satisfaction problems revisited. In LICS. 301–310.
B ODNARCHUK , V., K ALUZHNIN , L., KOTOV, V., AND ROMOV, B. 1969. Galois theory for Post algebras. I.
Kibernetika 3, 1–10.
B RIGHTWELL , G. AND W INKLER , P. 1999. Graph homomorphisms and phase transitions. Journal of Combinatorial Theory, Ser. B 77, 221–262.
B UBLEY, R., DYER , M., G REENHILL , C., AND J ERRUM , M. 1999. On approximately counting colourings of
small degree graphs. SIAM Journal of Computing 29, 387–400.
B ULATOV, A. A. 2002b. Mal’tsev constraints are tractable. Tech. Rep. PRG-RR-02-05, Computing Laboratory,
University of Oxford, Oxford, UK.
B ULATOV, A. A. 2003. Tractable conservative constraint satisfaction problems. In LICS. 321–330.
B ULATOV, A. A. AND G ROHE , M. 2004. The complexity of partition functions. In ICALP. 294–306.
B ULATOV, A. A. AND J EAVONS , P. 2001. Algebraic approach to multi-sorted constraints. Tech. Rep. PRG-RR01-18, Computing Laboratory, University of Oxford, Oxford, UK.
B ULATOV, A. A. AND J EAVONS , P. 2003. An algebraic approach to multi-sorted constraits. In CP. 197–202.
B ULATOV, A. A. 2006. Three-element Mal’tsev algebras. Acta Sci. Math. (Szeged) 72, 519–550.
Journal of the ACM, Vol. V, No. N, 20YY.
The Complexity of the Counting CSP
·
43
B ULATOV, A. A. 2006. A dichotomy theorem for constraint satisfaction problems on a 3-element set. J.
ACM 53 1, 66–120.
B ULATOV, A. A. AND DALMAU , V. 2006. A simple algorithm for Mal’tsev constraints. SIAM J. Comput. 36, 1,
16–27.
B ULATOV, A. A. AND DALMAU , V. 2007. Towards a dichotomy theorem for the counting constraint satisfaction
problem. Information and Computation 205, 5, 651–678.
B ULATOV, A. A. AND G ROHE , M. 2005. The complexity of partition functions. Theoretical Computer Science 348, 2-3, 148–186.
B ULATOV, A. A., J EAVONS , P., AND K ROKHIN , A. A. 2005. Classifying the complexity of constraints using
finite algebras. SIAM Journal on Computing 34, 3, 720–742.
B ULATOV, A. A. 2011. Complexity of conservative constraint satisfaction problems. ACM Trans. Comput.
Log. 12 4, 43–109.
B URRIS , S. AND S ANKAPPANAVAR , H. 1981. A course in universal algebra. Graduate Texts in Mathematics,
vol. 78. Springer-Verlag, New York-Berlin.
B URTON , R. AND S TEIF, J. 1994. Nonuniqueness of measures of maximal entropy for subshifts of finite type.
Ergodic Theory and Dynamical Systems 14, 213–236.
C AI , J., L U , P., AND X IA , M. 2008. Holographic algorithms by Fibonacci gates and holographic reductions for
hardness. In FOCS. 644–653.
C AI , J. AND L U , P. 2011. Holographic algorithms: From art to science. J. Comput. Syst. Sci. 77 1, 41–61.
C REIGNOU , N. AND H ERMANN , M. 1996. Complexity of generalized satisfiability counting problems. Information and Computation 125, 1, 1–12.
C REIGNOU , N., K HANNA , S., AND S UDAN , M. 2001. Complexity Classifications of Boolean Constraint Satisfaction Problems. SIAM Monographs on Discrete Mathematics and Applications, vol. 7.
D IAZ , J., S ERNA , M., AND T HILIKOS , D. 2001. Counting list H-colorings and variants. Tech. Rep. LSI-0127-R, Departament LSI, Universitat Politècnica de Catalunya.
D IAZ , J., S ERNA , M., AND T HILIKOS , D. 2002. Counting H-colorings of partial k-trees. Theoretical Computer
Science 281, 291–309.
D IAZ , J., S ERNA , M., AND T HILIKOS , D. 2004. DIMACS/DIMATIA Workshop on Graphs, Morphism and
Statistical Physics. DIMACS Series in Discrete Mathematics and Theoretical Computer Science Chapter.
Recent results on parameterized H-coloring. American Mathematical Society.
2005. D IAZ , J., S ERNA , M., AND T HILIKOS , D. The restrictive H-coloring. Discrete Applied Mathematics 145, 2, 297–305.
D ONNER , Q. 1992. On the number of list H-colorings. J. Graph Theory 16, 3, 239–245.
DYER , M., F RIEZE , A., AND J ERRUM , M. 2002. On counting independent sets in sparse graphs. SIAM Journal
on Computing 31, 1527–1541.
DYER , M., G OLDBERG , L. A., G REENHILL , C., AND J ERRUM , M. 2003. On the relative complexity of approximate counting problems. Algorithmica 38, 3, 471–500.
DYER , M., G OLDBERG , L. A., AND PATERSON , M. 2007. On counting homomorphisms to directed acyclic
graphs. J. ACM 54, 6.
DYER , M. AND G REENHILL , C. 2000. The complexity of counting graph homomorphisms. Random Structures
and Algorithms 17, 260–289.
DYER , M. E., G OLDBERG , L. A., AND J ERRUM , M. 20010. An approximation trichotomy for Boolean #CSP.
J. Comput. Syst. Sci. (JCSS) 76, 3-4, 267–277.
DYER , M. E., G OLDBERG , L. A., AND J ERRUM , M. 2009. The complexity of weighted Boolean #CSP. SIAM
J. Comput. 38, 5, 1970–1986.
DYER , M.,AND R ICHERBY, D. 2011. The #CSP dichotomy is decidable. In STACS. 261–272.
F EDER , T. AND VARDI , M. 1998. The computational structure of monotone monadic SNP and constraint
satisfaction: A study through datalog and group theory. SIAM Journal of Computing 28, 57–104.
F REEDMAN , M., L OV ÁSZ , L., AND S CHRIJVER , A. 2007. Reflection positivity, rank connectivity, and homomorphism of graphs. J. Amer. Math. Soc. 20, 1, 37–51.
F REESE , R. AND M C K ENZIE , R. 1987. Commutator theory for congruence modular varieties. London Math.
Soc. Lecture Notes, vol. 125. London.
G EIGER , D. 1968. Closed systems of function and predicates. Pacific Journal of Mathematics, 95–100.
Journal of the ACM, Vol. V, No. N, 20YY.
44
·
Andrei A. Bulatov
G R ÄTZER , G. 2003. General Lattice Theory. Birkhäuser Verlag, Basel.
G REENHILL , C. 2000. The complexity of counting colourings and independent sets in sparse graphs and hypergraphs. Computational Complexity 9, 52–73.
G UMM , H.-P. 1979. Algebras in permutable varieties: geometrical properties of affine algebras. Algebra Universalis 9 1, 8–34.
H ELL , P. AND N E ŠET ŘIL , J. 2004. Counting list homomorphisms for graphs with bounded degrees. In Graphs,
Morphisms and Statistical Physics. DIMACS Series in Discrete Mathematics and Theoretical Computer Science 63, 105–112.
H ELL , P. AND N E ŠET ŘIL , J. 1990. On the complexity of H-Coloring. Journal of Combinatorial Theory,
Ser.B 48, 92–110.
H OBBY, D. AND M C K ENZIE , R. 1988. The Structure of Finite Algebras. Contemporary Mathematics, vol. 76.
American Mathematical Society, Providence, R.I.
H UNT III, H., M ARATHE , M., R ADHAKRISHNAN , V., AND S TEARNS , R. 1998. The complexity of planar
counting problems. SIAM Journal on Computing 27, 1142–1167.
I DZIAK , P., M ARKOVIC , P., M C K ENZIE , R., VALERIOTE , M., AND W ILLARD , R. 2007. Tractability and
learnability arising from algebras with few subpowers. SIAM J. Comput. 39, 7, 3023–3037.
J EAVONS , P. 1998. On the algebraic structure of combinatorial problems. Theoretical Computer Science 200,
185–204.
J EAVONS , P., C OHEN , D., AND C OOPER , M. 1998. Constraints, consistency and closure. Artificial Intelligence 101, 1-2, 251–265.
J ERRUM , M. AND S INCLAIR , A. 1996. The Markov chain Monte Carlo method: an approach to approximate
counting and integration. In Approximation Algorithms for NP-hard Problems. PSW, 482–520.
J ONSSON , B. AND R IVAL ,I. 1979. Lattice varieties covering the smallest non-modular variety. Pacific J. of
Math. 82, 2, 1129–1133.
K L ÍMA , O., L AROSE , B., AND T ESSON , P. 2006. Systems of equations over finite semigroups and the #CSP
dichotomy conjecture. In MFCS. 584–595.
L EBOWITZ , J. AND G ALLAVOTTI , G. 1971. Phase transitions in binary lattice gases. Journal of Math.
Physics 12, 1129–1133.
L EVIN , L. 1973. Universal enumeration problems. Problems on Information Transmission 9, 265–266.
L INIAL , N. 1986. Hard enumeration problems in geometry and combinatorics. SIAM Journal on Algebraic and
Discrete Methods 7, 2, 331–335.
L OV ÁSZ , L. 1967. Operations with structures. Acta. Math. Acad. Sci. Hung. 18, 321–328.
L OV ÁSZ , L. 2006. The rank of connection matrices and the dimension of graph algebras. European Journal of
Combinatorics 27, 6, 962–970.
M C K ENZIE , R., M C N ULTY, G., AND TAYLOR , W. 1987. Algebras, Lattices and Varieties. Vol. I. Wadsworth
and Brooks, California.
N ORDH , G. AND J ONSSON , P. 2004. The complexity of counting solutions to systems of equations over finite
semigroups. In COCOON. 370–379.
O RPONEN , P. 1990. Dempster’s rule of combination is #P-complete. Artificial Intelligence 44, 245–253.
P ROVAN , J. AND BALL , M. 1983. The complexity of counting cuts and of computing the probability that a
graph is connected. SIAM Journal on Computing 12, 4, 777–788.
ROTH , D. 1996. On the hardness of approximate reasonning. Artificial Intelligence 82, 273–302.
S CHAEFER , T. 1978. The complexity of satisfiability problems. In STOC. 216–226.
S ZENDREI , A. 1986. Clones in universal algebra. Séminaire de Mathématiques Supérieures, 99. Presses de
l’Université de Montréal.
VADHAN , S. 2001. The complexity of counting in sparse, regular and planar graphs. SIAM Journal on Computing 31, 2, 398–427.
VALIANT, L. 1979a. The complexity of computing the permanent. Theoretical Computing Science 8, 189–201.
VALIANT, L. 1979b. The complexity of enumeration and reliability problems. SIAM Journal on Computing 8, 3,
410–421.
Journal of the ACM, Vol. V, No. N, 20YY.
© Copyright 2026 Paperzz