The complexity of parity graph homomorphism: an initial investigation

Given a graph G, we investigate the question of determining the parity of the number of homomorphisms from G to some other fixed graph H. We conjecture that this problem exhibits a complexity dichotomy, such that all parity graph homomorphism problems are either polynomial-time solvable or parityP-complete, and provide a conjectured characterisation of the easy cases. We show that the conjecture is true for the restricted case in which the graph H is a tree, and provide some tools that may be useful in further investigation into the parity graph homomorphism problem, and the problem of counting homomorphisms for other moduli.


Graph homomorphism
Graph homomorphism is a natural generalisation of graph colouring, in which the restrictions on adjacencies between colours can be more general than in the usual graph colouring problem. A homomorphism from a graph G to a graph H is an edge-preserving map between the vertices (see Definition 1.1). It is sometimes referred to as an H-colouring (where the target graph for the homomorphism is H). Ordinary graph colouring is the special case of homomorphisms into the complete graph. Definition 1.1. A homomorphism from a graph G into another graph H is a map ϕ : V (G) → V (H) satisfying the property that if (u, v) ∈ E(G) then (ϕ(u), ϕ(v)) ∈ E(H). The set of homomorphisms from G to H is denoted Hom(G, H). Example 1.2. A homomorphism from a graph G to the complete graph K n is a (proper, vertex) n-colouring of G. Example 1.3. Let H 1 be the graph with vertex set {a, b}, an edge joining a and b, and a loop at b. A homomorphism from a graph G to H 1 can be considered as an independent set of G. The vertices mapped to vertex a form an independent set (as none of them can be pairwise adjacent) and, conversely, given an independent set, it is possible to map the vertices of the independent set to a and the vertices of its complement to b. So there is a natural one-to-one correspondence between homomorphisms to H 1 and independent sets.
For the purposes of this paper, both G and H are allowed to have loops on their vertices, but not multiple edges. To reduce the potential for confusion, we will usually refer to the vertices of H as "colours", reserving the word "vertex" for vertices of G.
Fix a target graph H. There are a number of computational problems of the form: given an instance (graph) G return some information about Hom(G, H). The most basic one is the decision problem, which asks if Hom(G, H) non-empty. Each H specifies a particular decision problem; for example, if H is the triangle, the problem is to decide if G is 3-colourable. The goal is then to classify the complexity of the computational problem in terms of the graph H. The ideal is to identify a dichotomy, i.e., a partition of graphs H into those that specify tractable problems and those that specify intractable ones.
The complexity of the decision version of the graph homomorphism problem was completely classified by Hell and Nešetřil in [13]. For a given graph H, deciding whether an arbitrary graph has a homomorphism to H can be done in polynomial time if H has a loop or is bipartite. Hell and Nešetřil showed that this decision problem is NP-complete in all other cases.
It is also natural to consider the counting problem, which asks for the cardinality of Hom(G, H), which we denote by hom(G, H). The problem of exactly counting the number of homomorphisms to a fixed graph H was considered by Dyer and Greenhill [6], who gave a complete characterisation, again with a dichotomy theorem: the counting problem is polynomial-time solvable if H is either a complete graph with loops everywhere or a complete bipartite graph without loops, and it is #P-complete otherwise.
The result of Dyer and Greenhill has been extended in many different directions by various authors. One possibility is to specify weights w : E(H) → C for the edges of H; this edge-weighting naturally induces a weighing of homomorphisms ϕ from G to H, by taking a product of weights w(ϕ(u), ϕ(v)) over edges {u, v} of G. In the weighted setting, one can express partition functions of models in statistical physics. Note that the unweighted form of the problem can be recovered by restricting weights to be {0, 1}. Bulatov and Grohe [1] exhibited a dichotomy for non-negative real weights, which was extended to arbitrary real weights by Goldberg, Grohe, Jerrum and Thurley [11], and then on to complex weights by Cai, Chen and Lu [4]. The massive further generalisation to Constraint Satisfaction Problems (CSPs) was undertaken by several authors (e.g., Bulatov [2] and Dyer and Richerby [7]), culminating in the complex weighted case by Cai and Chen [3]. See Chen's survey for more details [5].
In this paper, we shall mostly be concerned with the problem of determining the cardinality of Hom(G, H) modulo k, for a positive integer k, with a special emphasis on k = 2, i.e., determining wither the number of H-colourings is odd or even. For k ≥ 2 and n an integer, denote by [n] k the residue class of n modulo k. We can of course identify these classes with the integers {0, 1, . . . , k − 1}. Formally, our computational problem is the following.
Instance. An undirected graph G.
Output. [hom(G, H)] k , i.e., the number of H-colourings of G modulo k.
Since the case k = 2 is of special significance, we introduce ⊕H-Colouring as a synonym for # 2 H-Colouring.
We give a dichotomy theorem for ⊕H-Colouring in the case where H is a tree: either ⊕H-Colouring is ⊕P-complete or it can be solved in polynomial time. (See Theorem 3.8.) Informally, ⊕P is the class of problems that can be expressed in terms of deciding the parity of the number of accepting computations of a non-deterministic Turing machine; see Section 2 for a precise definition. The proof of the dichotomy is based on a reduction system which transforms H to a "reduced form" of equivalent complexity. Since it is easy to decide the complexity of ⊕H-Colouring for reduced forms, we obtain not only the dichotomy result, but also an effective procedure for deciding the dichotomy. We conjecture that the same reduction system decribes a complexity dichotomy for general graphs. Although this conjecture remains open in general, Göbel, Goldberg and Richerby [10] have extended our result by showing that the conjecture holds for cactus graphs.
Finally we draw attention to some existing work in the general area of modular counting. The complexity of modular counting problems has been studied for at least three decades, early contributions being made by Valiant [18] and Papadimitriou and Zachos [16]. One of the more striking results, is that of Valiant [19], who provides an example of a counting problem that is unexpectedly easy modulo 7, though hard modulo 2. It is worth noting that modular CSPs have been studied, e.g., by Faben [8] and Guo, Huang, Lu and Xia [12]. This work is both more general, in the sense of being set within the wider context of CSPs, but also more restrictive, in that it relates to the two-element (Boolean) domain only.
2 Modular counting complexity 2.1 The classes # k P In this section, we formally define the counting classes that we will use in this paper.
A classical counting problem can be considered as a function taking a problem instance to the number of solutions associated with that instance. When counting is done modulo some number k ≥ 2, it is possible to view the problem from two somewhat different standpoints. On the one hand there is the decision or language view, where the task is to determine whether the number of solutions is different from 0, modulo k. On the other is the function view, where the task is to compute the residue, modulo k, of the number of solutions. Both views have been taken in earlier work, and the distinctions between them have been examined by Faben [9].
In the current context, the function view seems more natural. We work within a class # k P of computational problems which is the modular analogue of the classical class #P of counting problems. Informally, # k P contains functions that can be expressed as the residue, modulo k, of the number of accepting computational of a nondeterministic polynomial-time Turing machine.
Let Σ be a finite alphabet over which we agree to encode problem instances. In this paper, we are concerned particularly with the case k = 2, and we follow other authors in using ⊕P as a synonym for # 2 P [16].
Given a counting problem in #P, say #A, we write # k A for the # k P problem of determining the number of solutions to A modulo k. So while #A : Σ * → N is a function defined from strings to the natural numbers, # k A : Σ * → {0, . . . , k − 1} is the function from strings to the integers modulo k defined by # k A(x) ≡ #A(x) (mod k). As an example, # k Sat is the problem of determining the number of satsifying assignments to a CNF Boolean formula, modulo k. Naturally, ⊕Sat is the special case k = 2 of this problem.

