Counting edge-injective homomorphisms and matchings on restricted graph classes

We consider the parameterized problem of counting all matchings with exactly $k$ edges in a given input graph $G$. This problem is #W[1]-hard (Curticapean, ICALP 2013), so it is unlikely to admit $f(k)\cdot n^{O(1)}$ time algorithms. We show that #W[1]-hardness persists even when the input graph $G$ comes from restricted graph classes, such as line graphs and bipartite graphs of arbitrary constant girth and maximum degree two on one side. To prove the result for line graphs, we observe that $k$-matchings in line graphs can be equivalently viewed as edge-injective homomorphisms from the disjoint union of $k$ paths of length two into (arbitrary) host graphs. Here, a homomorphism from $H$ to $G$ is edge-injective if it maps any two distinct edges of $H$ to distinct edges in $G$. We show that edge-injective homomorphisms from a pattern graph $H$ can be counted in polynomial time if $H$ has bounded vertex-cover number after removing isolated edges. For hereditary classes $\mathcal{H}$ of pattern graphs, we obtain a full complexity dichotomy theorem by proving that counting edge-injective homomorphisms, restricted to patterns from $\mathcal{H}$, is #W[1]-hard if no such bound exists. Our proofs rely on an edge-colored variant of Holant problems and a delicate interpolation argument; both may be of independent interest.


Introduction
Since Valiant's seminal #P-hardness result for the permanent [35], the complexity theory of counting problems has advanced to a classical subfield of computational complexity. As it turned out that many interesting counting problems are #P-hard, various relaxations of the original problems were introduced, giving rise to approximate [26], modular [3], and subexponential counting [17], with additional restrictions on the input classes [25,38].
In this paper, we focus on a recent relaxation of hard counting problems by studying their parameterized complexity [18]. In this paradigm, the input to a given counting problem comes with a parameter k ∈ N, and we ask whether the problem is fixed-parameter tractable (FPT): That is, can it can be solved in time f (k) · poly(|x|) for some computable function f that may grow super-polynomially? For instance, the #P-complete problem of counting vertex-covers of size k in an n-vertex graph can be solved in time 2 k · poly(n) (and even faster) and is hence

Counting matchings in restricted graph classes
In non-parameterized counting complexity, restrictions of hard problems to planar and boundeddegree graphs were studied extensively: We can count perfect matchings on planar graphs in polynomial time by the FKT method [33,27], and several dichotomies show which counting versions of constraint satisfaction problems become easy on planar graphs [6,2].
For the particular problem of counting (not necessarily perfect) matchings, a line of research [25,15,34] culminated in the work of Xia et al. [38] who showed that the problem remains #P-hard even on planar bipartite graphs whose left and right side have maximum degree 2 and 3, respectively. In the parameterized setting, counting k-matchings is FPT in planar or bounded-degree graphs [20], which rules out a parameterized analogue of the hardness result by Xia et al. [38]. It was however shown that counting k-matchings remains #W [1]-complete on bipartite graphs [13], which was essential for the subsequent reductions to the general subgraph counting problem. In the first part of the paper, we find additional restricted graph classes on which counting k-matchings remains #W[1]-complete.

Restricted bipartite graphs of high girth
In [13], the #W[1]-completeness of counting k-matchings in bipartite graphs was actually shown for an edge-colorful variant where the edges of the bipartite graph are (not necessarily properly) colored with k colors and we wish to count k-matchings that pick exactly one edge from each color. This variant can be reduced to the uncolored one via inclusion-exclusion.
In this paper, we strengthen the #W [1]-hardness result for counting edge-colorful k-matchings in bipartite graphs G and show that we may restrict one side of G to have maximum degree two. We may additionally assume any constant lower bound on the girth of G, that is, the length of the shortest cycle in G. For counting (edge-colorful) k-matchings, it is known that an algorithm with running time f (k) · n o(k/ log k) for any computable function f would refute the counting exponential-time hypothesis #ETH [17]. That is, if such an algorithm existed, we could count satisfying assignments to 3-CNF formulas on n variables in time 2 o(n) . Our result establishes the same lower bound in the restricted case.
Theorem 1. For every c ∈ N, counting (edge-colorful or uncolored) k-matchings is #W[1]complete, even for bipartite graphs of girth at least c whose right side vertices have degree at most two. Furthermore, unless #ETH fails, neither of these problems has an f (k) · n o(k/ log k)time algorithm, for any computable function f .
We do the proof in §3 by extending the so-called Holant problems [36,4] to an edge-colored variant that proves to be useful for parameterized counting problems. In classical Holant problems, we are given as input a graph G = (V, E) with a signature f v at each vertex v ∈ V . Here, f v is a function f v : {0, 1} I(v) → Z, where {0, 1} I(v) is the set of binary assignments to the edges incident with v. The problem is to compute Holant(G), a sum over all binary assignments x ∈ {0, 1} E , where each assignment x is weighted by v∈V f v (x).
In our edge-colored setting, the graph G is edge-colored and Holant(G) ranges only over assignments that pick exactly one edge from each color. We apply the recent technique of combined signatures [14] in this setting, an approach that is also implicit in [13]. This gives a reduction from counting edge-colorful k-matchings in general graphs to 2 k instances of the restricted bipartite case. Previously, combined signatures were used only for problems with structural parameterizations, such as counting perfect matchings in graphs whose genus or apex number is bounded [14]. Our edge-colorful approach allows us to apply them also when the parameter is the solution size k.

Line graphs
Building upon Theorem 1, we then prove that counting k-matchings is #W [1]-complete even when the input graph is a line graph. We also obtain a lower bound under #ETH.
Theorem 2. The problem of counting k-matchings is #W[1]-complete, even when restricted to line graphs. Furthermore, unless #ETH fails, this problem does not have an f (k) · n o(k/ log k) time algorithm, for any computable function f .
Line graphs are claw-free, that is, they exclude K 1,3 as induced subgraphs. In fact, the class of line graphs can be characterized by a set S of nine (for large graphs seven) minimal subgraphs such that G is a line graph if and only if G contains none of the graphs from S as an induced subgraph [24,37]. Line graphs can be recognized in linear time [28], and several classical NPcomplete problems are polynomial-time solvable on line graphs, such as finding a maximum independent set [32], a maximum cut [23], or a maximum clique [30]. In contrast, Theorem 2 shows that counting k-matchings remains #W [1]-hard on line graphs.
To prove Theorem 2, one might be tempted to first prove hardness of counting edge-colorful kmatchings in line graphs, and then reduce this problem via inclusion-exclusion to the uncolored case. This approach however fails: While the colored problem is easily shown to be #W [1]complete (even on complete graphs), we cannot use inclusion-exclusion to subsequently reduce to counting uncolored matchings, since doing so would lead to graphs that are not necessarily line graphs. Hence we do not know how to prove Theorem 2 in the framework of edge-colorful Holant problems directly, as we do for Theorem 1.
Instead, we prove Theorem 2 in §4 by means of a delicate interpolation argument, most similar to techniques used in the first hardness proof for uncolored k-matchings [11]. Using a simple gadget and k-matchings in line graphs as the oracle for our reduction, we generate a linear system of equations such that one of the unknowns is the number of k-matchings in a general input graph G, which is #W [1]-complete to compute. The system turns out not to have full rank, but a careful analysis shows that the unknown we are interested in can still be uniquely determined in polynomial time.
Perfect matchings in (perfect) line graphs Completing the picture, we show that the nonparameterized problem of counting perfect matchings also remains #P-hard on line graphs. This holds even for line graphs of bipartite graphs, which are known to be perfect, and which play an important role in the proof of the strong perfect graph theorem by Chudnovsky, Seymour, and Robertson [10].
Theorem 3. The problem of counting perfect matchings is #P-complete even for graphs that have maximum degree 4 and are line graphs of bipartite graphs. On the other hand, the problem is polynomial-time solvable on 3-regular line graphs.
To prove this theorem, we invoke a dichotomy theorem for Holant problems by Cai, Lu, and Xia [7]: We show that the positive case of Theorem 3 can be reduced to a polynomial-time solvable Holant problem, while hardness in the negative case of Theorem 3 follows by reduction from a #P-complete Holant problem.

