Parameterized Counting of Partially Injective Homomorphisms

We study the parameterized complexity of the problem of counting graph homomorphisms with given partial injectivity constraints, i.e., inequalities between pairs of vertices, which subsumes counting of graph homomorphisms, subgraph counting and, more generally, counting of answers to equi-join queries with inequalities. Our main result presents an exhaustive complexity classification for the problem in fixed-parameter tractable and #W[1]\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\#\mathsf {W[1]}$$\end{document}-complete cases. The proof relies on the framework of linear combinations of homomorphisms as independently discovered by Chen and Mengel (PODS 16) and by Curticapean, Dell and Marx in the recent breakthrough result regarding the exact complexity of the subgraph counting problem (STOC 17). Moreover, we invoke Rota’s NBC-Theorem to obtain an explicit criterion for fixed-parameter tractability based on treewidth. The abstract classification theorem is then applied to the problem of counting locally injective graph homomorphisms from small pattern graphs to large target graphs. As a consequence, we are able to fully classify its parameterized complexity depending on the class of allowed pattern graphs.


Introduction
In his seminal work on the complexity of computing the permanent, Valiant [56] introduced counting complexity which has since then evolved into a well-studied sub-field of computational complexity theory. Despite some surprising positive results, such as polynomial time algorithms for counting perfect matchings in planar graphs by the FKT method [37,38,54], counting spanning trees by Kirchhoff's Matrix Tree Theorem (cf. [44]) or counting Eulerian cycles in directed graphs using the "BEST"-Theorem [1], most of the interesting counting problems turned out to be intractable. Therefore, several relaxations such as restrictions of input classes [55,57,60] and approximate counting [3,23,31,36] were introduced. Another possible relaxation, the one this work deals with, is to consider parameterized counting problems as independently introduced by Flum and Grohe [26] and McCartin [45]. Here, problems come with an additional parameter k and a problem is fixed-parameter tractable (FPT) if it can be solved in time g(k) · poly(n) where n is the input size and g is a computable function, which yields fast algorithms for large instances with small parameters. On the other hand, a problem is considered intractable if it is #W [1]-hard. This stems from the fact that #W [1]-hard problems do not allow an FPT algorithm unless standard assumptions such as the Exponential Time Hypothesis (ETH) are wrong (cf. [18,Chapter 14.4]).
When investigating a family of related (counting) problems, one could aim to simultaneously solve the complexity of as many problems as possible, rather than tackling a (possibly infinite) number of problems by hand. For example, instead of proving that counting paths in a graph is hard, then proving that counting cycles is hard and then proving that counting stars is easy, one should, if possible, find a criterion that allows a classification of those problems in hard and easy cases. Unfortunately, there are results such as Ladner's Theorem [39] (stating that there are problems neither in P nor NP-hard, assuming P = NP), which give a negative answer to that goal in general. However, there are families of problems that have enough structure to allow so-called dichotomy results. One famous example, and to the best of the author's knowledge the first such result, is Schaefer's dichotomy [52], stating that every instance of the generalized satisfiability problem is either polynomial-time solvable or NP-complete. Since then much work has been done to generalize this result, culminating in recent proofs [5,61] of the Feder-Vardi-Conjecture [24]. This question was open for almost twenty years and indicates the difficulty of proving such dichotomy results, at least for decision problems. In counting complexity, however, it seems that obtaining such results is less cumbersome. One reason for this is the existence of some powerful techniques like polynomial interpolation [55], the Holant framework [2,[6][7][8][9][10]33,58] as well as the principle of inclusion-exclusion which all have been used to establish very revealing dichotomy results.
Examples of dichotomies in parameterized counting complexity are the complete classifications of the homomorphism counting problem due to Dalmau and Jonsson [19] and the subgraph counting problem due to Curticapean and Marx [17]. For the latter, one is given graphs H and G and aims to count the number of subgraphs of G isomorphic to H , parameterized by the size of H . It is known that this problem is polynomial-time solvable if there is a constant upper bound on the size of the largest matching of H and #W [1]-hard otherwise 1 . The first step in the proof of that result was the hardness result of counting matchings of size k due to Curticapean [14], which turned out to be the minimal obstruction and was then reduced to the general problem.
The approach of first establishing minimal obstructions for tractability and then reducing to the general case seemed to be the canonical way to tackle such problems. However, recently Curticapean, Dell and Marx [16] discovered that a result of Lovász [41] implies the existence of parameterized reductions that, inter alia, allow a far easier proof of the general subgraph counting problem. Lovász result states that, given simple graphs H and G, the following holds true: In Equation (1) [11,16,20,51]. Informally, it states that a linear combination for pairwise non-isomorphic graphs H i is hard to compute if and only if at least one of the pattern graphs H i for which λ i = 0 has large treewidth.
Using complexity monotonicity, one only has to show two properties of (1) to obtain the dichotomy for counting subgraph embeddings: First, one has to show that a high matching number of H implies that one of the graphs H /ρ has high treewidth and second, that two (or more) terms with high treewidth and isomorphic graphs H /ρ and H /σ do not cancel out; note that the Möbius function might be negative. As there is a closed form for the Möbius function over the partition lattice it was possible to show that the sign of the Möbius function is equal whenever H /ρ and H /σ are isomorphic.

