Counting Homomorphisms to Trees Modulo a Prime
Many important graph theoretic notions can be encoded as counting graph homomorphism problems, such as partition functions in statistical physics, in particular independent sets and colourings. In this article we study the complexity of , the problem of counting graph homomorphisms from an input graph to a graph modulo a prime number . Dyer and Greenhill proved a dichotomy stating that the tractability of non-modular counting graph homomorphisms depends on the structure of the input graph. Many intractable cases in non-modular counting become tractable in modular counting due to the common phenomenon of cancellation. However, in subsequent studies on counting modulo the influence, the structure of has on the tractability, was shown to persist, yielding similar dichotomies.
Our main result shows that for every tree and every prime the problem is either polynomial time computable or -complete. This addresses the conjecture of Faben and Jerrum stating this dichotomy for every graph when counting modulo 2. In order to prove this result, we study the structural properties of a homomorphism. As an important interim, this study yields a dichotomy for the problem of weighted counting independent sets in a bipartite graph modulo some prime . Our results are the first suggesting that such dichotomies hold not only for the one-bit functions of the modulo 2 case but for the modular counting functions of all primes .
m o o \IfNoValueTF#2 \IfNoValueTF#3 \IfNoValueTF#3 \DeclareDocumentCommand\Patho o \IfNoValueTF#1 \IfNoValueTF#2 \IfNoValueTF#2
Graph homomorphisms generate a powerful language expressing important notions; examples include constraint satisfaction problems and partition functions in statistical physics. As such, the computational complexity of graph homomorphism problems has been studied extensively from a wide range of angles. Early results include that of Hell and Nešetřil , who study the complexity of ,the problem of deciding whether there exists a homomorphism from an input graph to a fixed graph . They show the following dichotomy: if is bipartite or has a loop, the problem is in and in every other case is -complete. This contrasts a result of Ladner , showing that if , then there exist problems that are neither in nor -hard.
Dyer and Greenhill  show a dichotomy for the problem , the problem of counting the homomorphisms from an input graph to . Their theorem states that is tractable if is a complete bipartite graph or a complete graph with loops on all vertices; otherwise is -complete. This dichotomy was progressively extended to weighted sums of homomorphisms with integer weights, by Bulatov and Gohe ; with real weights, by Goldberg et al. ; finally, with complex weights, by Cai, Chen and Lu . The work of Curticapean, Dell and Marx  studies the complexity of counting graph homomorphisms from a different point of view, when the parameter is the source graph and the input is the target graph. However, we examine graph homomorphism problems under the classical setting, where the input is the source graph and the parameter is the target graph. We study the complexity of counting homomorphisms modulo a prime . Let be the set of homomorphisms from the input graph to the target graph . For each pair of fixed parameters and , we study the computational problem , that is the problem of computing modulo . The value of and the structure of the target graph influence the complexity of . Consider the graph in Figure 1. Our results show that is computable in polynomial time when while it is hard for any other prime .
Our main goal is to fully characterise the complexity of in a dichotomy theorem. In this manner we aim to determine for which pair of parameters the problem is tractable and show that for every other pair of parameters the problem is hard. As the theorem of Ladner  extends to the modular counting problems, it is not obvious that there are no instances of with an intermediate complexity.
The first study of graph homomorphisms under the setting of modular counting has been conducted by Faben and Jerrum . Their work is briefly described in the following and we assume the reader to be familiar with the notion of an automorphism and its order. We provide the formal introduction in Section 2. Given a graph and an automorphism of , denotes the subgraph of induced by the fixpoints of . We write if there is an automorphism of order of such that and we write if either is isomorphic to (written ) or, for some positive integer , there are graphs such that , , and .
Faben and Jerrum showed [11, Lemma 3.3] that if the order of is a prime , is equivalent to modulo . Furthermore they showed [11, Theorem 3.7] that, there is (up to isomorphism) exactly one graph that has no automorphisms of order such that . This graph is called the order reduced form of . If falls into the polynomial computable cases of the theorem of Dyer and Greenhill, then is computable in polynomial time as well. For , Faben and Jerrum conjectured that these are the only instances computable in polynomial time.
Conjecture 1.1 (Faben and Jerrum ).
Let be a graph. If its order 2 reduced form has at most one vertex, then is in ; otherwise, is -complete.
Faben and Jerrum [11, Theorem 3.8] underlined their conjecture by proving it for the case in which is a tree. In subsequent works this proof was extended to cactus graphs in  and to square-free graphs in  by Göbel, Goldberg and Richerby.
The present work follows a direction orthogonal to the aforementioned work. Instead of proving the conjecture for richer classes of graphs, in our main theorem, we show a dichotomy for all primes, starting again by restricting the target graph .
Let be a prime and let be a graph, such that, its order reduced form is a tree. If is a star, is computable in polynomial time, otherwise is -complete.
Our results are the first to suggest that the conjecture of Faben and Jerrum might apply to counting graph homomorphisms modulo every prime instead of counting modulo 2. This suggestion, however, remains hypothetical. Borrowing the words of Dyer, Frieze and Jerrum : “One might even rashly conjecture” it “(though we shall not do so)”.
To justify our title we give the following corollary, stating a dichotomy for all trees .
Let be a prime and let be a tree. If the order reduced form of is a star, is computable in polynomial time, otherwise is -complete.
We illustrate Theorem 1.2 using the following discussion on Figure 1. The order 2 and the order 3 reduced form of both are the graph with one vertex, whereas for any other prime the graph stays as such.
The reductions in [11, 14, 13] show hard instances of by starting from , the problem of computing, modulo 2, the cardinality of , the set of independent sets of . was shown to be complete by Valiant . Later on, Faben  extended this result by proving to be -complete for all integers . For reasons to be explained later on, in Section 1.3, we do not use this problem as a starting point for our reductions.
Instead, we turn our attention to the problem of counting the independent sets of a bipartite graph modulo . In the same work Faben  includes a construction to show hardness for . We employ the weighted version as a starting point for our reduction and hence, further extend the research on .
Parameter. prime and .
Input. Bipartite graph .
In fact, we obtain the following dichotomy.
Let be a prime and let , . If or , then is computable in polynomial time. Otherwise, is -complete.
Section 1.1 provides background knowledge on modular counting. In Section 1.2 we will discuss some related work. The technical obstacles arising from values of the modulo are explained in Section 1.3. Additionally, in the same section, we explain how we overcome them by generalising the techniques used for the case . Finally, in Section 1.4 we discuss the limits of our techniques, which do not yield a dichotomy modulo any integer .
1.1 Modular counting
Modular counting was originally studied from the decision problem’s point of view. Here, the objective is to determine whether the number of solutions is non-zero modulo . The complexity class was first studied by Papadimitriou and Zachos  and by Goldschlager and Parberry . consists of all problems of the form “is odd or even?”, where is a function in . A result of Toda  states that every problem in the polynomial time hierarchy reduces in polynomial time to some problem in . This result suggests that -completeness represents strong evidence for intractability.
In our study modular counting is considered from the computing function’s point of view. For an integer the complexity class consists of all problems of the form “compute modulo ”, where is a function in . In the special case of , , as the instances of require a one bit answer. Throughout this paper though, instead of the more traditional notation , we will use to emphasise our interest in computing functions.
If a counting problem can be solved in polynomial time, the corresponding decision and modular counting problems can also be solved in polynomial time. The converse, though, does not necessarily hold. This is because efficient counting algorithms rely usually on an exponential number of cancellations that occur in the problem, e.g. compute the determinant of a non-negative matrix. The modulo operator introduces a natural setting for such cancellations to occur.
For instance consider the -complete problem of counting proper -colourings of a graph in the modulo (or even modulo ) setting. -colourings of a graph assigning all three colours can be grouped in sets of size , since there are permutations of the colours. Thus, the answer to these instances is always a multiple of , and therefore “cancels out”. It remains to compute the number of -colourings assigning less than colours. For the case of using exactly colours we distinguish the following two cases: is not bipartite and there are no such colourings; is bipartite and the number of -colourings of that use exactly colours is , where is the number of components of . Finally, computing the number of proper -colourings of that use exactly one colour is an easy task. Either has an edge and there are no such colourings, or has no edges and for every vertex there are colours to choose from.
Valiant  observed a surprising phenomenon in the tractability of modular counting problems. He showed that for a restricted version of -SAT computing the number of solutions modulo is in , but computing this number modulo is -complete. This mysterious number was later explained by Cai and Lu , who showed that the -SAT version of Valiant’s problem is tractable modulo any prime factor of .
1.2 Related work
We have already mentioned earlier work on counting graph homomorphisms and counting graph homomorphisms modulo 2. In this section we highlight the work of Guo et al.  on the complexity of the modular counting variant of the constraint satisfaction problem.
Parameter. and a set of functions , where for each , and .
Input. Finite set of constraints over Boolean variables of the form
Their results prove a dichotomy theorem [17, Theorem 4.1] for , when the domain of the functions in is restricted to the Boolean domain .
Constraint satisfaction problems, when the domain of the constraint functions is arbitrarily large, generalise graph homomorphism problems. In order to illustrate that is a generalisation of , let be an input for for which we describe an equivalent instance. The domain of the constraint satisfaction problem is and contains a single binary relation , with when and otherwise. Thus, is an instance of . The input of contains a variable for every vertex and a constraint for every edge . As can be observed from the construction, every valid homomorphism corresponds to an assignment of the variables satisfying every constraint in the CSP.
We mention, that the results of Guo et al. are incomparable to ours. We consider prime values of the modulo and a single binary relation, however the domain of our relations is arbitrarily large.
1.3 Beyond one-bit functions
Similar to the existing hardness proofs on modular counting graph homomorphisms we deploy a “pinning” technique. A partial function from a set to a set is a function for some . For any graph , a partially -labelled graph consists of an underlying graph and a pinning function , which is a partial function from to . A homomorphism from a partially labelled graph to is a homomorphism such that, for all vertices , . The resulting problem is denoted by , that is, given a prime and graph , compute . In Section 5, we show that reduces to . This allows us to establish hardness for , by proving hardness for . The reduction generalises the pinning reduction of Göbel, Goldberg and Richerby  from to .
We explain how to prove pinning when we restrict the pinning function , to “pin” a single vertex and the value of the modulo to 2. Given a graph with a distinguished vertex and a graph , we define to be the -vector containing the entries for each vertex . Observe that, for two vertices , such that , and any graph the relevant entries in will always be equal. Therefore, we can contract all such entries to obtain the orbit vectors . Suppose that there exists a graph with a distinguished vertex , such that , where the 1-entry corresponds to the vertex of . Given our input for , we can now define an input for , such that . contains a disjoint copy of and , where the vertices and are identified (recall that is the vertex of mapped by ). Due to the value of and the structure of , there is an even number of homomorphisms mapping to any vertex , which establishes the claim.
However, such a graph is not guaranteed to exist. Instead, we can define a set of operations on the vectors corresponding to graph operations and show that for any vector in there exist a sequence of graphs with distinguished vertices that generate this vector. Thus, there exists a set of graphs that generate , which yields the desired reduction. This technique of  exploits the value of the modulo to be 2. Applying this technique to counting modulo any prime directly, one can establish pinning for asymmetric graphs. A dichotomy for , when is an asymmetric tree appears in the first author’s doctoral thesis .
In order to go beyond asymmetric graphs, one has to observe that information redundant only in the modulo 2 case, is lost from the contraction of the vectors to the vectors . This works on asymmetric graphs, since then these two vectors are identical. By utilising the non-contracted vectors , we are able to, eventually, restore pinning for counting homomorphisms modulo any prime .
Let be a prime and let be a graph. Then reduces to via polynomial time Turing reduction.
We note that our pinning theorem applies to all primes and all graphs , so it does not restrict the family of target graphs to trees. The formal proofs outlined above are contained in Section 5.
Gadgets are structures appearing in the target graph that allow to reduce to (the hardness of is then immediate from Theorem 1.7). For illustrative purposes we simplify the definitions appearing in . Gadgets for consist of two partially labelled graphs with distinguished vertices , along with two “special” vertices . Given the input for , we construct an input for as follows. We attach a copy of to every vertex of (identifying with ) and replace every edge of with a copy of (identifying with and with ). The properties of ensure that there is an odd number of homomorphisms from to where the original vertices of are mapped to or , while the number of the remaining homomorphisms cancels out. The properties of ensure that there is an even number of homomorphisms from to when two adjacent vertices of are both mapped to , and an odd number of homomorphisms in every other case. We can now observe that , as the set of homomorphisms that does not cancel out must map every vertex of to or and no adjacent vertices both to . Every vertex of that is in an independent set must be mapped to , and every vertex that is out of the independent set must be mapped to .
Following the described approach one would end up reducing from a restricted instance, where a unary weight function must be applied to every variable of the instance (this is known as external field in statistical physics). Instead we choose a different approach and reduce from . This seems to capture the structure that produces hardness in in a more natural way.
We formally present our reduction in Section 6. In the following we sketch our proof method and focus our attention on the example graph in Figure 1. Let be a bipartite graph. Homomorphisms from to must respect the partition of , i.e. the vertices in can only be mapped to the vertices in and the vertices in can only be mapped to the vertices in , or vice versa. Any homomorphism from to , which maps the vertex to any vertex in , must map every neighbour of to . Similarly, any homomorphism from to , which maps the vertex to any vertex in , must map every neighbour of to . Thus, homomorphisms from to express independent sets of : represent the vertices of in the independent set and represent the vertices of in the independent set, or vice versa. We construct a partially labelled graph from to fix the choice of and in the set of homomorphisms from to . contains a copy of , where every vertex in is attached to the new vertex and every vertex in is attached to the new vertex . In addition, is the pinning function. We observe now that the vertices in can only be mapped to vertices in and vertices in can only be mapped to vertices in . This observation yields that the number of homomorphisms from to is equivalent to . Furthermore, the cardinality of the sets and introduces weights in a natural way.
For the reduction above, we need the following property easily observable in : there exist two adjacent vertices of degree and . Recall that in order to obtain hardness for Theorem 1.5 requires . In fact, as we will show in Section 6, these vertices need not be adjacent. During the construction of , we can replace the edges of with paths of appropriate length. We call such a structure in an -path. In Lemma 6.7 we formally prove that if has an -path, then is hard. Observe that stars cannot contain -paths. Finally, we show that every non-star tree contains an -path, which yields our main result on (Lemma 6.2).
Weighted bipartite independent sets
Consider a bipartite graph and let (the case is symmetric). We observe that every independent set which contributes a non-zero summand to can only contain vertices in ( is defined in Problem 1). This yields the closed form , which is computable in polynomial time. Regarding the case , we employ a generalisation of a reduction used by Faben. In [9, Theorem 3.7], Faben reduces the “canonical” -complete problem to the problem of counting independent sets of a bipartite graph.
We have to generalise this reduction for the weighted setting, in particular allowing different vertex weights for the vertices of each partition. Furthermore, during the construction we have to keep track of the assignment of vertices to their corresponding part, or . For this purpose we need to show the existence of bipartite graphs , where takes specific values. These graphs are then used as gadgets in our reduction. In the unweighted setting () the graphs are complete bipartite graphs. However, in the weighted setting () complete bipartite graphs are not sufficient. Therefore, we prove the existence of the necessary bipartite gadgets constructively. The technical proofs appear in Section 3.
We outline the obstacles occurring when extending the dichotomy for to any integer . Let be a graph and let , where be an integer with its prime factorisation. Assuming can be solved in polynomial time, then for each , can also be solved in polynomial time. The reason is that is a factor of and we can apply the modulo operator to the answer for the instance. The Chinese remainder theorem, (Theorem 8.1) shows that the inverse is also true: if for each we can solve in polynomial time, then we can also solve in polynomial time. Now we focus on powers of primes . Assuming is computable in polynomial time yields again that is also computable in polynomial time. However, the inverse is not always true.
Guo et al.  were able to obtain this reverse implication for the constraint satisfaction problem. They showed [17, Lemma 4.1 and Lemma 4.3] that, when is a prime, is computable in polynomial time if is computable in polynomial time. In Section 8 we show that their technique cannot be transferred to the setting. We show that there is a graph () such that is computable in polynomial time, while is -hard.
Our notation is introduced in Section 2. In Section 3 we study the complexity of the weighted bipartite independent sets problem modulo any prime. Section 4 presents the connection to the polynomial time algorithm of Faben and Jerrum for . Our pinning method is explained in Section 5. Section 6 contains the hardness reduction for . Our results are collected into a dichotomy theorem in Section 7. Finally, in Section 8 we discuss the obstacles arising when counting modulo all integers.
We denote by the set . Further, if is an element of the set , we write for . Let be a positive integer , then for a function its -fold composition is denoted by .
For a detailed introduction to Graph Theory the reader is referred to .
Unless otherwise specified, graphs are undirected and simple, requiring them to contain neither parallel edges nor loops. More formally, a graph is a pair , where denotes the set of vertices and the set of edges formed by pairs of vertices. This set of edges can be looked upon as a relation for a pair of vertices to either form an edge or not in . For a graph we sometimes denote its vertex set by and its edge set by . As stated above, for all vertices we require the edges to be undirected, that is if and only if Moreover, for an edge the condition ensures the absence of loops. A graph is a subgraph of if and . This is denoted by . If additionally such that implies that we call an induced subgraph. In fact, is then induced by the subset . For all vertices of a graph with a subgraph we denote by the neighbourhood of in containing all vertices in adjacent to , which refers to the Greek term ΓειτονιÃ¡. Consequently, we denote by the size of .
A path is a simple graph such that all its vertices can be ordered in a list without multiples and only two adjacent vertices in the list form an edge in . The length of a path is its number of edges. Two vertices in a graph are connected if there exists a path , such that . Otherwise the vertices are disconnected. If every pair of vertices in a graph is connected, then is called connected. Otherwise it is called disconnected. We call a subgraph a connected component of , if is connected and there exists no vertex such that is connected to any vertex in . An independent set of a graph is a set of vertices , such that no pair of vertices in is connected in . The distance of two connected vertices in , denoted by , is the length of a shortest path in connecting and . A cycle is a simple connected graph , such that all its vertices can be ordered in a list and only two vertices adjacent in the list form an edge. A tree is a simple connected graph, which does not contain cycles. For an integer a -walk is a list , which might contain multiples, such that two adjacent vertices in the list form an edge.
A graph is bipartite if there exist disjoint subsets , of such that and there exists no edge with or . We write for the bipartite graph with fixed components and , which we are calling the left and right component, respectively. For an integer the complete graph of size is the simple graph with and every pair of distinct vertices in forms an edge. Similarly, for integers the complete bipartite graph is the simple bipartite graph with and and every pair of vertices , forms an edge. A star is a complete bipartite graph for some integer .
Let and be graphs. A homomorphism from to is a function , such that edges are preserved, for short implies . Moreover, denotes the set of homomorphisms from to . An isomorphism between and is a bijective function preserving the edge relation in both directions, meaning if and only if . If such an isomorphism exists, we say that is isomorphic to and denote it with . An automorphism of is an isomorphism from the graph to itself. denotes the automorphism group of . An automorphism is an automorphism of order in case it is not the identity and is the smallest positive integer such that is the identity.
Partially labelled graphs
Let be a graph. A partially -labelled graph consists of an underlying graph and a (partial) pinning function , mapping vertices in to vertices in . Every vertex in the domain of is said to be -pinned to . We omit in case it is immediate from the context. We denote a partial function with finite domain also in the form . A homomorphism from a partially labelled graph to a graph is a homomorphism from to that respects , i.e., for all holds . By we denote the set of homomorphisms from to .
Graphs with distinguished vertices
Let and be a graphs. It is often convenient to regard a graph with a number of (not necessarily distinct) distinguished vertices , which we denote by . A sequence of vertices may be abbreviated by and stands for the subgraph of induced by the set of vertices . A homomorphism from to with is a homomorphism from to with for each . Such a homomorphism immediately yields a homomorphism from the partially labelled graph to and vice versa. For a partially labelled graph and vertices , we identify a homomorphism from to with the corresponding homomorphism from to . Similarly, and are isomorphic if and there is an isomorphism from to , such that for each . An automorphism of is an automorphism of with the property that for each and denotes the automorphism group of .
For a detailed discussion of this topic see . Our model of computation is the standard multitape Turing machine. For counting problems and , we say that reduces to via polynomial time Turing reduction, if there is a polynomial time deterministic oracle Turing machine such that, on every instance of , outputs by making queries to oracle . Further, reduces to via parsimonious reduction, if there exists a polynomial time computable function transforming every instance of to an instance of , such that . Clearly, if reduces to via parsimonious reduction, then also reduces to via polynomial time Turing reduction.
For an introduction to abstract algebra we refer the reader to . Finally, we assume familiarity with the notion of a group, an action of a group on a set and modular arithmetic in the field , where is a prime in . We are going to apply Fermat’s little theorem (see [1, Theorem 11.6]) and Cauchy’s group theorem (see, e.g., [1, Theorem 13.1]) frequently.
Theorem 2.1 (Fermat’s little theorem).
Let be a prime. If is not a multiple of , then .
Theorem 2.2 (Cauchy’s group theorem).
Let be prime. If is a finite group and divides , then contains an element of order .
3 Weighted bipartite independent set
We study the complexity of computing the weighted sum over independent sets in a bipartite graph modulo a prime. This weighted sum is denoted by , where are weights the vertices of each partition contribute. For this, the input bipartite graphs come with a fixed partitioning of their vertices. Note that the set of independent sets of a graph does not change if the graph contains multiedges and further note that a bipartite graph cannot contain loops. For this reason, in this section we do not have to distinguish between a bipartite multigraph or a bipartite simple graph.
For a graph let denote the set of independent sets of . Faben [9, Theorem 3.7] shows that the problem of counting the independent sets of a graph modulo an integer is hard, even when the input graph is restricted to be bipartite.
Theorem 3.1 (Faben).
For all positive integers , is -complete.
Let be a prime and , we will study the complexity of computing the following weighed sum over independent sets of a bipartite graph modulo
We note that every bipartite graph contains a partition and declaring a bipartite graph with is the same as having the graph along with the partition as input. A given partition is necessary when studying weighted independent, since changing the partitioning changes the value of the weighted sum. In the unweighted sum of Theorem 3.1, there is no need to give a fixed partition as input, as it does not change the number of independent sets.
More formally, we study the following problem.
Parameter. prime and .
Input. Bipartite graph .
As a note, corresponds to the special case . Theorem 3.1 directly implies that is -complete for all primes .
We begin by identifying the tractable instances of .
If or then is computable in polynomial time.
Without loss of generality we assume . Thus, any independent set that contains at least one vertex from contributes zero to the sum in . Therefore, we only need to consider the independent sets with . Since any subset of yields an independent set, we obtain
which can be computed in polynomial time. ∎
The remainder of the section is dedicated to proving that is hard in all other cases. Our reduction is inspired by the reduction of Faben in [9, Theorem 3.7].
In the proofs that follow, to avoid double counting, it is useful to partition the independent sets in the following way.
Let be a bipartite graph. We denote by the set of non-empty independent sets containing only vertices from . Similarly, we write for the set of non-empty independent sets that contain only vertices from . Finally, we denote by the set of independent sets containing at least one vertex in and at least one vertex in .
Given a bipartite graph , the following lemma expresses in terms of the partitioning defined above.
Let be a bipartite graph. Then,
By Definition 3.4 the set partitions into , which yields
For our reduction to work though, we must design gadgets which are tailored to our general setting of weighted independent sets.
Let be a prime and let .
For every we denote by the bipartite graph with vertices in two disjoint vertex sets , and the edge set
consisting of all edges in the complete bipartite graph except with .
See Figure 2 for the example graph .
has two types of vertices in each partition: the vertices in of degree and the vertices in