Completeness
Again, in an analogy with #P-completeness, we define the notion of # k P-completeness with respect to polynomial-time Turing reducibility. Essentially, a problem A is # k Phard if every problem in # k P can be solved in polynomial time given an oracle for A. Definition 2.2. We say that a problem B is polynomial-time Turing reducible to a problem A if problem B can be solved in polynomial time using an oracle for problem A. We write B ≤ T p A.
As one might expect, the modular counting versions of Sat, namely # k Sat for k ≥ 2, are examples of # k P-complete problems for all k. This can be easily seen as the usual reduction in Cook's Theorem, showing that SAT is NP-complete is parsimonious (i.e., preserves the number of solutions), and so certainly preserves the number of solutions modulo k for all k.
As mentioned above, the complexity of exactly counting the number of homomorphisms to a given graph H was characterised by Dyer and Greenhill. They proved the following theorem.
Theorem 2.4 (Dyer and Greenhill [6]). If a graph H is a complete bipartite graph with no loops or a complete graph with loops everywhere, then exactly counting H-colourings can be done in polynomial time. Otherwise, the problem is #P-complete.
Clearly, if the number of homomorphisms to a graph H can be counted exactly in polynomial time, then the parity can be determined in polynomial time. We will show that there are some cases in which symmetries of H can make the related modular counting problem easy, even when the exact counting problem is #P-hard.