Contributions
In the current work, we strengthen the previously outlined framework to the more general case of partially injective homomorphisms. This notion of graph homomorphisms interpolates between unrestricted homomorphisms and subgraph embeddings, i.e., fully injective homomorphisms. Informally, we consider pairs (H , I ) of graphs H and inequalities I between the vertices of H . Given a further graph G, we say that a homomorphism from H to G is partially injective with respect to I if for every inequality "u = v"∈ I , the homomorphism maps u and v to different vertices. Note that a subgraph embedding can be modelled by choosing as I the set of all inequalities. Furthermore, a reader familiar with database theory might recognize partially injective homomorphisms as answers to equi-join queries (cf. [47]) with inequalities: Here one is given a database B and a query where the x i are variables and the a i are inequalities x i = x j or atoms R(x i , x j , x k ) for some relation R of the database. The goal is then to compute the number of tuples (v 1 , . . . , v ) of elements of the database B for which all relational constraints and inequalities are satisfied. We emphasize that all results we obtain in this paper for partially injective homomorphisms hold as well for equi-join queries with inequalities. 3 Now, for the statement of our results, we adopt the notation of [16] and say that a graph F is a spasm of a graph with inequalities (H , I ) if F can be obtained from H by contracting vertices along inequalities in I ; the formal definition is given in Sect. 2. Furthermore, we write t(H , I ) for the maximum treewidth of spasms of (H , I ). The following result is shown in Sect. 3 and establishes an exhaustive classification for the parameterized complexity of counting partially injective homomorphisms.
for any computable function g unless the Exponential Time Hypothesis (ETH) fails.
In particular, we obtain the following algorithmic result.
Theorem 2 There exists a computable function g such that the number of partially injective homomorphisms from a graph H to a graph G with respect to a set of inequalities I can be computed in time We remark that Theorems 1 and 2 yield an almost tight conditional lower bound on the fine-grained complexity of counting partially injective homomorphisms. The missing gap of log(t(H , I )) is due to the unresolved open problem of whether it is possible to "beat treewidth" [42].
We will see that the previous results can easily be applied to fully understand the parameterized complexity of a wide range of counting problems. We chose counting of locally injective homomorphisms as an exemplary problem, which is studied in Sect. 4. Here, a homomorphism from H to G is called locally injective if it maps two vertices of H to different vertices of G if they have a common neighbour in H . The study of locally injective homomorphisms goes back to Nešetřil [46]; a particular application is given by what is called distance constrained labellings of graphs (cf. [25] We will see that the results on the fine-grained complexity of counting locally injective homomorphisms transfer from the general case as well.
A further question considered is whether counting of locally injective homomorphisms admits "real" fixed-parameter tractable cases, that is, instances of H for which the previous problem is fixed-parameter tractable but not solvable in polynomial time under standard assumptions; note that neither counting of homomorphisms nor counting of subgraph embeddings admits real fixed-parameter tractable cases [17,19]. The subsequent result establishes that the set of all trees induces a real fixed-parameter tractable case for counting of locally injective homomorphisms.

Theorem 3
The problem of counting locally injective homomorphisms from a tree T to a graph G is #P-hard and fixed-parameter tractable when parameterized by |V (T )|.
The proof of the previous theorem relies on the following #P-hardness result regarding the subgraph counting problem restricted to trees; it is shown in Sect. 4.1 and might be of independent interest.

Theorem 4
The problem of, given trees T 1 and T 2 , computing the number of subtrees of T 2 that are isomorphic to T 1 is #P-hard.
Finally, Sect. 5 establishes a generalization of Theorem 1 to computing linear combinations of partially injective homomorphisms. Intuitively, this will enable us to consider not only the problem of computing the number of partially injective homomorphisms from a fixed graph, but also from a set of graphs of equal size. A particular example of the latter is the problem of counting acyclic subgraphs of size k.

Techniques
The main ingredient of our proofs is the framework of linear combinations of homomorphisms and complexity monotonicity. We decided to present this framework using Lovász' notion of a quantum graph [41,Chapter 6], which is defined to be a formal linear combination of simple graphs with finite support: where the sum is over all graphs and λ H = 0 holds only for finitely many graphs. Graph parameters extend to quantum graphs linearly. Consider e.g.
Using quantum graphs, the principle of complexity monotonicity can be rephrased as follows: Computing homomorphisms from Q is precisely as hard as computing the hardest term #Hom(H → G) for which λ H = 0. Fortunately, the complexity of counting (unrestricted) graph homomorphisms is fully understood by the classification of Dalmau and Jonsson [19]: Informally, their result states that computing #Hom(H → G) is fixed-parameter tractable if the treewidth of H is bounded and #W[1]-complete otherwise; this is made formal in Sect. 2.
Given a graph with inequalities (H , I ), we use Möbius inversion over a certain geometric lattice to construct a quantum graph Q[H , I ] such that the number of partially injective homomorphisms from H to a graph G with respect to I equals #Hom(Q[H , I ] → G). However, the crucial part will be the study of the coefficients of Q[H , I ]. By complexity monotonicity, it is necessary to understand which coefficients of Q[H , I ] are non-zero to resolve the complexity of counting partially injective homomorphisms from (H , I ). Unfortunately, it has turned out that the analysis of the coefficients of a quantum graph seems to be much more involved than establishing its existence, as witnessed by recent publications [16,20,51]. In case of subgraph embeddings, Curticapean, Dell and Marx [16] used Equation (1) and the explicit formula of the Möbius function of the partition lattice to obtain both, a quantum graph and an explicit criterion on whether a coefficient vanishes.
In the current paper, we establish a connection between the coefficients of Q[H , I ] and the graphic matroid induced by the inequalities I on the vertex set of H . In particular, it turns out that the lattice over which we perform Möbius inversion in the construction of Q[H , I ] is precisely the so-called lattice of flats of this matroid. This will allow us to rely on Rota's NBC Theorem [49] and we obtain an explicit expression of the set of graphs for which the coefficients in Q[H , I ] are non-zero.
The classification for counting locally injective homomorphisms turns then into an application of the general theorem. For #P-hardness of the subgraph counting problem restricted to trees, we adapt the idea of the "skeleton graph" by Goldberg and Jerrum [28] and reduce directly from computing the permanent, the latter of which is #P-hard as shown by Valiant [56]. To transfer this result to locally injective homomorphisms we use the well-known observation that every locally injective homomorphism from a tree to a tree is fully injective. A partition of a finite set A is a set of pairwise disjoint and non-empty sets, called blocks, whose union is A.

Graph Theory
Graphs in this work are considered simple, undirected and without self-loops, unless stated otherwise. More precisely, a graph G is a pair of a finite set V (G) of vertices and a symmetric and irreflexive relation E(G) ⊆ V (G) 2 . We might only write V and E for vertices and edges if the graph is clear from the context. Furthermore we write {u, v} to denote edges, emphasizing undirectedness. If u and v are vertices of G and e = {u, v} is an edge of G we call u and v adjacent and say that u and v are incident to e. Given a vertex v of G we write N G (v) for the subset of vertices of G that are adjacent to v; if G is clear from the context, we just write N (v). Throughout this paper, we use n for the number of vertices and m for the number of edges. If a graph H is obtained from G by deleting a set of edges and a set of vertices of G, including incident edges, then H is called a subgraph of G. Given a subsetV of V (G) we write G[V ] for the graph with verticesV and edges E ∩V 2 . The resulting graph is called an induced subgraph of G.
Given a graph H and a partition δ of V (H ), the quotient graph H /δ contains a vertex for each block of δ, and two blocks B and B are made adjacent if there are u ∈ B and v ∈ B such that {u, v} ∈ E(H ) (see Fig. 1). Note that B and B might be equal; in particular H /δ may contain self-loops. Intuitively, H /δ is obtained from H by contracting the vertices that are contained in the same set of δ and deleting multiple edges, but keeping self-loops.

Treewidth
Intuitively, the treewidth of a graph measures how tree-like it is. In particular, graphs with small treewidth allow a decomposition in small separators. These decompositions are the basis of many efficient dynamic programming algorithms (DPs) for problems that are computationally infeasible on graphs without the promise of having small treewidth. Roughly speaking, those algorithms can be seen as generalizations of known and simple DPs that solve the corresponding problems on trees. Although we will mainly need the concept in a black-box manner, we decided give the formal definition for reasons of self-containment. Definition 1 (See e.g. Chapt. 7.2 in [18]) Let G be a graph. A tree decomposition of G consists of a tree T and a collection of The width of a tree decomposition is max t∈V (T ) |B t | − 1 and the treewidth of a graph G, denoted by tw(G), is the minimum width a tree decomposition of G can have. We say that a class of graphs has bounded treewidth if there exists a constant c such that the treewidth of every graph in the class is at most c.

Homomorphisms and Subgraph Embeddings
A homomorphism from a graph H to a graph G is a mapping that preserves edges. In other words, for every edge {u, v} ∈ E(H ) it holds that An embedding, also called subgraph embedding, is an injective homomorphism and a strong embedding from H to G is an embedding h such that for all pairs u and v of vertices of H we have that A bijective strong embedding is called an isomorphism and we say that two graphs H and G are isomorphic, denoted by H G, if there exists an isomorphism from H to G. 4 An isomorphism from a graph to itself is called an automorphism and we write Aut(H ) for the set of all automorphisms of a graph H . We will furthermore use the following notations for sets of homomorphisms and its variants.

Definition 2
Let H and G be graphs. are defined likewise. Observe that the set Emb(H → G) can be partitioned by the images of its elements. Furthermore, all classes of the induced equivalence relations have size #Aut(H ). As the images of the embeddings from H to G are precisely the subgraphs of G isomorphic to H , we obtain the following well-known fact.

Counting Problems
A counting problem is a function P : i Sigma * → N. Here i Sigma denotes a fixed finite alphabet which the reader can assume to be {0, 1} for all purposes in this work.

Parameterized Counting Complexity
The field of parameterized counting was introduced by Flum and Grohe [26] and by McCartin [45] with the goal of adapting the relaxation of parameterization for decision problems to the counting realm. A parameterized counting problem is a pair (P, κ) of a counting problem and a computable parameterization κ : i Sigma * → N. The following are two parameterized counting problems that are crucial for this work. Note that in the last example, H is a fixed, possibly infinite set of graphs that is not part of the input. If we choose H as the set of all complete graphs, then #Hom(H) and #Clique are equivalent up to a factor of k!, because the image of a homomorphism from a clique of size k is itself a clique of size k. Let us furthermore remark that we will omit defining κ explicitly from now on as it will be clear from the context. A parameterized counting problem (P, κ) is called fixed-parameter tractable (FPT) if there exists a computable function f and a deterministic algorithm A that, on input x, In particular, A is called an FPT algorithm. For the theory of parameterized hardness, especially for counting problems, it is common to rely on the following variant of Turing-reductions. Definition 3 Let (P, κ) and (P , κ ) be parameterized counting problems. A parameterized Turing-reduction from (P, κ) to (P , κ ) is an FPT algorithm A that solves (P, κ) and is given oracle access to (P , κ ). Furthermore, every oracle query y that is posed by A on input x must satisfy κ (y) ≤ g(κ(x)) for some computable function g independent of x.
We write (P, κ) ≤ T fpt (P , κ ) if a parameterized Turing reduction from (P, κ) to (P , κ ) exists. 5 The following parameterized classification of the homomorphism counting problem is due to Dalmau and Jonsson and will be the basis for the hardness results in this paper.

Theorem 5 ([19]) Let H be a recursively enumerable class of graphs. If H has bounded treewidth then
The tractable case in the previous theorem stems from the following algorithmic result for counting graph homomorphisms.

Fine-Grained Complexity Theory
The conditional lower bounds in this work are based on the Exponential Time Hypothesis (ETH) which is due to Impagliazzo and Paturi [34] and asserts that 3-SAT cannot be solved in time exp(o(m)), where m is the number of clauses of the input formula.
It is known that #W[1]-hard problems are not fixed-parameter tractable unless ETH fails. An even stronger result states that #Clique cannot be solved in time g(k) · n o(k) for any function g unless ETH fails [12,13]. We will rely on the following result about the fine-grained complexity of #Hom(H) which is an easy consequence of Marx' work on the fine-grained complexity of the constraint satisfaction problem. 6

Theorem 7 ([42]) Let H be a recursively enumerable class of graphs of unbounded treewidth. Then #Hom(H) cannot be solved in time
for any function g, unless ETH fails.

Quantum Graphs
We follow the notation of the textbook of Lovász-see Chapt. 6 in [41].

Definition 4 (Quantum graphs)
A quantum graph is a formal linear combination of simple graphs without self-loops with finite support and rational coefficients. We write where the sum is over all (isomorphism types of) graphs and λ H ∈ Q is zero for all but finitely many H . We write supp(Q) for the support of Q, that is, the set containing all graphs with a non-zero coefficient in Q. Furthermore, we call graphs in supp(Q) constituents of Q.
The functions we have seen in the preceding section extend to quantum graphs linearly. We make it explicit for the case of homomorphisms: The study of homomorphism numbers of quantum graphs has far-reaching consequences for the complexity classification of counting problems that require to count small structures in large graphs. They were first (implicitly) used in this context by Curticapean, Dell and Marx in a breakthrough result regarding the exact complexity of the subgraph counting problem [16]. Roughly speaking, they provided a construction of a quantum graph Q[H ], given a graph H , such that After that, they established that computing the number of homomorphisms from a quantum graph is precisely as hard as counting homomorphisms from the hardest constituent. This property is referred to as complexity monotonicity and allows to obtain exhaustive complexity classifications for counting problems that can be expressed as homomorphisms numbers from quantum graphs by ultimately relying on the fact that the problem of counting homomorphisms is fully understood by Theorem 5.
We are now able to provide a formal statement of complexity monotonicity. We point out that the principle of complexity monotonicity was independently (and less explicitly) discovered by Chen and Mengel [11] in the context of counting answers to conjunctive queries. In particular, their version of complexity monotonicity is proved for the more general case of logical structures with constant arity and, additionally, allows to include existentially quantified variables.

Combinatorics
A partially ordered set (poset) is a pair (L, ≤) of a finite universe L and a binary relation ≤ over L which is reflexive, transitive and anti-symmetric. We write σ ≤ ρ if (σ, ρ) is contained in ≤ and we write σ ≥ ρ if ρ ≤ σ .
A poset (L, ≤) is called a lattice if every pair σ, ρ ∈ L has a least upper bound and a greatest lower bound.

Matroids
We will follow the notation of the first chapter of the standard textbook of Oxley [48]. We call E the ground set of M. Furthermore, elements of I are referred to as independent sets of M. In particular, a subset-maximal element of I is called a basis of M and the rank of M, denoted by rk(M), is defined to be the size of a basis.
We point out that rk(M) is well-defined as every basis has the same cardinality due to (2). Now given a subset X ⊆ E we write rk(X ) for the rank of X which is defined to be the size of the largest independent set A ⊆ X . Furthermore, we define the closure of X to be cl(X ) := {e ∈ E | rk(X ∪ {e}) = rk(X )} .
By definition we have that rk(X ) = rk(cl(X )). Furthermore, we call X a where comp denotes the number of connected components (see, for instance, Chapt. 1.7 of [48]). Note that, in particular, every isolated vertex of G[X ] is a connected component.

Möbius Inversion
The The function μ L is called the Möbius function of L.
If the poset is clear from the context we will drop the L and only write μ. We will furthermore depend on the following corollary of Rota's NBC Theorem which is concerned with the sign of the Möbius function over a lattice of flats; note that ∅ is the (unique) smallest element of every such lattice.
Theorem 10 (Theorem 4 in [49]) Let (L, ≤) be the lattice of flats of some matroid and let ρ ∈ L be a flat. Then we have that We point out that the empty set ∅ is the (unique) smallest element of the lattice of flats of any matroid.

Partially Injective Homomorphisms
A graph with inequalities is a pair (H , I ) where H is a graph and I is an irreflexive and symmetric relation I ⊆ V (H ) 2 . We say that I is a set of inequalities. Intuitively, given a graph G and a graph with inequalities (H , I ) Now let (H , I ) be a graph with inequalities. It will be very convenient to assume that I does not contain an edge of H and, indeed, we can make this assumption without loosing generality. To see this, observe that whenever {u, v} is an edge of H , no homomorphism in Hom(H → G) can map u and v to the same vertex in G, because otherwise the image of u and v would have a self-loop. As we do not allow input graphs G with self-loops, every homomorphism h satisfies h(u) = h(v), regardless of whether {u, v} ∈ I .
Our classification theorem requires us to generalize quotient graphs to sets of inequalities as follows. Let (H , I ) be a graph with inequalities and let ρ be a subset of I . Now consider the graph with vertices V (H ) and edges ρ. The connected components of this graph induce a partition Part(ρ) of V (H ). In particular, every isolated vertex constitutes a singleton in the partition. We abuse notation and write H /ρ for the quotient graph H /Part(ρ) in what follows; consult Fig. 2 for an illustration. Graphs H /ρ for ρ ⊆ I will turn out to be constituents of the quantum graph for (H , I ) if they do not contain self-loops. 7 For this reason, we adopt the notation of [16] and call a graph F a spasm of (H , I ) if F does not contain self-loops and is isomorphic to a graph H /ρ for ρ ⊆ I . In other words, F is a spasm of (H , I ) if it can be obtained from H by successively identifying vertices of H along inequalities in I without creating self-loops.
We write Spasm(H , I ) for the set of all spasms of (H , I ) and we set Given a class H of graphs with inequalities, we define Spasm(H) to be the set containing every graph F that is the spasm of some (H , I ) ∈ H.
The following is the main result of the current section. Let us first emphasize the following consequence of Theorem 11 for the parameterized and fine-grained complexity of #PartInj(H).

Corollary 2 (Theorem 1, restated) Let H be a recursively enumerable class of graphs with inequalities. If the treewidth of Spasm(H) is bounded, then #PartInj(H) is fixedparameter tractable. Otherwise #PartInj(H) is #W[1]-complete and cannot be solved in time g(|V (H )|) · |V (G)| o(t(H ,I )/ log(t(H ,I ))) , for any computable function g unless ETH fails.
Proof We show that the problems #PartInj(H) and #Hom(Spasm(H)) are interreducible with respect to parameterized Turing-reductions. For the reduction #PartInj(H) ≤ T fpt #Hom(Spasm(H)) we observe that by Theorem 11 The classification in fixed-parameter tractable and #W[1]-complete cases follows then by Theorem 5. Furthermore, we observe that all reductions are tight in the sense that the running time is linear in the size of the target graphs G and that every oracle query only increases the size of the target graphs by a factor depending on the parameter. Consequently, the conditional lower bound under ETH holds by Theorem 7.
The algorithm for counting partially injective homomorphisms follows in a similar way: (2) and the treewidth-based dynamic programming algorithm for counting homomorphisms as given by Theorem 6.

Proof of Theorem 2 Holds by Equation
The proof of Theorem 11 consists of two steps. In the first one, we will invoke Möbius inversion over the lattice of flats of the graphic matroid induced by the inequalities. This will allow us to construct the quantum graph Q[H , I ]. In the second step, we will then use Theorem 10 to prove that the constituents of Q[H , I ] are precisely the spasms of (H , I ).
Starting with the first step, we consider the inequality graph I (H , I )  Proof Let G be a graph. We define We will now partition the set Hom(H → G)[σ ] by the inequalities that are satisfied. To this end, given some The claim then follows by deleting terms for which H /ρ contains a self-loop and collecting for isomorphic graphs afterwards. In particular, there exists a flat ρ for every spasm F such that F H /ρ: Recall that spasms of (H , I ) are defined in such a way that they are isomorphic to H /ρ for some subsetρ of I that is not necessarily a flat. However, we can take the closure ρ := cl(ρ) ofρ, that is, we add elements of I tô ρ as long as the induced connected components in I(H , I ) do not change. We conclude by the fact that the closure ρ = cl(ρ) is a flat by definition and H /ρ = H /ρ.
What follows is one of the main structural insights of this work. We show that all spasms of (H , I ) are constituents of Q[H , I ]. Note that this is far from obvious as there might be many flats ρ for which H /ρ is isomorphic to the same spasm F. Hence λ F is the sum of different values of the Möbius function that might, a priori, differ in sign and cancel out to zero. The following lemma shows that we rely on Theorem 10 to prove that such cancellations are impossible.

Lemma 2 Let F be a spasm of (H , I ) and let λ F be as in (4). Then we have that
We provide an illustration of the previous lemma in Fig. 3.
Proof Let L = L(H , I ) and let ρ ∈ L be a flat such that F is isomorphic to H /ρ. It suffices to prove that  (4). The claim follows then by Corollary 3 and Lemma 2.

Proof of Theorem 11 Let Q[H , I ] be as in
One might wonder, whether the tractable cases in Theorem 11 are not only fixedparameter tractable, but also polynomial-time solvable. We have seen that this is the case if we count homomorphisms without inequalities (Theorem 5) or homomorphisms with all inequalities, that is, subgraph embeddings [17]. However, we will show that for partial injectivity constraints, there are fixed-parameter tractable cases that are not polynomial-time solvable unless P = #P. We will encounter an example for this phenomenon in the subsequent section, in which we consider the problem of counting locally injective homomorphisms. Li-Hom(H → G) as the set of all locally injective homomorphisms from H to G and given a class of graphs H, we define #Li-Hom(H) as the problem of, given graphs H ∈ H and G, computing #Li-Hom(H → G); the parameter is |V (H )|.

Locally Injective Homomorphisms
It is immediate to express local injectivity as partial injectivity.  PartInj(H , I → G) . a a Fig. 4 Illustration of the windmill graph W 6 and a spasm of (W 6 , I ) that contains the clique of size 4 as a minor: The dotted lines in the right picture constitute a flat of the inequality graph w.r.t. I as every pair of vertices of the matching has the common neighbour a. If the graph is contracted along this flat and afterwards a is removed, we obtain the desired K 4 Consequently, the classification for counting partially injective homomorphisms completely resolves the complexity of counting locally injective homomorphisms: Proof of Corollary 1 Holds by Fact 2 and Corollary 2.
In particular, we are able to transfer the conditional lower bound under ETH as well.
We provide an example using windmill graphs. To this end, given n ∈ N, we define W n as the graph obtained from the matching M n of size n by adding a new vertex a and connecting it to all vertices of the matching.

Corollary 4 Let W be the set of all windmill graphs W n for n ∈ N. Then #Li-Hom(W)
is #W[1]-complete and cannot be solved in time for any function g, unless ETH fails.
Proof Let F be an arbitrary graph with k edges and letF be the graph obtained from F by adding a new vertex a that is made adjacent to all vertices of F. We claim thatF is a spasm of (W k , I ) where I is defined as in Fact 2. To see this, we observe that the edges of M k in W k can be arranged according to F and then be identified according to the inequalities between every pair of vertices of the matching; consult Fig. 4 for an illustration. Therefore F is the minor of some spasm of (W k , I ) and consequently, the set of spasms of (W k , I ) for all k ∈ N contains all graphs as minors and is therefore of unbounded treewidth. #W[1]-completeness follows hence by Corollary 2.
For the conditional lower bound, we rely on the fact that there exists an infinite and recursively enumerable class E of graphs such that every graph H ∈ E has treewidth Θ(|V (H )|) and is sparse, i.e., |E(H )| ∈ Θ(|V (H )|). In fact, every explicit construction of d-regular expanders has this property (cf. [30] and [18,Exercise 7.34]). By the previous observation, we have that each graph H ∈ E is a minor of a spasm of W |E(H )| . Now assume there exists a function g and an algorithm that solves #Li-Hom(W) in time By Fact 2, Theorem 11 and complexity monotonicity (Theorem 8), this algorithm can be used to solve the problem #Hom(E) in timê
On the other hand, we obtain the following tractability result. Proof Let T be a tree and let I as in Fact 2. Then every spasm of (T , I ) is a tree as well and has hence treewidth 1. Fixed-parameter tractability thus follows by Fact 2 and Corollary 2.
However, #Li-Hom(T ) is an exemplary instance of the problem of counting locally injective homomorphisms that is most likely not solvable in polynomial time.

Lemma 3 (First part of Theorem 3, restated) #Li-Hom(T ) is #P-hard.
The class #P is the classical counting analogue of NP. A formal definition, including a rough introduction to classical counting, and the proof of the above lemma can be found in the following subsection. Roughly speaking, the idea is to reduce from subgraph counting on trees, which is shown to be #P-hard as well.

Counting Subtrees of a Tree
We start by giving an introduction to classical counting complexity which was established by Valiant in his seminal work about the complexity of computing the permanent [56]. Recall that a (non-parameterized) counting problem is a function F : {0, 1} * → N. The class of all counting problems solvable in polynomial time is called FP. On the other hand, the notion of intractability is #P-hardness. #P is the class of all counting problems that are polynomial-time (many-one) reducible 8 to #SAT, the problem of computing the number of satisfying assignments of a given CNF formula. A counting problem F is #P-hard if there exists a polynomial-time Turing-reduction from #SAT to F, that is, an algorithm with oracle access to F that solves #SAT in polynomial time.
For the proof of Lemma 3, we will first show #P-hardness of the following intermediate problem: Given two trees T 1 , T 2 , compute the number #Sub(T 1 → T 2 ) of subtrees of T 2 that are isomorphic to T 1 . We call this problem #Sub(T , T ). Related results are #P-hardness for counting all subtrees of a given graph due to Jerrum [35] or even counting all subtrees of a given tree due to Goldberg and Jerrum [28]. As the number of non-isomorphic trees with n vertices is not bounded by a polynomial in n, we do not know how to reduce directly from those problems. Instead we use a construction quite similar to the "skeleton" graph in the construction of Goldberg and Jerrum [28] to reduce from the problem of computing the permanent: Recall that a matrix with the same number of rows and columns is called quadratic. Given a quadratic matrix A with elements (a i, j ) i, j∈ [n] the permanent of A is defined by

Lemma 4 ( Theorem 4, restated) #Sub(T , T ) is #P-hard.
where Sym n is the symmetric group with n elements. We claim that for all quadratic matrices A of size n ≥ 5 with entries from the set {0, 1} the following holds true where id n is the quadratic matrix of size n with 1s on the diagonal and 0s everywhere else. In the following we write v for a vertex in T A and v for a vertex in T id n . To prove the claim we first observe that whenever a subtree of T A is isomorphic to T id n , the root r of T id n has to be mapped to the root r of T A by the isomorphism as the roots are the only vertices with degree n (which is why we needed n ≥ 5 as every other vertex has degree ≤ 4). It follows that the vertices u 1 , . . . , u n of T id n are mapped to the vertices u 1 , . . . , u n of T A which induces a permutation on n elements, that is, an element π ∈ Sym n . We will now partition the subtrees of T A isomorphic to T id n by those permutations and write #Sub(T id n → T A )[π ] for the number of subtrees that induce π . Now fix π and consider a subtree that induces π . It holds that for all j ∈ [n] the vertex w j has to be mapped to w π( j) as those are the only vertices with degree exactly 4 and furthermore, the vertices x j , y j , z j have to be mapped to x π( j) , y π( j) , z π( j) (possibly permuted but the subtree of T A is the same). Now v i,i is adjacent to b i,i for each i ∈ [n] and thus v i,π(i) has to be adjacent to b i,π(i) , that is a i,π(i) = 1. If this is not the case then there is no subtree that induces partition π . Furthermore there is at most one subtree isomorphic to T id n inducing π because the image is enforced by the vertices r , w j and v i,i for all i, j ∈ [n]. Consequently if for all i ∈ [n] it holds that a i,π(i) = 1, and otherwise #Sub(T id n → T A )[π ] = 0 .
Hence #Sub(T id n → T A )[π ] = n i=1 a i,π(i) and therefore Now the reduction works as follows: If the input matrix A has size ≤ 4 we bruteforce the output and otherwise we compute #Sub(T id n → T A ) using the oracle for #Sub(T , T ).
The proof of Lemma 3 relies on the fact that locally injective homomorphisms from a tree to a tree are embeddings.

Proof of Lemma 3
It is a well-known fact that a locally injective homomorphism h from a tree T 1 to a tree T 2 is (fully) injective. To see this, assume that there are vertices v and u in T 1 that are mapped to the same vertex in T 2 . As T 1 is a tree there exists exactly one path v = w 0 , w 1 , . . . , w , w +1 = u between v and u in T 1 . It holds that ≥ 1 as otherwise v and u would be adjacent and hence h(u) = h(v) would have a self-loop in T 2 which is impossible. As h is locally injective we have that h(v) = h(w 2 ), hence u = w 2 , and as h is edgepreserving there are edges {h(v), h(w 1 )} and {h(w 1 ), h(w 2 )} and a path from h( This induces a cycle and contradicts the fact that T 2 is a tree. Therefore #Emb(T 1 → T 2 ) = #Li-Hom(T 1 → T 2 ). By Fact 1, we have that for all H and G the following is true If H is a tree then H is planar and thus #Aut(H ) can be computed in polynomial time [32,43]. Therefore #P-hardness of #Li-Hom(T ) follows by reducing from #Sub(T , T ), which is hard by Lemma 4: Given trees T 1 and T 2 we obtain #Li-Hom(T 1 → T 2 ) by querying the oracle and compute #Aut(T 1 ) in polynomial time. Finally, we output #Li-Hom(T 1 → T 2 ) #Aut(T 1 ) = #Emb(T 1 → T 2 ) #Aut(T 1 ) = #Sub(T 1 → T 2 ) .

Quantum Graphs with Inequalities
We will now go one step further and consider linear combinations of partially injective homomorphisms. In particular, this allows for generalizing subgraph counting in the sense, that we do not only wish to count subgraphs isomorphic to a single graph H , but rather to count subgraphs that are isomorphic to some graph in a given set of graphs. An example for the latter is the problem of counting acyclic subgraphs of size k. We emphasize that the subsequent results for subgraphs have already been observed by Curticapean, Dell and Marx [16]. We extend their results to partial injectivity constraints. It will be convenient to express the problems in this section by quantum graphs with inequalities, which are defined to be formal linear combinations of graphs with inequalities of finite support. We write If all constituents (H , I ) of I satisfy that I is the full injectivity constraint, then #PartInj(I → ) computes a linear combination of subgraph embeddings, given by where the sum is over all graphs and λ H = λ (H ,I ) if (H , I ) is a constituent of I and λ H = 0 otherwise.
We point out that #PartInj(I → ) does not allow for complexity monotonicity in general, even if there are no negative coefficients. To see this, recall that counting homomorphisms is the zeta transformation of counting subgraph embeddings (invoke Lemma 1 with I being the set of all inequalities). In particular, the following holds true for the k-matching M k : Consequently, assuming that k = r 2 , this constitutes a linear combination of subgraph embeddings, such that the r -clique is contained with a non-zero coefficient. However, as matchings have treewidth 1, #Hom(M k → ) can be computed in time poly(k) · n O(1) by Theorem 6, whereas cliques of size r cannot be counted in time poly(r ) · n O(1) = poly(k) · n O(1) , unless ETH fails [12,13]. Now observe that quantum graphs with inequalities yield linear combinations of partially injective homomorphisms and the latter are again linear combinations of homomorphisms. Consequently, it is possible to express the number of partially injective homomorphisms from a quantum graph with inequalities as the number of homomorphisms from a quantum graph without inequalities; recall the definition of where (6) is the definition of #PartInj(I → ), (7) is Corollary 3 and (8)  We will now provide a criterion that, if satisfied, allows us to give the support of Q[I] explicitly. are equal for different constituents and hence there might be cancellations. Going back to the example of computing #Hom(M k → ), we observe that the expression as a linear combination of subgraph embeddings does indeed contain constituents with different numbers of vertices. In other words, those cancellations must occur in the general case (unless ETH fails). We furthermore point out that the proof of Theorem 13 actually shows the following, more general statement.

Remark 1
The second claim of Theorem 13 holds true even if we only require that all non-zero coefficients have the same sign and that the number of vertices of constituents of I have the same parity. Now, arguably, Theorem 13 might seem artificial at first glance. Let us hence provide a concrete application which shows its utility. We define the problem #VertexForests as follows: Given a graph G and a positive integer k, the task is to compute the number of acyclic subgraphs with k vertices 9 in G. The problem is parameterized by k. The following hardness result follows implicitly from [16]. We include a proof only for illustrating an application of Theorem 13.

Lemma 5 #VertexForests is #W[1]-complete.
Proof Let F k be the set of all acyclic graphs with k vertices. Furthermore, given some graph F, we write full(F) for the set of all possible inequalities between vertices of F. Now the number of acyclic subgraphs of size k of a graph G equals Now, similarly to the proof of Corollary 2, we invoke complexity monotonicity and obtain that #VertexForests is interreducible with #Hom(Q) with respect to parameterized Turing reductions, where Q = H ∈ Spasm(F, full(F)) | F ∈ k∈N F k .
As for every k ∈ N, F 2k contains the matching M k , we conclude that Q contains for every k all (connected) graphs with k edges and is therefore of unbounded treewidth. The lemma hence holds by Theorem 5.

Remark 2
The problem #Trees of counting connected acyclic subgraphs with k vertices can be proved #W[1]-complete similarly, as shown in [16]. We emphasize that the framework of quantum graphs significantly simplifies the original #W[1]-completeness proof of #Trees [4].

Conclusions and Future Work
We established an exhaustive classification of the parameterized complexity of counting partially injective homomorphisms and have thus fully understood the complexity of counting answers to equi-join queries with inequalities, subsuming not only the prior classification of the subgraph counting problem, but also inducing a novel dichotomy for counting locally injective homomorphisms. Building upon the works of Chen and Mengel [11] and Curticapean, Dell and Marx [16] our proof illustrates once more the potential of the framework of complexity monotonicity for the field of parameterized counting. In particular, it allows a canonical generalization to logical structures of bounded arity such as equi-join queries and, even further, to conjunctive queries (implicitly in [11], explicitly in [20]), which, together with our result on quantum graphs with inequalities, might find further applications for first-order model counting problems, especially in the context of relational databases.