Counting edge-injective homomorphisms
To prove Theorem 2, we actually prove the equivalent statement that counting edge-injective homomorphisms from the graph k ·P 2 to host graphs G is #W[1]-complete. Here, we write k ·P 2 for the graph consisting of k disjoint copies of the path P 2 with two edges. A homomorphism f from H to G is edge-injective if, for any distinct (but not necessarily disjoint) edges e = uv and e = u v of H, the edges f (u)f (v) and f (u )f (v ) in G are distinct (but not necessarily disjoint). The number of edge-injective homomorphisms from k · P 2 to G is easily seen to be equal to the number of k-matchings in L(G), up to a factor of k! · 2 k , which is the size of the automorphism group of a k-matching.
Starting from their application in the proof of Theorem 2, we observe that edge-injective homomorphisms are an interesting concept on its own, since they constitute a natural interpolation between homomorphisms and subgraph embeddings (which are vertex-injective homomorphisms). To study the complexity of counting edge-injective homomorphisms from general patterns, we define the problems #Hom * (H) for fixed graph classes H: Given graphs H ∈ H and G, the problem is to count the edge-injective homomorphisms from H to G. Similar frameworks exist for counting subgraphs [13], counting/deciding colorful subgraphs [13,31,22], counting/deciding induced subgraphs [9], and counting/deciding (not necessarily edge-injective) homomorphisms [21,16]. In all of these cases, precise dichotomies are known for the parameterized complexity of the problem when the pattern is chosen from a fixed class H and the parameter is |V (H)|. For instance, homomorphisms from H can be counted in polynomial time if H has bounded treewidth, and the problem is #W[1]-complete otherwise [16]. A similar statement holds for the decision version of this problem, but here only the cores of the graphs in H need to have bounded treewidth [21].
Our main outcome is a similar result for counting edge-injective homomorphisms: To state it, let the weak vertex-cover number of a graph G be defined as the size of the minimum vertexcover in the graph obtained from G by deleting all isolated edges, that is, connected components with two vertices. Furthermore, a graph class H is hereditary if H ∈ H implies F ∈ H for all induced subgraphs F of H. To prove this theorem in §6, we first adapt an algorithm for counting subgraphs of bounded vertex-cover number [13] to the setting of edge-injective homomorphisms. Then we use a Ramsey argument to show that any graph class with unbounded weak vertex-cover number contains one of six hard classes as induced subgraphs. This gives a full dichotomy for the complexity of #Hom * (H) on hereditary graph classes H, however leaving out several interesting nonhereditary classes such as paths, cycles, and P c -packings. Here, a P c -packing for c ∈ N is a disjoint union of paths P c , that is, paths consisting of c edges. We handle these specific classes individually.
Theorem 5. The problem #Hom * (H) is #W [1]-complete if H is the class of paths, the class of cycles, or the class of P c -packings, for any c ≥ 2.
We conclude this introduction with a possible future application of edge-injective homomorphisms. A wide open problem in parameterized complexity lies in classifying the subgraph patterns whose existence is easy to decide. The problem is known to be FPT on patterns of bounded treewidth [1], and it seems reasonable to believe that all classes H of unbounded treewidth are W[1]-hard. However, even W[1]-hardness for the class of complete bipartite graphs was only shown recently in a major breakthrough [29]. On the other hand, the complexity is much better understood for deciding the existence of homomorphisms from a pattern class H: As stated above, the treewidth of the cores is the criterion for the complexity dichotomy [21]. Since subgraph embeddings are vertex-injective homomorphisms, the notion of edge-injective homomorphisms interpolates between the solved case of homomorphisms and the unsolved case of subgraphs. In light of this fact, we also consider our results on edge-injective homomorphisms as an initial investigation of a potential avenue towards a dichotomy for deciding subgraph patterns.
An fpt Turing reduction is a Turing reduction from a problem (Π, κ) to a problem (Π , κ ), such that the reduction runs in f (k) · poly(n)-time and each query y to the oracle satisfies κ (y) ≤ g(k). Here, both f and g are computable functions. A problem is #W[1]-hard if there is an fpt Turing reduction from the problem of counting the cliques of size k in a given graph; since it is believed that the latter does not have an FPT-algorithm, #W[1]-hardness is a strong indicator that a problem is not FPT. For more details, see [19].
The counting exponential-time hypothesis (#ETH) is the claim that there exists a constant > 0 for which there is no 2 n -time algorithm to compute the number of satisfying assignments for an n-variable 3-CNF formula. For the counting k-cliques problem, #ETH implies that there is no f (k) · n o(k) -time algorithm [8]. Whenever an fpt Turing reduction from counting k-cliques (or any source problem) to another parameterized counting problem increases the parameter k by at most a constant factor, then the same running time lower bound under #ETH holds for the target problem as well.
Let H and G be graphs. A function ϕ : The set of all homomorphisms from H to G is denoted by Hom(H, G). A homomorphism ϕ ∈ Hom(H, G) is called edge-injective if all e, f ∈ E(H) with e = f satisfy ϕ(e) = ϕ(f ). We denote the set of all edgeinjective homomorphisms from H to G by Hom * (H, G). A homomorphism ϕ ∈ Hom(H, G) is an embedding of H in G if it is a (vertex-)injective homomorphism from H to G. The set of all embeddings from H to G is denoted by Emb(H, G).
For a class H of graphs, let #Hom * (H) denote the following computational problem: Given H ∈ H and a simple graph G, compute the number #Hom * (H, G), parameterized by |V (H)|. The problems #Hom(H) and #Emb(H) are defined analogously.
The line graph L(G) of a simple graph G is the graph whose vertex set satisfies V (L(G)) = E(G) such that e, f ∈ E(G) with e = f are adjacent in L(G) if and only if the edges e and f are incident to the same vertex in G. A line graph is called line-perfect if it is the line graph of a bipartite graph.

Matchings in restricted bipartite graphs
In this section, we prove Theorem 1. Our arguments make heavy use of k-edge-colored graphs, for k ∈ N, which are graphs G with a (not necessarily proper) edge-coloring c : E(G) → [k]. A matching in G is colorful if it contains exactly one edge from each color. We let #ColMatch(G) be the number of such matchings and #ColMatch be the corresponding computational problem; this problem is #W[1]-hard by the following theorem.

Lemma 7.
There is an fpt Turing reduction from #ColMatch for k-edge-colored graphs to the problem of counting k-matchings in uncolored subgraphs of G; the reduction makes at most 2 k queries, each query is a subgraph of G, and the parameter of each query is k.

Colorful Holant problems
We first adapt Holant problems to an edge-colorful setting by introducing edge-colored signature graphs and colorful Holant problems. In the uncolored setting, the notion of a "Holant" was introduced by Valiant [36] and later developed to a general theory of Holant problems by Cai, Lu, Xia, and various other authors [4,5]. In Section 3.2, we will use colorful Holants to prove Theorem 1 by a reduction from #ColMatch. A more general exposition of this material appears in the first author's PhD thesis [12, Chapters 2 and 5.2].
Definition 8. For a graph G, we denote the edges incident with a given vertex v ∈ V (G) by I(v). For k ∈ N, a k-edge-colored signature graph is a k-edge-colored graph Ω that has a signature f v : {0, 1} I(v) → Q associated with each vertex v ∈ V (Ω). The graph underlying Ω may feature parallel edges.
Given such an Ω, denote its color classes by , there is exactly one edge e ∈ E i with x(e) = 1. Given a set S ⊆ E(Ω), we write x| S for the restriction of x to S, which is the unique assignment in {0, 1} S that agrees with x on S. We then define ColHolant(Ω) as the sum If all signatures in Ω map to {0, 1}, then ColHolant(Ω) simply counts those edge-colorful assignments x with f v (x| I(v) ) = 1 for all v ∈ V (Ω). In the following, we will use this simple fact to rephrase #ColMatch as ColHolant(Ω) for an edge-colored signature graph Ω.
For assignments x ∈ {0, 1} * , write hw(x) for the Hamming weight of x. For a statement ϕ, let [ϕ] be defined to be 1 if ϕ holds and 0 otherwise.  If a signature graph Ω has a vertex v with some complicated signature f associated with it, we can sometimes simulate the effect of f by replacing v with a graph fragment that has only the signature hw ≤1 associated with its vertices. Since ColHolant(Ω) of signature graphs Ω featuring only hw ≤1 can be expressed as a number of edge-colorful matchings via Fact 9, this will allow us to reduce from ColHolant(Ω) to #ColMatch. The graph fragments we are looking for are formalized as edge-colored matchgates: Definition 10. An edge-colored matchgate is an edge-colored signature graph Γ that contains a set D ⊆ E(Γ) of dangling edges. These are edges with only one endpoint in V (Γ), and we consider them to be labeled with 1, . . . , |D|. Furthermore, we require the signature hw ≤1 to be associated with all vertices in Γ. The colors on edges E(Γ)\D will be denoted as internal colors.
We say that an assignment y ∈ {0, 1} E(Γ) extends an assignment x ∈ {0, 1} D if y agrees with x on D. The signature ColSig(Γ) : {0, 1} D → Q of Γ is defined as If Ω is a k-edge-colored signature graph and Γ is an edge-colored matchgate with internal colors disjoint from [k], then we can insert Γ at a vertex v ∈ V (Ω) as follows (see Figure 1): First delete v from Ω, but keep I(v) as dangling edges in Ω. Then insert a disjoint copy of Γ into Ω and identify its dangling edges with I(v). That is, if e is a dangling edge with endpoint u in Ω and e is identified with a dangling edge of the same color with endpoint v in Γ, then we consider e as an edge uv in the resulting graph. 1 Remark 11. When inserting Γ into a signature graph Ω, we implicitly assume that the edgecolors of dangling edges are a subset of the edge-colors in Ω. Furthermore, note that the insertion of matchgates can result in multigraphs.
A simple calculation shows that inserting a matchgate Γ at a vertex v with signature f v preserves ColHolant(Ω), provided that ColSig(Γ) = f v . Applying this insertion operation repeatedly, we obtain the following fact, as proved in Fact 2.17 and Lemma 5.16 of [12].

Fact 12.
Let Ω be a k-edge-colored signature graph such that each v ∈ V (Ω) is associated with some signature f v . If there is a matchgate Γ v with ColSig(Γ v ) = f v for every vertex v, then we can efficiently construct an edge-colored graph G on O( v |V (Γ v )| + v |E(Γ v )|) vertices and edges such that ColHolant(Ω) = #ColMatch(G).
In some cases, Fact 12 may not be applicable, since the involved signatures cannot be realized by matchgates. For such cases, Curticapean and Xia [14] define combined signatures: Rather than realizing a given signature f via matchgates, we may be able to express f as a linear combination of t ∈ N signatures that do admit matchgates. If there are s ∈ N occurrences of such signatures in Ω, then we can compute ColHolant(Ω) as a linear combination of t s colorful Holants, where all involved signatures can be realized by matchgates.

Lemma 13.
Let Ω be a k-colored signature graph. Let s, t ∈ N and let w 1 , . . . , w s be distinct vertices of Ω such that the following holds: For all κ ∈ [s], the signature f κ at w κ admits coefficients c κ,1 , . . . , c κ,t ∈ Q and signatures g κ,1 , . . . , g κ,t such that f κ = t i=1 c κ,i · g κ,i holds. Here, the linear combination is to be understood point-wise.
Given a tuple θ ∈ [t] s , let Ω θ be the edge-colored signature graph defined by replacing, for each κ ∈ [s], the signature f κ at w κ with g κ,θ(κ) . Then we have (1) Proof. We first prove the claim for s = 1. That is, the signature of exactly one vertex w 1 is expressed as a linear combination of signatures.

Claim 14.
Let Ω be a signature graph and let w ∈ V (Ω) be an arbitrary fixed vertex with signature f w . Let g 1 , . . . , g t be signatures and c 1 , . . . , c t ∈ Q be coefficients such that let Ω i be the signature graph obtained from Ω by Proof. In the following, let x range over edge-colorful assignments in {0, 1} E(Ω) . By elementary manipulations, we have This proves the claim.
The lemma now follows by applying Claim 14 inductively for w 1 , . . . , w s . Each of the s involved steps reduces the number of combined signatures by one, and elementary algebraic manipulations hence imply (1).
Lemma 13 allows us to prove hardness results under fpt Turing reductions if ColHolant(Ω) is #W[1]-hard to compute and the values ColHolant(Ω θ ) for all θ can be computed by reductions to the target problem. This is our approach in the remainder of this section.

k-Matchings in bipartite graphs
In the following, we use the techniques from Section 3.1 to prove Theorem 1. We reduce from #ColMatch, which is #W[1]-complete by Theorem 6. Let k ∈ N and let G be a simple kedge-colored graph for which we want to compute #ColMatch(G). We first construct a certain bipartite signature graph Ω bip with ColHolant(Ω bip ) = #ColMatch(G).
Lemma 15. Given a k-edge-colored graph G, let Ω bip = Ω bip (G) denote the signature graph on edge-colors [k] × [2] constructed as follows: Initially, Ω bip is G, where each vertex is associated with the signature hw ≤1 . Then, for each i ∈ [k], perform the following: 1. Add a fresh vertex w i to Ω bip .
2. For e ∈ E(G), of color i and with e = uv, delete e and insert an edge uw i of color (i, 1) and an edge w i v of color (i, 2). Annotate the added edges with π(uw i ) = π(w i v) = e.
3. Note that every colorful assignment x ∈ {0, 1} I(w i ) at a vertex w i has precisely two edges e 1 (x) and e 2 (x) that are incident to w i and assigned 1 by x. We associate w i with the signature f i that maps The constructed signature graph Ω bip satisfies ColHolant(Ω bip ) = #ColMatch(G).
Proof. It is clear that Ω bip is bipartite, since every edge of G appears in Ω bip as a subdivided edge with a subdivision vertex w i for some i ∈ [k]. Let us call an assignment x ∈ {0, 1} E(Ω bip ) satisfying for Ω bip if none of the signatures in Ω bip vanishes on x. The edge-colorful satisfying assignments x ∈ {0, 1} E(Ω bip ) stand in bijection with the edge-colorful matchings of G: In any such x, the vertex w i for i ∈ [k] is incident with two edges e i and e i that are assigned 1 under x and have the same annotation h i = π(e i ) = π(e i ), for some h i ∈ E(G). We can hence contract e i and e i to one edge h i . The resulting edge set is an edge-colorful matching in G due to the signature hw ≤1 at non-subdivision vertices. Reversing this contraction operation, every edge-colorful matching in G can be extended to a unique satisfying assignment x ∈ {0, 1} E(Ω bip ) , and all signatures evaluate to 1 on this assignment.
We now realize the signatures f i in Ω bip by linear combinations of the signatures of edgecolored matchgates. For i ∈ [k], let E i (G) denote the edges of color i in G. Let m i = |E i (G)| and consider the edges in E i (G) to be ordered in some arbitrary fixed way.
Lemma 16. Recall the definition of Ω bip from Lemma 15. For i ∈ [k], let m = m i and let Γ i,1 denote the matchgate on dangling edges I(w i ) that consists of 2m vertices and is defined as follows: First, create independent sets a 1 , . . . , a m and b 1 , . . . , b m , which we call "external" vertices. Then, for all j ∈ [m] and all edges e, e ∈ E(Ω bip ) of colors (i, 1) and (i, 2) with π(e) = π(e ): If π(e) is the j-th edge in the ordering of E i (G), for j ∈ N, then attach e as dangling edge to a j and e as dangling edge to b j .
Let Γ i,2 be defined likewise, with the following addition: For all j ∈ [m], add an extra vertex c j , an edge a j c j of color (i, 3) and an edge c j b j of color (i, 4).
Recall the signature f i from Lemma 15. We can express f i as a linear combination of This is because x trivially is the only satisfying assignment that extends x, since there are no edges other than I(w i ) in Γ i,1 . Concerning Γ i,2 , let x ∈ {0, 1} I(w i ) be a colorful assignment with active edges e 1 , e 2 . We show which implies the claim of the lemma. In the following, we calculate the two cases in (2) separately. To this end, let us say that a path in Γ i,2 is hit by x if at least one of the edges assigned 1 in x is incident with an endpoint of the path. " = " : There are m − 1 paths in Γ i,2 not hit by x, each on the same two colors. This gives (m − 1) 2 = m 2 − 3m + 2 matchings. " = " : There are m − 2 paths not hit by x. Each matching may contain • 2 edges from the intact paths, yielding (m − 2) 2 matchings, or • 1 such edge, yielding 2(m − 2) matchings, or • 0 such edges, yielding 1 matching.
By summing over the disjoint possible choices, we obtain (2).
Using Lemmas 13, 15 and 16, we can now reduce counting edge-colorful matchings in graphs G to the same problem in subdivisions of G. If G is a k-colored graph and t ∈ N is some number, then a t-subdivision of G for t ∈ N is obtained by replacing each edge of G by a path with exactly t inner vertices. We may assign any colors to the new edges.
Lemma 17. Let G be a k-edge-colored graph on n vertices and m edges. Then we can compute #ColMatch(G) with O(2 k ) oracle calls #ColMatch(G ) for graphs G that are subgraphs of a 3-subdivision of G. Furthermore, G has at most 4(n + m) vertices and edges and at most 4k colors.
, the resulting signature graph Ω * is a 3-subdivision of G. It has at most 4(n + m) vertices and edges and at most 4k colors. For θ ∈ [2] k , consider the graph Ω θ obtained from Ω bip by inserting Γ i,θ(i) at w i for every i ∈ [k]. We observe that Ω θ is a subgraph of Ω * .
Invoking Lemmas 13 and 16, we can hence write ColHolant(Ω bip ) as a linear combination of the 2 k quantities ColHolant(Ω θ ) where each Ω θ features only the signature hw ≤1 . By Fact 9, the value ColHolant(Ω θ ) can hence be computed as #ColMatch(G ) for the edge-colored graph G obtained by removing all signatures from Ω θ . As observed above, this is a subgraph of a 3-subdivision of G.
Theorem 1 now follows easily from the hardness of #ColMatch and repeated applications of Lemma 17: Proof of Theorem 1. Let c ∈ N be an arbitrary constant and let G be a k-edge-colored graph for which we wish to compute #ColMatch(G). We first prove Theorem 1 for the edge-colorful case. To this end, we reduce the computation of #ColMatch(G) to instances #ColMatch(F ), where F is obtained from G by repeating c times the operation of taking a subgraph of the 3-subdivision.
Note that this indeed proves the edge-colorful part of Theorem 1: If F is obtained as above, then F is bipartite, with the maximum degree of one side bounded by 2: Put the first and third vertex (if present) of all subdivided edges on one side. Concerning the girth, each cycle C in G will appear in F either (i) as a subdivision of C, or (ii) not at all, because vertices of C or its subdivisions were deleted in the process. No other cycles can be created by the operation.
Each single application of Lemma 17 on a [t]-edge-colored graph F creates 2 t new instances for #ColMatch that are [4t]-edge-colored subgraphs of 3-subdivisions of F . Hence, iteratively applying Lemma 17 for a total of c times on G yields 2 O(4 c k) instances #ColMatch(F ) where each F is a [4 c k]-edge-colored graph on O(4 c (n+m)) vertices and edges that is obtained by repeatedly taking subgraphs of subdivisions. In particular, since c is constant, we reduce counting kmatchings in G to counting O(k)-matchings in the graphs F , hence proving the claimed lower bound under #ETH.
Finally, we show #W[1]-completeness of the uncolored variant of the problem. To this end, we use Lemma 7 to reduce from the edge-colorful variant: To compute #ColMatch(F ) for a [t]-colored graph G, we only need to count t-matchings in uncolored subgraphs of F . This preserves the properties required on F and the claimed lower bound under #ETH.

Matchings in line graphs
We now sketch the proof of Theorem 2, stating that counting k-matchings in line graphs is #W[1]-hard. A wedge is any graph isomorphic to P 2 , the path with two edges, and a wedge packing k · P 2 is the vertex-disjoint union of k wedges. For any graph G, we observe that the number of embeddings of a k-matching in L(G) is equal to the number of edge-injective homomorphisms from a wedge packing k · P 2 to G. To prove Theorem 2, we reduce from the k-matching problem in well-structured bipartite graphs to the latter problem. The following technical lemma encapsulates the delicate interpolation argument used in the reduction. For Lemma 18. For all g, b ∈ N, let a g,b ∈ Q be unknowns, and for all r ∈ N, let P r (y) be the univariate polynomial such that There is a polynomial-time algorithm that, given a number k and the coefficients of P r (y) for all r ∈ N with r ≤ O(k), computes the numbers a t,k−t for all t ∈ {0, . . . , k}.
Proof. Let t ∈ {0, . . . , k}. For all k, i ∈ N, let I k,i be defined as As an intermediate step, we construct a polynomial-time algorithm that allows us, given the coefficients of P r (y) and a number m ∈ N, to compute I k,i for all k, i ∈ N with 2k + i ≤ m. If m = 0, then I 0,0 is the only number we need to compute. We obtain it by observing that P 0 (y) = I 0,0 = a 0,0 . Now suppose that m > 0 and that we inductively already computed the values I k,i for all k, i ∈ N with 2k + i ≤ m. We will compute the values I k,i with 2k + i = m + 1.
Let r be an integer that satisfies 2r − (m + 1) ≥ 0. Furthermore, let C r denote the coefficient of y 2r−(m+1) in P r (y), which is given as input. We want to describe C r as an expression in terms of the unknowns a g,b . To this end, we investigate which of the summands a t,k−t · r k ·(y −t) 2(r−k) contribute to C r .
It follows that the summands with k > m+1 2 do not contribute to C r .
Let us view (y − t) 2(r−k) as a bivariate polynomial in y and t for a moment. Then, by expanding this polynomial in powers of y, there exist univariate polynomials Using bivariate interpolation, we can easily compute all coefficients of Let c 0 , . . . , c m+1−2k−1 be the remaining coefficients. Since only terms with k ≤ (m + 1)/2 contribute to C r , we obtain the following.
Now consider the I k,j from the last sum. Since 2k + j ≤ 2k + m − 2k = m, we have already computed these I k,j recursively. We also know all of the c j , so we can compute the number C r for any r ≥ m+1 2 , where Finally, consider the corresponding matrix A such that and pairwise distinct and large enough r 0 , . . . , r m+1

2
. Column i is an    Each is a set of linearly independent polynomials, and thus the column vectors of A are linearly independent and A is invertible. This allows us to compute the unique solution for the I k,m+1−2k for all k ∈ N with k ≤ m/2. Finally, we argue how to compute the a t,k−t from the I k,i . By definition, we have the following set of linear equations: The corresponding matrix B where (B) i,j = j i for i, j = 0, . . . , k is a Vandermonde matrix and thus invertible. Therefore we can compute the unique solution for the a t,k−t .
We then prove Theorem 2 by showing the following equivalent theorem. Proof. We reduce from the problem of counting k-matchings in bipartite graphs whose rightside vertices have degree ≤ 2 and where any two distinct left-side vertices have at most one common neighbor. For this problem, Theorem 1 for bipartite graphs with girth greater than 4 implies #W[1]-hardness and the desired bound under #ETH. Let (G, k) be an instance of this problem, and let L(G) and R(G) be the left and right vertex sets, respectively. For r ∈ N, we construct a graph G r as follows (see Figure 2): 2. Add r special vertices 1, . . . , r as well as the edges 01, 02, . . . , 0r.
3. For every vertex v ∈ R(G) with deg(v) = 2, remove v and add the set N (v) as an edge to G r . Note that |N (v)| = 2, so N (v) can indeed be considered as an edge.
Since G is a simple graph and any two distinct vertices u, v ∈ L(G) have at most one common neighbor in G, the graph G r is again simple. Let H = H 1∪ · · ·∪ H k be the graph that consists of k vertex-disjoint copies of P 2 . For ϕ ∈ Hom * (H, G 0 ), we say that a wedge H i is We aim at determining the number α k,0 by using an oracle for #Hom * (H). Since we cannot directly ask the oracle to only count homomorphisms with a given number of bad and good wedges, we query the oracle multiple times and recover these numbers via a very specific form of interpolation fueled by Lemma 18. To apply the lemma, we observe the following identity.
Proof. Consider the following way to construct an element ϕ of Hom * (H 1∪ · · ·∪ H k , G r ) whose image consists of g good wedges, b bad wedges, and t test wedges, where g + b + t = k. There are k g+b possibilities to select the set of H i that will be mapped to a good or a bad wedge. Once this selection has been done, there are α g,b edge-injective homomorphisms that map the selected H i to g good and b bad wedges; to see this, note that G 0 and G r have exactly the same good and bad wedges. Finally, the test wedges can only be mapped to the edges incident to 0, for which reason only the star with center 0 is relevant for the test wedges. Each good wedge that has already been placed blocks one edge of the star. Hence the t wedges map into a star S n+r−g with n + r − g leaves. The number of edge-injective homomorphisms that map t wedges into a star with leaves is ( ) 2t .
Note that β k (G r ) is a polynomial in r of degree at most 2k. Setting y = n + r, Claim 22 yields a polynomial identity that is exactly of the form required by Lemma 18, and thus we can compute the unknowns α g,b for all g, b ∈ N with g + b ≤ k from the polynomials β 0 , . . . , β O(k) . Overall, the reduction runs in polynomial time, makes at most O(k 2 ) queries to the oracle, and the parameter of each query is at most O(k). This proves the #W[1]-hardness and the lower bound under #ETH.

Perfect matchings in line graphs of bipartite graphs
In this section we prove Theorem 3. For the hardness part, we consider symmetric signatures that count the number of perfect matchings in (uncolored) complete graphs. These signatures can be realized by (uncolored) matchgates consisting of a clique where every vertex has exactly one further edge that is connected to exactly one dangling edge. The graph obtained by inserting these matchgates is the line graph of the 3-subdivision of a simple graph, which is bipartite.
To prove that the problem is polynomial-time on 3-regular line graphs, we use the fact that every connected 3-regular line graph that is not isomorphic to K 4 must be the union of a triangle packing and a matching [39]. We then consider every triangle as a matchgate that can be contracted, and observe that the resulting Holant can be evaluated in polynomial time. For the proof we deal with symmetric Holants over the Boolean domain. To avoid confusion we will follow the notation of Cai, Lu, and Xia [7] for symmetric signatures. More precisely, let f be a symmetric function over the Boolean domain with arity n. As f is symmetric, the value of f (x) only depends on the hamming weight of x. Therefore we write f (i) for the value of f on inputs with hamming weight i.
Lemma 23. Let F be a set of symmetric signatures such that each f ∈ F satisfies f (x) = #PerfMatch(K hw(x) ). Furthermore, let c be the largest arity of any function in F and let ∆ 1 and ∆ 0 be the unary signatures that force the value of their unique incident edge to be 0 and 1, respectively. Then Holant(F ∪ {∆ 1 , ∆ 0 }) admits a polynomial-time Turing reduction to the problem of counting perfect matchings on graphs that have maximum degree c and are line graphs of bipartite graphs.

Claim 24.
If every signature f v of G can be realized by a matchgate Γ v such that (1) the non-dangling edges of Γ v can be partitioned into cliques such that every vertex of Γ v is contained in at most two cliques, (2) every vertex adjacent to a dangling edge is contained in exactly one clique and (3) every vertex is adjacent to at most one dangling edge, then the graph G ↑ obtained from G by inserting matchgates at every vertex is a line graph.
Proof. If there is a partition of the edges of G ↑ into cliques such that every vertex is contained in at most two cliques then G ↑ is a line graph. We construct such a partition as follows: First, all edges inside the gates are partitioned as in (1) and second, all other edges become cliques of size two itself. Now let v be a vertex of G ↑. Then v is contained in one of the matchgates. If v is not adjacent to a dangling edge then it follows from (1) that v is contained in at most two cliques. Otherwise it follows from (2) that v is contained in exactly one clique inside the gate.
Furthermore v is adjacent to exactly one vertex from another gate (3). Therefore v is contained in only one further clique corresponding to the edge that connects the two gates. This concludes the proof. We are going to realize every signature of F c by a matchgate that satisfies (1), (2) and (3). First, let v be a vertex with f v = ∆ 1 = hw =1 . It follows that the vertex v itself is a matchgate that realizes f v . More precisely the matchgate for v is a single vertex with one dangling edge. As f v is unary, v has degree 1 and therefore the vertex in this matchgate is adjacent to exactly one dangling edge. Furthermore the set of non-dangling edges of this gate is empty and can therefore be partitioned into one empty clique. Hence (1), (2) and (3) hold. Next let v be a vertex of degree d v with f v (x) = #PerfMatch(K hw(x) ). The matchgate for this signature is the complete graph K dv = (V = {u 1 , . . . , u dv }, V × V ) with additional vertices w 1 , . . . , w dv and We denote this matchgate by Γ v (see Figure 3 for an example).
Proof. Let E v be the set of edges of Γ v (including dangling edges) and D v the set of dangling edges. Furthermore we write x i for x(w i ). We have Now let y be an assignment that corresponds to a non-zero summand. Then it holds that y| {{u i ,u j } : x i =x j =1} is the characteristic vector of a perfect matching of the subgraph G x of G with vertices V (G x ) = {u i : x i = 1}. Note that G x is the complete graph on hw(x) vertices. All other bits of y are fixed. On the other hand, every perfect matching on K hw(x) induces exactly one assignment that results in a non-zero summand. As every non-zero summand is one, we have Sig(Γ v , x) = #PerfMatch(K hw(x) ) = f v .
It remains to show that these matchgates satisfy conditions (1), (2) and (3) of Claim 24. We therefore give the clique partition explicitly: All edges in the complete graph are one clique of size d v and each edge {u i , w i } is a clique of size two. Then the vertices u i for i ∈ [d v ] are contained in exactly two cliques and all vertices w i for i ∈ [d v ], that is, the vertices adjacent to the dangling edges are each contained in exactly one clique. Furthermore each of the w i is adjacent to exactly one dangling edge. Applying Claim 24, the resulting graph G ↑ is indeed a line graph. Moreover, it follows from the given clique partition that the primal graph L −1 (G ↑) is a three-subdivision of a simple graph, with additional edges that each are adjacent to exactly one vertex in the subdivision graph. These additional edges belong to the single vertices in the line graph that realize ∆ 1 . Therefore L −1 (G ↑) is odd-cycle free and hence bipartite. Finally the degree of every vertex in G ↑ is bounded by the size of the largest complete graph inside one of the gates which itself is bounded by the maximum arity of a function f v ∈ F. Per assumption this arity is bounded by c and consequently G ↑ is indeed a line graph of a bipartite graph whose degree is bounded by c.

The last remaining ingredient for the proof of Theorem 3 is the following lemma:
Lemma 26. The problem of counting perfect matchings in connected 3-regular line graphs can be solved in polynomial time.
Proof. If the input graph is isomorphic to K 4 , then the number of perfect matchings is 3. Otherwise we can use the work of Zhang and Bylka [39], who investigated connected 3-regular line graphs that are not isomorphic to K 4 . One of their results is the fact that each edge of such a graph is either contained in exactly one triangle or it is adjacent to two triangles ( [39], Characteristic 3.3). Let L = (V, E) be a connected 3-regular line graph that is not isomorphic to K 4 . As we want to count the number of perfect matchings we consider L as a Holant with signature hw = 1 at every vertex. Next we contract every triangle T in the signature grid to a vertex v T . The remaining edges are exactly those that were adjacent to two triangles in L (Note that this operation may produce parallel edges). In the resulting Holant L ↓ every vertex Having this lemma, it is trivial to verify that f is nondegenerate. Now, the dichotomy for Holant * states that Holant * ({f }) is #P-hard if none of the following conditions are satisfied: 1. f has arity no more than two.
The first condition is obviously not true. For the second one we choose k = 1. Then af (k) + bf (k + 1) − af (k + 2) = 0 implies b = 0, that is, the condition does not hold. Finally, the falsity of the third condition can be observed by choosing k = 2.
It follows that Holant * ({f }) and therefore Holant(F ∪{∆ 1 , ∆ 0 }) are #P-hard. We can conclude by applying Lemma 23 with F = {f } as f (x) = #PerfMatch(K hw(x) ). Since the arity of f is 4, it follows that counting perfect matchings in line graphs of bipartite graphs whose degree is bounded by 4 is #P-hard. For the tractability result for 3-regular line graphs we simply apply the algorithm induced by Lemma 26 for every connected component and multiply the outcomes.

Edge-injective homomorphisms
In this section we prove Theorem 4, our dichotomy theorem for counting edge-injective homomorphisms. Let H be a graph. Recall that a set S ⊆ V (H) is a weak vertex-cover if every edge e ∈ E(H) either has a non-empty intersection with S or e does not have any other edges incident to it. The weak vertex-cover number of G is the minimum size of a weak vertex-cover of G. A family of graphs H has bounded weak vertex-cover number if this number can be uniformly bounded by a constant c = c(H) for all graphs H ∈ H; otherwise this number is unbounded.

Polynomial-time counting for bounded weak vertex-cover number
The polynomial-time cases of our dichotomy are established in the following theorem.

Theorem 28.
If H is a family of graphs with bounded weak vertex-cover number, then #Hom * (H) is polynomial-time computable.
The algorithm is based on dynamic programming. Let H ∈ H and G be the input for the algorithm. Isolated edges of H can be removed easily, as their contribution to the number of edge-injective homomorphisms admits a closed formula. The basic idea now is to guess which c vertices in G the vertex-cover of H maps to; after this part of the homomorphism is fixed, all vertices of H outside of the vertex-cover form an independent set, and they can only be distinguished if their neighborhoods are distinct. Since there are at most 2 c different neighborhoods, the graph H has a very simple structure, and a surprisingly technical dynamic programming algorithm, with which we deal in detail in the following, achieves a running time of n O(2 c ) . We now describe one iteration of the algorithm, so let Let P x be the set of all such partitions p. Note that |p| ≤ c and |P x | ≤ c c . We modify the table T into a table T as follows. Let f ≥0 be any index of the table. We set T is a partition in P x . To prove the invariant, it is now sufficient to show the claim that, for every partition p ∈ P x , the number of with p = p is equal to Proof. We contract H into a graph H ϕ as follows: For any u, v ∈ S ∪T that satisfy ϕ(u) = ϕ(v), we contract u and v to a single vertex. Note that N H (u) ∩ N H (v) = ∅ holds because ϕ is edgeinjective, and so the contracted graph does not contain any multi-edges or loops. Let S ϕ be the set of vertices that S ∪ T contracts to in H ϕ . Note that S ϕ is a weak vertex-cover of H ϕ . We contract ϕ to obtain a function ϕ : S ϕ → V (G). This function is now injective, and therefore an embedding from Emb (H ϕ [S ], G).
We now observe that the number of ρ ∈ Hom * (H, G) satisfying the two conditions is identical to the number of ρ ∈ Hom * (H ϕ , G) such that 1. ρ is consistent with ϕ on S ϕ and 2. ρ (x) ∈ ϕ (S) holds for all x ∈ V (H) \ (S ∪ T ).
We use the previous lemma to compute the number of ρ efficiently.
Finally, Lemma 30 allows us to prove Theorem 28.
Proof of Theorem 28. Given a graph G and H ∈ H with weak vertex-cover S ⊆ V (H) such that |S| = c, we want to compute #Hom * (H, G). Let n = |V (G)|. We say that ϕ 1 , and so we compute the number of edge-injective homomorphisms from H to G from the sizes of equivalence classes. Since we are considering edge-injective homomorphisms, we have |T | ≤ |S| 2 ≤ c 2 and hence |S ∪ T | ≤ c 2 + c. It follows that #Hom * (H[S ∪ T ], G) ≤ n c 2 +c . Overall, we have at most n c 2 · n c 2 +c pairs (T, ϕ) for which [T, ϕ] is not empty. Our algorithm first computes a weak vertex-cover S of size at most c, computes the size of each possibly non-empty set [T, ϕ] using Lemma 30, and sums over the values. The overall running time of this algorithm is bounded by a polynomial in n, which concludes the proof.

Hardness for hereditary graph classes
We now consider graph classes H that do not have bounded weak vertex-cover number, and we prove that #Hom * (H) is #W [1]-complete if H is also hereditary. To do so, we first show that every class of unbounded weak vertex-cover number contains one of six basic graph classes (depicted in Figure 4) as induced subgraphs.
For the purposes of this paper, we say that W k is a windmill of size k if it is a matching of size k with an additional center vertex adjacent to every other vertex. Moreover, the subdivided star SS k is a k-matching with a center vertex that is adjacent to exactly one vertex of each edge in the matching. A triangle packing k · K 3 is the disjoint union of k triangles, a wedge is a path P 2 that consists of two edges, and a wedge packing k · P 2 is the disjoint union of k wedges. Figure 4: Example graphs from each of the six minimal graph classes that do not have bounded weak vertex-cover number according to Lemma 31: K 6 , K 3,3 , W 3 , 4 · K 3 , 5 · P 2 , and SS 5 .
Lemma 31. Let us say that a class H contains another class C as induced subgraphs if, for every C ∈ C, there is some H ∈ H such that H contains C as induced subgraph. If H is a class of graphs with unbounded weak vertex-cover number, then H contains at least one of the following classes as induced subgraphs: Proof. Let H be a graph class of unbounded weak vertex-cover number, and let C ∈ N be a constant such that all cliques, bicliques, subdivided stars, windmills, and triangle packings that occur as induced subgraphs in H have size at most C. To prove the lemma, we argue that H contains induced P 2 -packings of unbounded size. Without loss of generality, we assume that H is closed under taking induced subgraphs. Let H ⊆ H be the class of all graphs H ∈ H that do not contain isolated edges. Since H has unbounded weak vertex-cover number, the vertex-cover number of H is unbounded. Curticapean and Marx [13,Lemma 5.2] prove that, in this situation, H contains arbitrarily large cliques, induced bicliques, or induced matchings. By our assumption, the size of every clique and biclique is at most C. Thus for every k, there is a graph H k ∈ H such that H k contains a size-k matching M k ⊆ E(H k ) as an induced subgraph. For every k and every e ∈ M k , we choose an arbitrary vertex v e ∈ V (H k ) \ V (M k ) that is adjacent in H k to one or both endpoints of e. These vertices exist since e is not an isolated edge in H k and M k is an induced matching in H k . Let N k = { v e : e ∈ M k } and note that v e and v e may coincide for distinct e, e ∈ M k . Let A v ⊆ M k be the set of all e ∈ M k such that exactly one endpoint of e is adjacent to v, and let B v ⊆ M k be the set of all e ∈ M k that have both their endpoints adjacent to v.
is an induced windmill of size |B v |. By our assumption on H, the sets A v and B v have size at most C for all v ∈ N k and all k.
Before we argue that arbitrarily large P 2 -packings exist as induced subgraphs, we apply Ramsey's theorem to obtain some more structure. Since M k = v∈N k (A v ∪ B v ) holds, the set N k has size at least k/(2C). Thus the graph class { H k [N k ] : k ∈ N } is infinite, and since we assumed that every clique in H has bounded size, Ramsey's theorem guarantees the existence of independent sets I k ⊆ N k whose sizes are unbounded as k grows.
Finally, we construct a large induced packing of triangles and paths of length 2 using the following greedy procedure: For each v ∈ I k with B v = ∅, we select an arbitrary edge e ∈ B v to contribute one triangle with v, and we remove A v ∪ B v from M k . Similarly, each v ∈ I k with B v = ∅ and A v = ∅ contributes one copy of P 2 and we delete A v ∪ B v from M k . By definition of A v and B v , the vertex v is not adjacent to any edge in M k \ (A v ∪ B v ); moreover, it is not adjacent to any vertex in I k \ {v}. Hence the constructed disjoint union of triangles and paths of length 2 is indeed an induced subgraph of H k . Since all sets A v and B v are of size at most C, the number of components we constructed is at least |I k |/(2C), which is unbounded as k grows. By our assumption on H, at most C of the components are triangles, and at least |I k |/(2C) − C components are copies of P 2 . We conclude that H contains arbitrarily large induced P 2 -packings.
Since hereditary classes H are closed under induced subgraphs, Lemma 31 guarantees that any hereditary class H with unbounded weak vertex-cover number contains at least one of the six graph families defined above as an actual subset of H. We need to prove hardness for each of these six families: If H is the class of all cliques, the class of all bicliques, the class of all subdivided stars, the class of all windmills, the class of all triangle packings, or the class of all wedge packings, then #Hom * (H) is #W[1]-hard.
As we show in the following, ever edge-injective homomorphism from a clique, a biclique, or a windmill into a graph is, in fact, an embedding. Hence the problem #Hom * for these three graph families is equivalent to the corresponding subgraph counting problem. Since these graph families have unbounded vertex-cover number, the main theorem of Curticapean and Marx [13] implies that the subgraph counting problem for these three graph families is #W[1]-hard.
Lemma 33. Let G be a simple graph and let H be a clique, biclique, or windmill. Every edge-injective homomorphism ϕ from H to G is an embedding.
Proof of Lemma 33. Let ϕ be an edge-injective homomorphism from H to G. Clearly, for two distinct vertices x and y of H, we have ϕ(x) = ϕ(y) if x and y are joined by an edge of H or if they have a common neighbor z in H. If H is a clique, then all x, y ∈ V (H) with x = y are adjacent in H. If H is a biclique or a windmill, then any two distinct vertices x and y are either adjacent or have a common neighbor. In either case, ϕ is an embedding. For the class of triangle packings, we devise a straightforward reduction from the problem of counting k-matchings in bipartite graphs. Essentially, we add an additional vertex that is adjacent to all other vertices, and since the original graph was bipartite, every triangle of the triangle packing must use the new vertex. Proof. We reduce from the problem of counting k-matchings in a bipartite graph. Given a simple bipartite graph G = (U ∪ V, E) and a number k, we construct a graph G from G by adding a single apex a, that is, a new vertex a and the edges {a, v} for all v ∈ U ∪ V . Since G is bipartite, every triangle in G consists of a and some vertices u ∈ U and v ∈ V . We denote such a triangle by a v,u . The output of the reduction is the instance (H, G ), where H is the graph k · K 3 . In either case, the edges of H partition into k triangles; let us fix this partition and an arbitrary order on the triangles.
Since G is a simple graph, the homomorphic image of a triangle is a triangle, and exactly one vertex of each of the k triangles is mapped to a. Let ϕ be an edge-injective homomorphism from k · K 3 to G . Let the image of the i-th triangle be {a, u i , v i }. Since ϕ is edge-injective and a is Finally, we claim that the number m k of k-matchings of G can be derived from the number of edge-injective homomorphisms. The homomorphism ϕ can first arbitrarily choose one vertex of each triangle to be mapped to a, which gives it 3 k choices. For the remaining matching of size k, the homomorphism ϕ must map it to a matching in G by edge-injectivity. Thus it can choose one of the 2 k · k! automorphisms of the k-matching. Overall, we get 6 k · k! edge-injective homomorphisms ϕ with M ϕ = M . Thus |Hom * (k · K 3 , G )|/(6 k · k!). The reduction takes polynomial time, increases the parameter from k to |H| = O(k), and requires only one query to the oracle.
For subdivided stars, we reduce from counting k-matchings in well-structured bipartite graphs to (essentially) the graph G 0 that was constructed in the proof of Theorem 20. The analysis is much simpler for subdivided stars since we can guarantee easily that the center vertex is mapped to the newly added vertex 0. Proof. We reduce from the problem of counting k-matchings in bipartite graphs where the degree of right-side vertices is at most two and any two distinct left-side vertices have at most one common neighbor. Let (G, k) be an instance of this problem, and let L(G) and R(G) be the left and right vertex sets, respectively. Starting from G, we construct a new graph G (see Figure 5): isolated vertices. Let y be the neighbor of z and let x be the center vertex of the subdivided star. Then ϕ(y) = 1 and ϕ(x) = 0 holds. Next, let y 1 , . . . , y k be the other degree-2 vertices of H, and let z 1 , . . . , z k be the corresponding degree-1 vertices. Since ϕ is an edge-injective homomorphism, the vertices a i := ϕ(y i ) are mutually distinct and satisfy a i ∈ L(G).
We define the matching M ϕ = {a 1 b 1 , . . . , a k b k } as follows. Note that ϕ(z i ) ∈ {0, 1, 2}. If ϕ(z i ) ∈ R(G), then it is a degree-1 vertex of R(G), and we set b i = ϕ(z i ). Otherwise we have ϕ(z i ) ∈ L(G) and the edge ϕ(y i z i ) exists in G ; we let b i be the unique vertex with N G (b i ) = {a i , ϕ(z i )} that caused this edge to be added to G in the construction. The b i are mutually distinct due to the edge-injectivity. Hence M ϕ is indeed a matching.
For every k-matching M of G, there are (k + 1)! distinct edge-injective homomorphisms ϕ with M = M ϕ since ϕ can choose an arbitrary order for the k + 1 rays of the subdivided star. This proves the claim. Overall, the reduction runs in polynomial time and queries the oracle exactly two times with parameter |H| = O(k).

Hardness for some non-hereditary graph classes
The dichotomy for #Hom * (H) with hereditary graph classes H leaves open some non-hereditary graph classes of interest. In the final part of the paper, we investigate #Hom * (H) for several such classes, namely those of cycles, paths, and packings of constant-length paths. It turns out that the problem of counting edge-injective homomorphisms is #W [1]-hard in all of these cases (excluding the class of matchings, which are packings of length-1 paths).
Theorem 37. For the classes C and P of all cycles and paths, respectively, the problems #Hom * (C) and #Hom * (P) are #W[1]-hard. Furthermore, the problem of counting all edgedisjoint s-t-walks in a given graph is #W[1]-hard.
Theorem 38. For c ∈ N, let PP c be the class of packings of the path P c . Then #Hom * (PP c ) is #W[1]-hard for c ≥ 2 and computable in polynomial time otherwise.

Cycles and paths are hard
First, we deal the problems of counting edge-disjoint cycles, paths and s-t-paths of length k. The first two of these problems are equivalent to the problems of counting edge-injective homomorphisms from C k and P k respectively. In particular it holds that • The number of edge-injective homomorphisms from C k to a graph G equals the number of edge-disjoint k-cycles in G multiplied by k.
• The number of edge-injective homomorphisms from P k to a graph G equals the number of edge-disjoint k-cycles in G multiplied by 2.
The problem of counting edge-disjoint s-t-paths does not directly correspond to a problem of counting edge-injective homomorphisms but nevertheless it is stated for the sake of completeness.
i edges i edges e i+1 Figure 6: Gadgets H v (left) and G i+1 (right) as used in the proofs of Lemma 39 and Lemma 41, respectively.
We will show that the problem #Cycle * of counting edge-disjoint cycles of length k in a graph is #W[1]-hard. First, consider the weighted version of the #Cycle * : Given an undirected graph G, a parameter k ∈ N and a weight function w : E → N bounded by f (k) for a computable function f , #WeightedCycle * denotes the problem of computing where EC k (G) denotes the set of all edge-disjoint cycles of length k in G. Note that setting w to be constant 1 results in the number of edge-disjoint cycles. Proof. We show #W[1]-hardness by constructing an fpt Turing reduction from #Cycle, the problem of counting simple cycles of a given length. This problem was the first one discovered to have a fixed parameter tractable decision version whereas the counting version is #W[1]hard (e.g., see [19]). On input G, k the algorithm works as follows: If k < 3 then return 0. Else consider G x that is obtained from G by substituting each node v ∈ V with degree d v by the gadget graph H v constructed as follows: We start with a path of length 3 such that the intermediate edge is weighted with x. Next we add vertices s 1 v , . . . , s dv v and connect each of them with an edge to one endpoint of the path. After that we add vertices t 1 v , . . . , t dv v and connect each of them with an edge to the other endpoint.
Furthermore add edges {s i v , t j u } and {s j u , t i v } for every edge {u, v} that is the i-th edge of v and the j-th edge of u. The resulting graph is shown in Figure 6. Consider G x as a weighted graph were every edge has weight 1 except for the edges labeled with x as above. Now an oracle call for #Cycle * with input (G x , 6k) yields a polynomial p ∈ Z[x].
Claim 40. The degree of p is bounded by k. Furthermore the coefficient of x k equals twice the number of simple k-cycles in G.
Proof. The shortest edge-disjoint path between any pair of two different edges with weight x is at least 5 (if we exclude the two edges with weight x). As we search for edge-disjoint cycles of length 6k, x can occur at most 6k 5+1 = k times in one cycle. Therefore the degree of p is bounded by k. Furthermore the distance is equal to 5 if and only if the two edges belong to gadgets H v and H u such that {v, u} ∈ E(G). In particular this path either leaves H v through s i v and enters H u through t j u for some i and j or it leaves H v through t i v and enters H u through s j u for some i and j . Now consider an edge-disjoint cycle c of length 6k that includes k edges with weight x. It follows that c = (e 1 , P 1 , . . . , e k , P k , e 1 ) where each e i has weight x and each P i is a path consisting of 5 edges with weight 1. Next let H v i be the gadget containing e i and consider H v 1 . It holds that P 1 either passes through s i v 1 and t j v 2 for some i and j or through t i v 1 and s j v 2 for some i and j . However, if we fix one of this two options, only one possibility remains for all other P 2 , . . . , P k as we cannot turn around in a gadget if we consider edgedisjoint cycles. Therefore there are exactly two edge-disjoint cycles c 1 = (e 1 , P 1 , . . . , e k , P k , e 1 ) and c 2 = (e 1 , P 1 , . . . , e k , P k , e 1 ) that correspond to the cycle c = (v 1 , . . . , v k , v 1 ) in G and vice versa. Furthermore c is simple as c 1 , c 2 are edge-disjoint, that is, the e i 's and therefore the v i 's are pairwise different.
Finally we compute the coefficient of x k by interpolation.
Next we show hardness of the unweighted version by reducing from the weighted version.
Proof. Input G with edge weights bounded by f (k) for a computable function f , k. Again, if k < 3, we hardwire the output. Otherwise we use the following Gadgets: • G 1 is simply one undirected edge e 1 := {a 1 , b 1 } • G i+1 is constructed from G i as follows: We add vertices a i+1 and b i+1 and edges {a i+1 , a i } and {b i+1 , b i }. Furthermore we add a path of length 2i + 1 between a i+1 and b i+1 and denote the i + 1-th edge of this path e i+1 . G i+1 is depicted in Figure 6.
Proof. Proof by induction on k: • The claim holds obviously for G 1 • Consider G k+1 . An edge-disjoint walk from a k+1 to b k+1 either takes the "left" way and therefore contains e k+1 or takes a way through G k : -The "left" way has length 2k + 1 = 2(k + 1) − 1.
-Every way through G k corresponds one-to-one to a closed walk from a k to b k in G k . Applying the induction hypothesis we obtain that there are exactly k edge-disjoint walks from a k to b k in G k , one for every e j for j ∈ [k]. Furthermore each of this walks has length 2k − 1. It follows that there are exactly k edge-disjoint walks from a k+1 to b k+1 , each of length 2 + 2k − 1 = 2(k + 1) − 1. e j is contained in exactly one of this walks for every j ∈ [k].
We conclude that the claim is fulfilled for G k+1 .
Recall the problem from which we reduce and let w M be the maximum weight of an edge. Note that w M ≤ f (k). Now let H i be the gadget constructed from G w M by removing edges e w M , · · · , e i+1 . (H w M = G w M ). Applying Claim 43, we obtain that there are exactly i edgedisjoint walks from a w M to b w M in H i . Furthermore each of this walks has length 2w M − 1. Finally, we construct G from G by substituting each edge e = {a, b} with H w(e) and edges {a, a w M } and {b, b w M }.
Claim 44. The number of edge-disjoint cycles of length (2w M k + k) in G equals Proof. Consider therefore an edge-disjoint cycle c of length (2w M k + k) in G . Assuming c does contain an edge {a, a w M } (that is, it is not entirely contained in one gadget), it follows that c can cross every a w M and b w M at most once. To see this, observe that every time when such a node is reached we can consider the cycle coming from "outside the gadget" (e.g. by choosing a fitting orientation of c). Since c is an edge-disjoint cycle, we have to continue by an edge-disjoint walk through the end of the gadget. This walk has length 2w M − 1 by Claim 43. Now we cannot turn around inside the gadget again and complete the cycle afterwards since otherwise we would have constructed a longer edge-disjoint walk from one endpoint of the gadget to the other, which contradicts Claim 43. It follows that every edge-disjoint cycle of length (2w M k + k) that is not entirely contained in one gadget consists of 2w M − 1 walks through gadgets. Now, taking an edge e = {a, b} with weight w(e) in G corresponds to taking one of the w(e) edge-disjoint walks (a, a w M , it follows that an edge-disjoint cycle of length k in G corresponds to the edge-disjoint cycles of length (2w M k + k) in G that cross the gadgets corresponding to the weighted edges in G, but only if no edge-disjoint cycle of length (2w M k + k) entirely fits in one gadget. However, the latter cannot be the case since the longest edge-disjoint cycle in G w M has length 4w M + 2 and for every k > 2 it holds that Finally, we have to show that the construction of G was an fpt-reduction: • The construction of G takes time at most O(n 2 · f (k) 2 ) (See Claim 42) • The value of the new parameter is 2w M k + k ≤ 2f (k) + k, that is, it does not depend on n This concludes the proof.
Next we use this result to show hardness for paths and s-t-paths. But at first we use an intermediate problem: Lemma 46. Let #vCycle * be the problem of counting edge-disjoint cycles of length k that contain a given vertex. Then #vCycle * is #W[1]-hard Proof. We reduce from #Cycle * . Let EC k (G, v) be the set of all edge-disjoint cycles of length k in G that contain v ∈ V (G).
Claim 47. Recall that EC k (G) denotes the set of all edge-disjoint cycles of length k in G. It holds that Proof. By induction on |V (G)|. If |V (G)| = 0 the union is empty and therefore the claim holds. Otherwise let |V (G)| = n + 1. It holds that Where the third equality follows from the induction hypothesis.

It follows that
Finally |EC k (G − {v i+1 , . . . , v n }, v i )| can be computed by removing vertices v i+1 , . . . , v n from G and counting the edge-disjoint cycles that contain v i .
We are now ready to prove Theorem 37. Recall that it claims #W[1]-hardness of the problems #stPath * of counting edge-disjoint s-t-paths of length k and #Path * of counting edge-disjoint paths of length k.
Proof of Theorem 37. We reduce in both cases from the problem #vCycle * . Given an instance (G, v, k) of this problem we construct the graph G from G by adding vertices s and t and edges {s, v} and {t, v}. Then the number of edge-disjoint s-t-paths of length k + 2 in G equals the number of edge-disjoint cycles in G containing v (1). This proves that #stPath * is #W[1]-hard. For M ⊆ {s, t} let A M be the set of edge-disjoint paths of length k + 2 that do not pass through a vertex u ∈ M and let G M be the graph obtained from G by removing every vertex that lives in M . Note that |A M | can be computed by counting edge-disjoint paths of length k + 2 in G M (2). Now the number of edge-disjoint s-t-paths of length k + 2 in G equals |A ∅ \ (A {s} ∪ A {t} )|. Using the inclusion-exclusion principle we have Finally it follows from (1) and (2) that #Path * is also #W[1]-hard.

Classification of path packings
In this subsection, we prove Theorem 38: Let H c be the class of all P c -packings. Then this theorem claims that #Hom * (H c ) is #W [1]-hard under fpt Turing reductions for c ≥ 2 and polynomial time solvable for c = 1.
Proof of Theorem 38. For H = k · P 1 and an arbitrary graph G, the number of edge-injective homomorphisms from H to G is E(G) k · 2 k · k! .
For P 2 -packings, hardness is shown in Section 4. Now let c ≥ 3. We reduce from the problem of counting k-matchings in bipartite graphs where the degree of right-side vertices is at most two and any two distinct left-side vertices have at most one common neighbor. Let (G = (L∪ R, E), k) be an instance of this problem, and let L and R be the left and right vertex sets, respectively. Starting from G, we construct a new edge-weighted graph G x : 1. Every vertex u ∈ L is relabeled as u 0 .
3. For every u c−2 we add a vertex c c−1 and an edge {u c−1 , u c−2 } with weight x.
4. For every vertex v ∈ R with deg(v) = 2, remove v from the graph and add the set N (v) as an edge to G x .
5. Every edge that is not weighted with x is weighted with 1.
Since G is a simple graph and any two distinct vertices u, u ∈ L have at most one common neighbor in G, the graph G x is again a simple graph. Next consider the weighted sum over all edge-injective homomorphisms from k · P c : Claim 48. For a given x ∈ N we can evaluate S[x] in polynomial time if we have an oracle for #Hom * (k · P 2 ). , u c−2 } for i = j be both in E(Im(ϕ)). We have two cases. Either the preimages of e i and e j belong to the same path but this is not possible as the path has length c ≥ 3. Otherwise the preimages of e i and e j belong to two different paths but again as c ≥ 3 it follows that the edge u c−2 , u c−3 is the image of two different edges which contradicts the fact that ϕ is edge-injective.

Proof. Given
Note that c ≥ 3 is crucial for this claim to hold. Therefore the case c = 2 is much more involved.
We claim that the coefficient of x k in S[x] equals the number of k-matchings in G multiplied by 2 k · k!. Images of path packings contributing to x k are exactly those containing exactly k edges of weight x. Furthermore the image of one single path of length c can contain at most one edge with weight x. Therefore the image of each of the k paths contains exactly one edge with weight x. If this is the case the image of every path i has the form P i = (u i c−1 , u i c−2 , . . . , u i 0 , w i ) where w i is either v ∈ R or u 0 for u = u. Now the following function f is a bijection from these images to the k-matchings in G: f ({P 1 , . . . , P k }) = {g(P 1 ), . . . , g(P k )} where g(P i ) = As u i 0 = u j 0 for two different paths, g is injective and therefore f is also. Now suppose the image is not a k-matching, that is, there are edges e 1 = {u 1 0 , v 1 } and e 2 = {u 2 0 , v 2 } such that e 1 ∩ e 2 = ∅. As u 1 0 = u 2 0 and G is bipartite it follows that v 1 = v 2 . If deg(v 1 ) = deg(v 2 ) = 1 then u 1 0 = u 2 0 which is contradictory. Therefore N (v 1 ) = N (v 2 ) = {u 1 0 , u 2 0 }, but in this case the edge {u 1 0 , u 2 0 } is met by two paths of the path packing which contradicts edge-injectivity. Therefore the image is a k-matching. Finally given a k-matching M = {e 1 , . . . , e k } in G we can construct the corresponding paths P 1 , . . . , P k in G x such that g(P i ) = e i which proves surjectivity. Last but not least partition all edge-injective homomorphisms contributing to x k by their image. As we have 2 possibilities for the endpoints of every path and k! permutations of the k paths it follows that there are exactly 2 k · k! edge-injective homomorphisms that map to the same image. Since we can interpolate the coefficient of x k as in Claim 48 the proof is complete.