Reduction by involutions
We will also need to discuss the automorphism groups of graphs. There will be particular reference to automorphisms of order 2, or involutions. Definition 3.1. An automorphism of a graph G is an injective homomorphism from G to itself. In other words, an automorphism of a graph G is a permutation σ of the vertices of G such that {σ(u), σ(v)} ∈ E(G) ⇐⇒ {u, v} ∈ E(G). If σ has order 2, i.e., σ is not the identity but σ • σ is, then we say that σ is an involution of G.
As hinted at earlier, our approach is based on a reduction system for graphs H that preserves the complexity of the problem ⊕H-Colouring. The reductions are defined in terms of the automorphisms of H.  Proof. We will in fact show that the number of H-colourings of G which are not H σcolourings is even, which is equivalent to saying that see the number of H-colourings which use at least one colour in V (H)\V (H σ ) is even.
To see this, we partition the set of such colourings into subsets of size two. The basic idea here is that to each colouring which uses at least colour in V (H)\V (H σ ) we can associate the colouring gained by first applying σ to H and then colouring G. Formally, given any colouring ϕ : V (G) → V (H), consider the alternative colouring σ • ϕ. This is still an H-colouring of G, as both σ and ϕ are edge-preserving. It is different from ϕ as there is some vertex v ∈ G such that ϕ(v) ∈ V (H)\V (H σ ), and so σ(ϕ(v)) = ϕ(v). On the other hand σ • σ • ϕ is just ϕ, as σ is an involution. So σ acts as an involution on the set of H-colourings of G which use at least one colour from V (H)\V (H σ ). Since this involution has no fixed points, the size of this set must be even.
Note that the above argument does not rely on any special properties of the modulus 2 beyond the fact that it is prime. It is not just the proof that fails for a composite modulus k. The complete graph K 5 on five vertices has an automorphism of order 6 that moves all the vertices, but it is not true that for every graph G that the number of 5-colourings of G is divisible by 6.
We define the following reduction system on the set of unlabelled graphs.
Definition 3.5. The binary relation → k on graphs is defined as follows. For graphs H and K, the relation H → k K holds iff there exists an automorphism σ of H, of order k, such that H σ = K. If there exists a sequence of graphs H 1 , H 2 , . . . , H ℓ such that we write H → * k K and say that H reduces to K by automorphisms of order k. (If k = 2, we say that H reduces to K by involutions.) If K has no automorphisms of order k we say that K is a reduced form associated with the graph H. Example 3.6. In Figure 1 we give an example of a graph H, along with two ways of reducing H by involutions. On the right-hand side we reduce H by using the involution σ which swaps each of the pairs of vertices a and e, b and f , c and d, leaving behind only the involution-free graph on the vertices g and h. On the left-hand side, we begin with the involution τ which swaps e and f , and have to reduce the resulting graph by involutions twice more before we get to the involution-free graph ((H τ ) υ ) η which is isomorphic to the graph H σ . This is not a coincidence. We will see in Theorem 3.7 that reduced forms are unique. To make further progress, we need to assume k = p is prime. Eventually, we will further restrict attention to the case p = 2. However, we state and prove some intermediate results for a general prime p, as they may be of use in further explorations of modular counting problems.
Theorem 3.4 says that in classifying the complexity of # p H-Colouring problems, it is enough to restrict attention to graphs H that are reduced forms, i.e., that do not have any automorphisms of order p. This is enough for the proof of the main dichotomy result, but it is an interesting fact that reduced forms are unique. In any case, the concepts used in the proof of uniqueness of the reduced form will be needed later.
Theorem 3.7. Given a graph G, and a prime p there is (up to isomorphism) exactly one graph G * such that G * has no automorphisms of order p and G → * p G * . The proof, which uses the concept of "Lovász vector" of a graph, is presented in the next section. We can now state main result.
Theorem 3.8. If H is a tree, then ⊕H-Colouring is ⊕P-complete if the reduced form obtained by reducing H by involutions is non-trivial, i.e., has more than one vertex. Otherwise it is solvable in polynomial time.
We conjecture that this result holds for graphs in general. The conjecture is unresolved, though Göbel, Goldberg and Richerby [10] recently extended our result from trees to cactus graphs. One could extend the conjecture to # p H-Colouring, for primes p > 2. Specifically, one might conjecture that, for each p, the set of reduced forms H corresponding to polynomial-time cases of # p H-Colouring is finite (and that all other reduced forms correspond to #P-complete cases). However, we do not go that far here.

The Lovász vector of a graph
We need a modular version of the Lovász vector [13, §2.3] of a graph. Definition 3.9. Let p be a prime, and G 1 , G 2 , . . . be a fixed enumeration of all pairwise non-isomorphic graphs. (Thus every graph is isomorphic to exactly one graph in the sequence.) The mod-p Lovász vector of a graph H is the sequence [hom(G i , H)] p : i ≥ 1 .
We show that the mod-p Lovász vector determines a graph, provided the graph has no automorphisms of order p. First recall some elementary facts about groups.  It follows that: Lemma 3.12. For any prime p, a graph has an automorphism of order p if and only if the order of its automorphism group is divisible by p.
Proof. The automorphisms of a graph form a group. If this group contains an element of order p, then the order of the automorphism group is divisible by p, by Lagrange's Theorem. If the order of the automorphism group is divisible by p, then it contains an automorphism of order p by Cauchy's Group Theorem.

Now the claim.
Lemma 3.13. Suppose p is a prime, and H and H ′ are two graphs, neither of which has an automorphism of order p. Then H and H ′ are isomorphic if and only if they have the same mod-p Lovász vector.
Proof. Clearly the condition is necessary: two isomorphic graphs have the same mod-p Lovász vector. Now we need to prove that it is sufficient. This proof is similar to the proof of Theorem 2.11 in Hell and Nešetřil's monograph [14].
So suppose H and H ′ have the same mod-p Lovász vector, that is for all graphs G. We first observe that, in order to show that H and H ′ are isomorphic, it is sufficient to prove that for every graph G: where inj(G, H) denotes the number of injective homomorphisms from G to H. To see this, first take G = H in the above congruence (2). The left hand side of the congruence is just the order of the automorphism group of H, which, by Lemma 3.12, is not congruent to 0 modulo p. Therefore, the right hand side, inj(H, H ′ ), is also different from from 0 modulo p and, in particular, there exists an injective homomorphism from H to H ′ . Similarly, if we take G = H ′ we find an injective homomorphism the other way, and thus an isomorphism between H and H ′ . We will prove that equation (1) implies equation (2) by induction on the size of G. If G only has one vertex then every homomorphism from G to any other graph is injective, so the equality holds. Now assume that the equality is true for all graphs that have fewer vertices than G. The proof strategy is essentially to count those homomorphisms which are not injections, and show that there are the same number of these, so there must be the same number of injective homomorphisms.
For a partition Θ = {S i : i ∈ I} of the vertex set V (G) of a graph G, define the quotient graph G/Θ as follows. The vertex set of G/Θ is the index set I. There is an edge between i, j ∈ I in G/Θ iff there is some edge joining a vertex in S i to a vertex in S j in Θ. (It may happen that i = j, in which case G/Θ has a loop at i.) The number of homomorphisms is equal to the number of injective homomorphisms plus the number of homomorphisms which are not injective. In order to count the number of homomorphisms which are not injective, we consider the different ways in which the colours of H can be assigned to vertices of G.
A colouring of G with H induces a partition of G in the obvious way, with vertices which are given the same colour assigned to the same part of the partition. If we call this partition Θ, then any H-colouring of G can be considered as an injective H-colouring of G/Θ, since each vertex of G/Θ is associated with exactly one colour from H. Let ι be the partition consisting of a single block for each vertex (i.e., the partition associated with injective homomorphisms from G to H). Then we have both Since G/Θ is necessarily smaller than G if Θ = ι, we know by the induction hypothesis that inj(G/Θ, H) ≡ inj(G/Θ, H ′ ) (mod p), and since hom(G, H) ≡ hom(G, H ′ ) (mod p) by assumption, we do have inj(G, H) ≡ inj(G, H ′ ) (mod p), as required.
Note that the largest graph G considered in the above inductive argument has the same number of vertices as H. So if H and H ′ are not isomorphic then there must be a graph G with at most as many vertices as H that distinguishes H and H ′ , that is, where G * and G † have no automorphisms of order p. Theorem 3.4 says the reduction operation → p preserves the mod-p Lovász vector, so G * and G † have the same vector. On the other hand, Lemma 3.13 above says that the mod-p Lovász vector characterises (isomorphism classes of) graphs with no automorphisms of order p, so G * and G † are isomorphic.

Pinning colours to vertices
We would like to be able to count the number of H-colourings of a given graph G in which certain vertices of G are forced to receive certain colours from H. This would allow us to isolate a suitable "hard" subgraph H ′ of H, and hence reduce the known hard H ′ -colouring problem to the particular H-colouring problem that interests us. We achieve this by building gadgets, which are graphs with a distinguished vertex, with the following property: effectively, only a certain set of colours can be applied to the distinguished vertex of a gadget. By attaching these gadgets to a vertex of G, we can restrict that vertex to be coloured with a particular set of colours.
In essence, we want to show that for any two distinct colours h 1 , h 2 ∈ V (H) in a given H, there exists some rooted graph (Γ, γ) such that the number of ways of H-colouring Γ with γ receiving h 1 is different, modulo 2, to the number of ways of Hcolouring Γ with γ receiving h 2 . (In fact, as we can see, we can find such a rooted graph Γ for all prime moduli.) Suppose G is an instance graph with distinguished root vertex v. We can then use rooted graphs such as (Γ, γ) to pick out the colourings of G in which vertex v receives a colour from some particular subset of the colours. Roughly, we do this by attaching a copy of Γ to G, identifying γ and v. Call the resulting graph G ′ . Suppose a colouring of G with vertex v receiving h 1 extends to a colouring of G ′ in (say) an odd number of ways. Then a colouring with v receiving h 2 will extend in an even number of ways. In this way we have effectively "cancelled" the colourings of G with v coloured h 2 , while leaving untouched those with v coloured h 1 .
The construction of the required gadgets rests on a rooted version of Lemma 3.13 Before we give the proof, we need to define rooted versions of a few concepts we have already encountered. We denote the number of homomorphisms from rooted graph (G, g) to rooted graph (H, h) by hom * ((G, g), (H, h)). If the roots are implied by the context we will sometimes suppress them in the above notation, and just write hom * (G, H).
Similarly, we denote the number of injective homomorphisms from rooted graph (G, g) to (H, h) by inj * ((G, g), (H, h)) and, again, we may suppress the specified vertices if they are implied by the context, instead writing inj * (G, H).
Finally, we will use the concept of the Lovász vector of a rooted graph. For us, this will be the vector which counts, for a given rooted graph (H, h), the number of homomorphisms to (H, h) from every other rooted graph. We will use parity Lovász vector is an alternative name for mod-2 Lovász vector. Proof. As for Lemma 3.13, but with hom * and inj * replacing hom and inj. In defining the quotient of a rooted graph (G, g) by a partition Θ = {S i : i ∈ I}, we define the root of (G, g)/Θ to be the vertex i ∈ I such that g ∈ S i . As with Lemma 3.13, it can be seen that we need only finitely many terms of the mod-p Lovász vector to reconstruct (H, h).

Building Gadgets
In the following we return to ⊕H-Colouring, and are only interested in automorphisms of order two, or involutions. Note that many of the results in this section can be generalised to automorphisms of arbitrary prime order, but we only require the gadgets for the case p = 2 in Section 5, so only this case is presented here, for simplicity.
It will be useful to consider the case where H and H ′ have the same underlying graph but different roots (note that for H and H ′ to be non-isomorphic as rooted graphs, there can be no automorphism of H with takes h to h ′ , i.e., that h and h ′ lie in different orbits of the automorphism group of H). Since we will no longer be able to use the previous naming convention for the specified vertices, we will refer to the two roots in H as x and y. In the following, we will be assuming that H is involution-free. As we saw in Section 3, it suffices to consider the complexity of ⊕H-Colouring for involution-free H.
Lemma 4.5 allows us to construct the following useful gadgets: given an involutionfree graph H and two colours x and y which are in different orbits of Aut(H), there is a rooted graph (Γ, γ) that distinguishes x and y. Proof. Since (H, x) and (H, y) are non-isomorphic as rooted graphs, they have different parity Lovász vectors by Lemma 4.5. Simply take (Γ, γ) to be the first rooted graph for which the corresponding entries of the parity Lovász vectors of (H, x) and (H, y) differ.
We will use rooted graphs such as those guaranteed by Lemma 4.6 as "gadgets" in a reduction from the problem of counting restricted H-colourings (in which a given vertex of the instance graph is forced to be coloured with colours from a specified orbit of Aut(H)) to the problem of counting unrestricted H-colourings modulo 2. Note that this result would follow immediately if were able to build a gadget (i.e., rooted graph) (Γ, γ) such that hom * ((Γ, γ), (H, x)) is odd, while hom * ((Γ, γ), (H, y)) is even for all y = x. Then we could just attach a copy of Γ at the vertex of G that we want to colour with x, identifying this vertex with γ, and then count H-colourings of the new graph. Unfortunately, Lemma 4.6 doesn't allow us to construct such a gadget, as it doesn't allow us to choose which colour is x and which is y. However, we can construct a series of gadgets which allow us to count colourings of G in which the root of G receives a colour from a given orbit of H, by developing a sort of algebra on the gadgets, as described below. We define an operation that combines two rooted graphs by identifying their root vertices. Definition 4.9. Given two rooted graphs Γ and Π, we define the the new rooted graph Γ · Π to be the graph obtained by identifying the roots of each. The root of Γ · Π is the vertex formed by identifying the roots of the other two graphs.
If we think of each gadget Γ and Π as enforcing a certain set of allowed colours at its root vertex, which can think of this operation as forming a gadget that enforces the intersection of these sets. This is equivalent to saying that vector associated with the new gadget is obtained by taking the coordinate-wise product of the vectors associated with the individual gadgets. Definition 4.10. We define the operation * : GF(2) n × GF(2) n → GF(2) n to be the coordinate-wise product of two vectors, so the i th coordinate of v * w is the i th coordinate of v multiplied by the i th coordinate of w. Proof. Fix a colour h i ∈ V (H). The number of colourings of Γ ·Π with the root receiving colour h i is just the product of the number of colourings Γ and Π with the roots in each case receiving colour h i . Thus, if there is a zero in the i th place of either of the vectors v * H (Γ) or v * H (Π), then there is a zero in the i th place of v * H (Γ · Π); otherwise there is a one.
Lemma 4.15. For any involution free graph, H, the all-ones vector is implementable, and for any pair of distinct orbits in H there is at least one implementable vector which has a 1 at every vertex in one of the two orbits and a 0 at every vertex in the other orbit.
Proof. The all-ones vector is implementable using the graph on one vertex. The rooted graphs whose vectors distinguish between distinct orbits of colours in H are obtained using Lemma 4.6.
We now know that the set of implementable vectors is closed under the operations of coordinate-wise addition and coordinate-wise multiplication, that for any pair of colours which are not in the same orbit it contains a vector which has different entries at these two places, and that it contains the all-ones vector. In the following lemma, we prove that these facts are enough to enable us to count colourings in which a specific vertex is required to be coloured with colours from any given orbit of Aut(H).  (1, 1, . . . , 1) and has the property that for any two indices i and j there is some vector in the set whose i th coordinate differs from its j th coordinate. The closure of this set under the operations of coordinate-wise multiplication and coordinate-wise addition includes each of the vectors in the standard basis.
Proof. We proceed by induction on n. If n = 1 the lemma clearly holds, as the all-ones vector is the only vector in the standard basis. Now, assume that n > 1; we shall attempt to construct the vectors in the standard basis in GF(2) n .
By induction, we can construct vectors that agree with the standard basis in the first n − 1 places, without being able to control what happens in the n th place (note that the restriction of the set of vectors S to the first n − 1 places still satisfies the conditions of the lemma). That is, we can certainly obtain vectors of each of the following forms, where the x i can be either 0 or 1 (1 1 1 1 . . . This leaves several cases: Case 1. The x i are all equal to zero. In this case, we already have the first n − 1 vectors from the standard basis, and we can just take the sum of all n − 1 vectors with the all-ones vector, which has a 1 in the last place and zeros everywhere else, to get the last one. Case 2. There are at least two i, j such that x i , x j = 1. But then the product of these two vectors is the vector (0, 0, . . . , 0, 1). To obtain the remaining vectors from the standard basis, we just take the sum of this vector with any of those from the original list which had a 1 in the n th place, i.e., e i is the sum of this vector with the vector which had a 1 in the i th place and a 1 in the n th place. Case 3. There is exactly one vector in the list, v with a 1 as the n th coordinate. Say this vector has a 1 in the i th and n th places. By assumption, there is some vector in S which has different values in the n th and i th places. The product of this with v is a vector with exactly one 1, in either the i th or the n th place, and the sum of this basis vector with v is the other of e i and e n . Proof. for the purposes of this proof, it is convenient to think in terms to the abbreviated vectors v * H (G) in place of the full vectors v H (G). (This is not an essential change; we are merely eliminating duplicated coordinates.) So, now, an implementable vector is one the form v * H (Γ 1 + · · · + Γ r ), for some rooted graphs Γ 1 , . . . , Γ r . By Lemma 4.14 the set of vectors we can implement is closed under the operations of addition and coordinate-wise multiplication, and by Lemma 4.15 we can implement the all ones vector and, for each pair of indices (orbits) i and j a vector v with v i = v j . Thus, by Lemma 4.16, every vector in the standard basis is implementable.
We are now ready to return to Theorem 4.7. Let v be the characteristic vector of the orbit O. We know that v is implementable. So we now just have to show that our definition of "implementable" actually does what we want it to do. That is, it is possible to determine, in polynomial time using an oracle for unrestricted H-colourings, the parity of the number of H-colourings of a rooted graph G in which the root receives a colour from O.
Proof of Theorem 4.7. Let v ∈ GF(2) n be the characteristic vector of the orbit O. By Lemma 4.17, the vector v is implementable, i.e., v = v H (Γ 1 + Γ 2 + · · · + Γ r ) for some set of rooted graphs Now take the sum of the coordinates of the vectors, modulo 2: The left-hand side counts, modulo 2, H-colourings of G in which vertex x receives a colour from O; this is exactly the quantity we are interested in computing. The j th term on the right hand side, counts, modulo 2, the number of (unrestricted) H-colourings of the graph G · Γ j . So the right-hand side can be evaluated using r calls to an oracle for ⊕H-Colouring.  Proof. Define the matrix A = (a ij ) ∈ GF(2) n×n as follows. For all 1 ≤ i, j ≤ n, a ij = number of colourings of G with x receiving colour i and y colour j 2 .
Let u and v be the characteristic vectors of O and O ′ . By Lemma 4.17 we know that u and v are implementable, i.e., u = v H (Γ 1 ) + · · · + v H (Γ r ) and v = v H (Γ ′ 1 ) + · · · + v H (Γ ′ s ) for some rooted graphs Γ 1 , . . . , Γ r and Γ ′ 1 , . . . , Γ ′ s . Thus Note that the left hand side is the quantity we are interested in, namely the number of restricted H-colourings of G. Finally note that the (i, j) th term in the last sum is equal, modulo 2, to the number of colourings of G with Γ i attached to x and Γ ′ j to y. So each term on the right hand side may be computed using an oracle for ⊕H-Colouring.

Trees
As we have seen, if we apply the reduction operations defined in Definition 3.5 to any graph H, this preserves the parity of the number of H-colourings of any graph G. In particular, if a given H reduces to a graph, say H ′ such that the H ′ -colouring problem lies in P, then the H-colouring problem also lies in P. There are certain involution-free graphs H for which the H-colouring problem obviously lies in P.
Lemma 5.1. Counting the number of H-colourings of a given graph G can be done in polynomial time if H is one of the null graph (the graph on no vertices), the graph on one vertex with no loop, the graph on one vertex with a loop, or the graph on two disconnected vertices, one with a loop and one without.
Proof. If H is the null graph then there is no H-colouring of G, so the counting problem is obviously trivial. If H is the graph on one vertex then G has exactly one H-colouring if and only if G has no edges, and zero otherwise, which can be determined in polynomial time. If H is the graph on one vertex with a loop, then there is exactly one H-colouring of G. If H is the graph on two vertices one with a loop and one without then there are exactly 2 |Isol(G)| colourings of G, where Isol(G) is the set of isolated vertices of G. Each isolated vertex can be coloured with either the looped vertex or the unlooped vertex of H independently, and all the vertices which form part of a connected component of size greater than one must be coloured with the looped vertex.
Corollary 5.2. If the reduced form associated with a given H in the reduction system defined in Definition 3.5 is one of the null graph, the graph on one vertex, the graph on one vertex with a loop or the graph on two vertices, one with a loop and one without, then H-colouring is in P.
Proof. This follows directly from Lemma 5.1 and the fact that the reduction system preserves the number of H-colourings, as shown in Lemma 3.3 We conjecture that for general graphs, the reduction given in Corollary 5.2, that is, H reducing by involutions to one of the four trivial graphs is the only way in which the ⊕H-Colouring problem can fail to be ⊕P-complete. Note that this criterion does encompass all of the easy cases identified by Dyer and Greenhill [6]. A complete graph with loops everywhere reduces to the null graph if it has an even number of vertices and the graph on one vertex with a loop if it has an odd number. On the other hand, a complete bipartite graph reduces to the graph on one vertex if there are an odd number of vertices in total, and the null graph otherwise.
In this section, we will prove that this conjecture is true for trees. In particular, if the reduced form, in the reduction system of Definition 3.5, associated with a given tree T is the graph on one vertex or the null graph, then the associated ⊕T -Colouring problem can be solved in polynomial time. Otherwise, it is ⊕P-complete. Note that Göbel, Goldberg and Richerby [10] have recently extended the known range of validity of the conjecture from trees to cactus graphs.

Involution-Free Trees
Involution-free trees have quite a lot of structure, and we will exploit this when we build gadgets for our reductions from ⊕IndSet (defined below) to ⊕H-Colouring in the next section. Lemma 5.3. An involution-free tree on more than one vertex has two vertices of degree 2 which are adjacent to leaves.
Proof. The argument given below is very similar to the standard argument given to show that any tree has at least two leaves.
The first observation to make is that any involution-free tree contains some path of length at least 3. If the maximum-length path in a tree is of length 1, then the tree consists of a single edge, and so has an involution. If it is of length 2, then the tree is a star, and exchanging any two of its leaves is an involution.
Consider a longest path in an involution-free tree, and label the vertices of this path p 0 , p 1 , . . . , p ℓ . Note that p 0 and p ℓ are both leaves. Then we claim that both vertices p 1 and p ℓ−1 are degree 2. Note that p 1 and p ℓ−1 are in fact distinct vertices, as ℓ ≥ 3. Assume the degree of p 1 is greater than 2, and consider a vertex, v, adjacent to p 1 which is neither p 0 nor p 2 . This vertex cannot have any neighbours which are not already in the path (as this would contradict maximality of the path). It also cannot have any neighbours which are in the path (as this would create a cycle, contradicting the fact that G is a tree). Therefore, it cannot have any neighbours other than p 1 . But then exchanging this vertex with p 0 is an involution of G, so there is no such vertex, and p 1 is degree 2 as claimed. An analogous argument shows that p ℓ−1 must be degree 2.
We will also require the following lemma.
Lemma 5.4. An involution-free tree has trivial automorphism group.
This follows directly from a characterisation of Pólya [17] after Jordan [15] of the automorphism groups of trees.
Proof. The automorphism group of a tree can be formed from symmetric groups using the operations of direct product and wreath product with a symmetric group [17]. Since the symmetric groups S n for n > 1 have even order, the automorphism group of a tree is either of even order or has order 1. If it has even order, then by Lagrange's Theorem, the tree has an involution. So an involution-free tree has trivial automorphism group.
Finally, we require the following technical lemma concerning the number of walks of various lengths between vertices in involution-free trees.
Lemma 5.5. Let H be an involution-free tree, let e 0 be a vertex of degree 2 which is adjacent to a leaf in H, and let e ℓ be a vertex of even degree such that there are no vertices of even degree on the path joining e 0 and e ℓ , where ℓ ≥ 1 is the length of the path joining e 0 and e ℓ . We will name the vertices on this path e 0 , o 1 , o 2 , . . . , o ℓ−1 , e ℓ .
Then there are an even number of vertices v such that both: 1. v is a neighbour of the first vertex on this path other than e 0 , i.e., v is a neighbour of e 1 in the case ℓ = 1, and a neighbour of o 1 otherwise; and 2. the number of walks of length ℓ from v to e ℓ in H is odd.
Proof. We will refer in this proof to the vertices o 1 and o 2 , which do not exist if ℓ = 1 or ℓ = 2, we deal with this at the end of this proof. For now, assume ℓ ≥ 3. We want to prove that there are an even number of neighbours of o 1 from which there are an odd number of walks of length ℓ to e ℓ in H. There are an odd number of paths of length ℓ from e ℓ to each of the neighbours of o 1 other than o 2 : there is, in fact, one such walk, and it is the unique path connecting the neighbour to e ℓ in the tree. We claim that there are an even number of walks of length ℓ from e ℓ to o 2 . A walk of length ℓ from e ℓ to o 2 traverses exactly 1 edge more than once, as there is a unique path of length ℓ − 2 from e ℓ to o 2 . Two such walks which traverse the same edge more than once are identical. There is therefore a one-to-one correspondence between these walks and the edges which are traversed at least twice by at least one of them. We claim that the number of such edges is even.
Any edge which is adjacent to any of the vertices in {o 2 , o 3 . . . e ℓ }, and only those edges, may be traversed more than once, so it suffices to show that there are an even number of such edges. To see this, note that the only edges in this set which are adjacent to more than one of the vertices in the set are: o 4 ), . . . , (o ℓ−1 , e ℓ )}, there are the same number of edges in this set as the number of vertices of odd degree in {o 2 , . . . , e ℓ }. The total number of edges is then just the sum of the vertex degrees minus the number of edges which are adjacent to more than one of the vertices; but the sum of the vertex degrees is ℓ − 2 (mod 2) (as there are ℓ − 2 vertices of odd degree) and the number of repeated edges is ℓ − 2, so the parity of the total number of edges is (ℓ − 2) − (ℓ − 2) ≡ 0 (mod 2).
As noted above, if ℓ = 1 or if ℓ = 2 the vertices o 1 or o 2 may not exist. However, the theorem still holds.
In particular, if ℓ = 1 then we actually have two adjacent vertices of even degree and the first vertex on the path which is not e 0 is in fact e 1 , which is of even degree. Clearly there are an even number of vertices adjacent to e 1 with an odd number of length 1 walks to e 1 , these being exactly the neighbours of e 1 .
If ℓ = 2, then again the vertex whose neighbours we are interested in is of odd degree, call it o 1 , and there are an odd number of walks of length 2 from e 2 to each of the neighbours of o 1 other than itself: in fact, there is exactly one such walk, the path joining the two vertices. On the other hand, e 2 is of even degree, so there are an even number of walks of length 2 from e 2 to itself. Since o 1 has an odd number of neighbours, this leaves an even number of neighbours of o 1 which have an odd number of length 2 walks to e 2 , as claimed.

The Reduction
Our starting point is the following problem, which was shown by Valiant [19] (in the guise of "Mon 2-CNF") to be ⊕P-complete; see also Faben [8,Thm. 3.5]).
Output. The parity of the number of independent sets in G.
Theorem 5.6. Given an involution-free tree H with more than one vertex, ⊕H-Colouring is ⊕P-complete. In fact, there is a polynomial-time reduction from ⊕IndSet to ⊕H-Colouring.
Definition 5.7. Given a graph G, we call σ 2 (G) the graph obtained by replacing every edge in G with a path of length 2. We refer to the newly introduced vertices as stretch vertices, and the original vertices of G as G-vertices. The construction is illustrated in Figure 2. The graph defined above, σ 2 (G), is usually referred to as the 2-stretch of G, and it is an established result that counting H-colourings of σ 2 (G) is equivalent to counting H 2 -colourings of G, where H 2 is the multigraph whose adjacency matrix is the square of the adjacency matrix of H (see, e.g., [6]). We will use a variant of this stretch operation in which we count only those colourings of σ 2 (G) in which both the stretch vertices and the G-vertices are coloured with specific subsets of the colours in H. This is achieved using gadgetry based on the principles established in Section 4.
We now detail the reduction from ⊕IndSet. First, given any graph G, we will construct a certain graph G * . We then claim that the number of H-colourings of G * , with certain vertices restricted to receive certain colours from H, is congruent modulo 2 to the number of independent sets in G.
For a given involution-free tree H, pick a vertex of degree 2, e 0 , adjacent to a leaf, and a vertex of even degree, e k such that the unique path of length k in H from e 0 to e k does not contain any vertex of even degree (exactly as in the statement of Lemma 5.5). Note that, as H is involution-free, there are two vertices of even degree, and at least one vertex of degree two which is adjacent to a leaf in H by Lemma 5.3, and we can choose e 0 and e k with the above properties. Now, given a graph G, first create σ 2 (G), then add two new vertices R and B. Add an edge between each of the original vertices of G (G-vertices) and R, and a path of length k from every one of the new vertices (stretch vertices) of σ 2 (G) to B. We call this new graph G * , and the construction is illustrated in Figure 3. Now, using the technology described in Corollary 4.18, and the fact that the orbit of a vertex in an involution-free tree is trivial by Lemma 5.4, we can determine the parity of the number of H-colourings of G * , in which R is restricted to be coloured with e 0 and B is restricted to be coloured with e k , using only a ⊕H-Colouring oracle. We claim that this number is congruent (modulo 2) to the number of independent sets in G. We will use what we know about the number of walks of length k between the colours e 0 and e k from Lemma 5.5.
Lemma 5.8. Suppose H is an involution-free tree, and let e 0 be a vertex of degree 2 adjacent to a leaf, and e k a vertex of even degree at distance k ≥ 1 from e 0 such that there are no vertices of even degree on the path of length k joining them. Suppose G is a graph and let G * be constructed from G as described above.
Then the number of H-colourings of G * in which R receives e 0 and B receives e k is congruent modulo 2 to the number of independent sets in G.
Proof. First consider the G-vertices in G. They are all neighbours of a vertex which is coloured with e 0 , so they must therefore receive colours that are adjacent to e 0 in H. But e 0 was chosen to be one of the vertices of degree 2 adjacent to a leaf in H, so G-vertices can only be coloured with either the leaf adjacent to e 0 (which we will call l) or with the first vertex on the path linking e 0 and e k , which we will call v 1 in the remainder of this proof. This vertex is o 1 , except in the case k = 1 where it is e 1 . Now, consider the stretch vertices. These are connected to a vertex which is coloured e k by a path of length k. So, consider the colour used at a given stretch vertex, s. If there are an even number of walks of length k from e k to this colour in H, then there are an even number of colourings of G * which use that colour at s, as there are an even number of ways of colouring the path joining s and B, and the total number of colourings is the product of the number of ways of colouring this path with the number of ways of colouring the rest of the graph.
We therefore need to count colourings of G * in which the colours used at the stretch vertices are such that there are an odd number of paths of length k between them and e k in H. Note that these colours must also be adjacent to either v 1 or l in H (as the G-vertices are all coloured with either v 1 or l, and every stretch vertex is adjacent to a G-vertex), and therefore, in fact, must be adjacent to v 1 , as the only neighbour of l is e 0 , which is also a neighbour of v 1 . Now, we are reduced to considering colourings of G * in which the following conditions hold. The G-vertices are coloured either l or v 1 , while the stretch vertices are coloured with one of the neighbours of v 1 which has an odd number of length k walks from itself to e k . We claim that the parity of the number of such colourings is equal to the parity of the number of ways of colouring G with the two colours l and v 1 such that no two vertices coloured with v 1 are adjacent.
Consider a colouring of G with the colours v 1 and l. If there are two vertices of G which are adjacent in G and both coloured with v 1 then there are an even number of extensions of this colouring to an H-colouring of G * : the stretch vertex between the two G-vertices in G * can be coloured with any one of the neighbours of v 1 which are at distance k from e k in H, and there are an even number of such vertices by Lemma 5.5.
On the other hand, if there are no two such vertices, there is exactly one extension of the given colouring of G to an H-colouring of G * : every one of the stretch vertices is adjacent to a vertex which is coloured l, so the stretch vertices must all be coloured e 0 , and as there is only one path of length k from e 0 to e k in H, this determines the colouring of the vertices on the paths linking the stretch vertices to B.
So the number of colourings of G * with H such that R is coloured e 0 and B is coloured e k is congruent modulo 2 to the number of colourings of G in which each vertex is either coloured with l or v 1 and adjacent vertices may not both be coloured with v 1 . But these are exactly the independent sets of G: vertices coloured v 1 are "in" the independent set and vertices coloured l are "out". colourings of G with h i at v is the same as the parity of the number of colourings of G which use any of the vertices in the orbit of h i at v.
But we can do this for every vertex in H 1 , and since G is connected, any colouring which uses a vertex from H 1 at v can use only colours from H 1 anywhere in G. Conversely, any colouring of G which uses only colours from H 1 must use some colour from H 1 at v, so this does indeed allow us to count all such colourings of G.
Note that this actually allows us to strengthen Theorem 3.8: the H-colouring problem associated with any forest H is polynomial-time solvable if the reduced form associated with the forest in the reduction system described in Section 3 is the null graph or the graph on one vertex, and ⊕P-complete otherwise.