Approximate counting CSP seen from the other side

In this paper we study the complexity of counting Constraint Satisfaction Problems (CSPs) of the form #CSP($\mathcal{C}$,-), in which the goal is, given a relational structure $\mathbf{A}$ from a class $\mathcal{C}$ of structures and an arbitrary structure $\mathbf{B}$, to find the number of homomorphisms from $\mathbf{A}$ to $\mathbf{B}$. Flum and Grohe showed that #CSP($\mathcal{C}$,-) is solvable in polynomial time if $\mathcal{C}$ has bounded treewidth [FOCS'02]. Building on the work of Grohe [JACM'07] on decision CSPs, Dalmau and Jonsson then showed that, if $\mathcal{C}$ is a recursively enumerable class of relational structures of bounded arity, then assuming FPT $\neq$ #W[1], there are no other cases of #CSP($\mathcal{C}$,-) solvable exactly in polynomial time (or even fixed-parameter time) [TCS'04]. We show that, assuming FPT $\neq$ W[1] (under randomised parametrised reductions) and for $\mathcal{C}$ satisfying certain general conditions, #CSP($\mathcal{C}$,-) is not solvable even approximately for $\mathcal{C}$ of unbounded treewidth; that is, there is no fixed parameter tractable (and thus also not fully polynomial) randomised approximation scheme for #CSP($\mathcal{C}$,-). In particular, our condition generalises the case when $\mathcal{C}$ is closed under taking minors.


Introduction
The Constraint Satisfaction Problem (CSP) asks to decide the existence of a homomorphism between two given relational structures (or to find the number of such homomorphisms). It has been used to model a vast variety of combinatorial problems and has attracted much attention. Since the general CSP is NP-complete (#P-complete in the counting case) and because one needs to model specific computational problems, various restricted versions of the CSP have been considered. More precisely, let C and D be two classes of relational structures. In this paper we will assume that structures from C, D only have predicate symbols of bounded arity. The constraint satisfaction problem (CSP) parameterised by C and D is the following computational problem, denoted by CSP(C, D): given A ∈ C and B ∈ D, is there a homomorphism from A to B? CSPs in which both input structures are restricted have not received much attention (with a notable exception of matrix partitions [21,22] and assorted graph problems on restricted classes of graphs). However, the two most natural restrictions have been intensively studied over the last two decades. Let − denote the class of all (bounded-arity) relational structures, or, equivalently, indicate that there are no restrictions on the corresponding input structure.
Problems of the form CSP(−, {B}), where B is a fixed finite relational structure, are known as nonuniform or language-restricted CSPs [35]. For instance, if B = K 3 is the complete graph on 3 vertices then CSP(−, {B}) is the standard 3-COLOURING problem [29]. The study of nonuniform CSPs has been initiated by Schaefer [43] who considered the case of CSP(−, {B}) for 2-element structures B. The complexity of CSP(−, {H}), for a fixed graph H, was studied under the name of H-colouring by Hell and Nešetřil [34]. General nonuniform CSPs have been studied extensively since the seminal paper of Feder and Vardi [23] who in particular proposed the so-called Dichotomy Conjecture stating that every nonuniform CSP is either solvable in polynomial time or is NP-complete. The complexity of nonuniform CSPs has been resolved only recently in two independent papers by Bulatov [3] and Zhuk [44], which confirmed the dichotomy conjecture of Feder and Vardi and also its algebraic version [4].
CSPs restricted on the other side, that is, of the form CSP(C, −), where C is a fixed (infinite) class of finite relational structures, are known as structurallyrestricted CSPs. For instance, if C = ∪ k≥1 {K k } is the class of cliques of all sizes then CSP(C, −) is the standard CLIQUE problem [29]. In this case the complexity of CSPs is related to various "width" parameters of the associated class of graphs. For a relational structure A let G(A) denote the Gaifman graph of A, that is, the graph whose vertices are the elements of A, and vertices v, w are connected with an edge whenever v and w occur in the same tuple of some relation of A. Then G(C) denotes the class of Gaifman graphs of structures from C, and we refer to the treewidth of G(A) as the treewidth of A. Dalmau, Kolaitis, and Vardi showed that CSP(C, −) is in PTIME if C has bounded treewidth modulo homomorphic equivalence [11]. Grohe then showed that, assuming FPT = W [1], there are no other cases of (bounded arity) CSP(C, −) solvable in polynomial time (or even fixed-parameter time, where the parameter is the size of the left-hand side structure) [31]. The case of structures with unbounded arity was extensively studied by Gottlob et al. who introduced the concept of bounded hypertree width in an attempt to characterise structurally restricted CSPs solvable in polynomial time [30]. The search for a right condition is still going on, and the most general structural property that guarantees that CSP(C, −) is solvable in polynomial time is fractional hypertree width introduced by Grohe and Marx [32]. Finally, Marx showed that the most general condition, assuming the exponential-time hypothesis, that captures structurally-restricted CSPs solvable in fixed-parameter time is that of submodular width [36].
An important problem related to the CSP is counting: Given a CSP instance, that is, two relational structures A and B, find the number of homomorphisms from A to B. We again consider restricted versions of this problem. More precisely, for two classes C and D of relational structures, #CSP(C, D) denotes the following computational problem: given A ∈ C and B ∈ D, how many homomorphisms are there from A to B? This problem is referred to as a counting CSP. Similar to decision CSPs, problems of the form #CSP(−, D) and #CSP(C, −) are the two most studied ways to restrict the counting CSP, and the research on these problems follows a similar pattern as their decision counterparts.
For a fixed finite relational structure B, the complexity of the nonuniform problem #CSP(−, {B}) was characterised for graphs by Dyer and Greenhill [18] and for 2-element structures by Creignou and Hermann [9]. The complexity of the general nonuniform counting CSPs was resolved by Bulatov [5] and Dyer and Richerby [19]. As in the case of the decision version the complexity of nonuniform counting CSPs is determined by their algebraic properties, and every such CSP is either solvable in polynomial time or is #P-complete. These dichotomy results were later extended to the case of weighted counting CSP, for which Cai and Chen obtained a complexity classification of counting CSPs with complex weights [7].
The complexity of counting CSPs with restrictions on the left hand side structures also turns out to be related to treewidth. Flum and Grohe showed that #CSP(C, −) is solvable in polynomial time if C has bounded treewidth [24]. Dalmau and Jonsson then showed that, assuming FPT = #W [1], there are no other cases of (bounded arity) #CSP(C, −) solvable exactly in polynomial time (or, again, even fixed-parameter time) [10]. Note that the result of Dalmau and Jonsson states that the class C itself has to be of bounded treewidth, while in Grohe's characterisation of polynomial-time solvable decision CSPs of the form CSP(C, −) it is the class of cores of structures from C that has to have bounded treewidth. There has also been some research on counting problems over structures of unbounded arity. First, it was showed that notions sufficient for polynomial-time solvability of decision CSPs can be lifted to the problem of counting CSPs. In particular, the polynomial-time solvability of #CSP(C, −) was shown by Pichler and Skritek for C of bounded hypertree width [40], by Mengel for C of bounded fractional hypertree width [38], and finally by Farnqvist for C of bounded submodular width [20]. Secondly, the work of Brault-Baron et al. showed that the (unbounded arity) structurally-restricted #CSP(C, −) are solvable in polynomial time for the class C of β-acyclic hypergraphs [2]. 1 The results we have mentioned so far concern exact counting; however, many applications of counting problems allow for approximation algorithms as well. For nonuniform CSPs the complexity landscape is much more complicated than the dichotomy results for decision CSPs or exact counting. The analogue of "easily solvable" problems in this case are those that admit a Fully Polynomial Randomised Approximation Scheme (FPRAS): a randomised algorithm that, given an instance and an error tolerance ε ∈ (0, 1) returns in time polynomial in the size of the instance and ε −1 a result which is with high probability a multiplicative (1 + ε)approximation of the exact solution. The parameterised version of this algorithmic model is known as a Fixed Parameter Tractable Randomised Approximation Scheme (FPTRAS). However, unlike exact counting or the decision CSP, it is not very likely there is a concise and clear complexity classification. For instance, Dyer et al. [16] identified a sequence of counting CSPs, Bipartite q-Colouring, that are likely to attain an infinite hierarchy of approximation complexities. Only a handful of results exist for the approximation complexity of counting nonuniform CSPs. The approximation complexity of #CSP(−, {B}) for 2-element structures B was characterised by Dyer et al. [17], where a trichotomy theorem was proved: for every 2-element structure B the problem #CSP(−, {B}) either admits an FPRAS, or is interreducible with #SAT or with the problem #BIS of counting independent sets in bipartite graphs. Apart from this only partial results are known. If B is a connected graph and #CSP(−, {B}) does not admit an FPRAS, then Galanis, Goldberg and Jerrum [27] showed that #CSP(−, {B}) is at least as hard as #BIS. Also, if every unary relation is a part of B a complexity classification of #CSP(−, {B}) can be extracted from the results of Chen et al. [8], 2 see also [28].
Our Contribution It should be clear by now that the picture painted by the short survey above misses one piece: the approximation complexity of structurally restricted CSPs. This is the main contribution of this paper.
Let C be a class of bounded-arity relational structures. If the treewidth of C modulo homomorphic equivalence is unbounded then, by Grohe's result [31], it is hard to test for the existence of a homomorphism from A to B, where A ∈ C, for any instance A, B of CSP(C, −). Using standard techniques (see, e.g., the proof of [37,Proposition 3.16]), this implies, assuming that FPT = #W [1] (under randomised parameterised reductions [15]), that there is not an FPTRAS for #CSP(C, −), let alone an FPRAS. Consequently, the tractability boundary for approximate counting of #CSP(C, −) lies between bounded treewidth and bounded treewidth modulo homomorphic equivalence.
As our main result, we show that for C such that a certain class of graphs (to be defined later) is a subset of G(C), #CSP(C, −) cannot be solved even approximately for C of unbounded treewidth, assuming FPT = W [1] (under randomised which in particular includes #CSP(C, −) as defined here. 2 Chen et al. [8] studied the weighted version of #CSP(−, {B}), and although their result does not provide a complete characterisation of the weighted problem, it allows to determine the complexity of #CSP(−, {B}) as defined here. parameterised reductions). Before we introduce the classes of graphs we use, we review how the hardness of CSP(C, −) or #CSP(C, −) is usually proved.
We follow the hardness proof of Grohe for decision CSPs [31], which was lifted to exact counting CSPs by Dalmau and Jonsson [10]. In fact Grohe's result had an important precursor [33]. The key idea is a reduction from the parameterised CLIQUE problem to CSP(C, −). Let G = (V, E) and k be an instance of the p-CLIQUE problem, where k is the parameter. Broadly speaking, the reduction works as follows. For a class of unbounded treewidth, the Excluded Grid Theorem of Robertson and Seymour [42] guarantees the existence of the (k × k 2 )-grid (as a minor of some structure A ∈ C), which is used to encode the existence of a k-clique in G as a certain structure B. The encoding usually means that G has a k-clique if and only if there is a homomorphism from A to B whose image covers a copy of the grid built in B. For decision CSPs, the correctness of the reduction -that there are no homomorphisms from A to B not satisfying this condition -is achieved by dealing with coloured grids [33] or by dealing with structures whose cores have unbounded treewidth (with another complication caused by minor maps) [31]. For the complexity of exact counting CSPs, the correctness of the reduction [10] is achieved by employing interpolation or the inclusion-exclusion principle, a common tool in exact counting.
None of these two methods can be applied to approximate solving #CSP(C, −). We cannot assume that the class of cores of C has unbounded treewidth, because then by [31] even the decision problem cannot be solved in polynomial time, which immediately rules out the existence of an FPRAS. Interpolation techniques such as the inclusion-exclusion principle are also well known to be incompatible with approximate counting. The standard tool in approximate counting to achieve the same goal of prohibiting homomorphisms except ones from a certain restricted type, is to use gadgets to amplify the number of homomorphisms of the required type. We give a reduction from p-#CLIQUE to #CSP(C, −) by using "fan-grids", formally introduced in Section 3.3. Unfortunately, due to the delicate nature of approximation preserving reductions, we cannot use minors and minor maps and have to assume that "fan-grids" themselves are present in G(C). (In Section 5, we will briefly discuss how a weaker assumption can be used to obtain the same result.) By the Excluded Grid Theorem [42], if C is closed under taking minors, then G(C) contains all the fan-grids (details are given in Section 3.3 and in particular in Lemma 4). Thus, the classes C for which we establish the hardness of #CSP(C, −) includes all classes C that are closed under taking minors. 3

Relational Structures and Homomorphisms
A relational signature is a finite set τ of relation symbols R, each with a specified arity ar(R). A relational structure A over a relational signature τ (or a τ -structure, for short) is a finite universe A together with one relation R A ⊆ A ar(R) for each symbol R ∈ τ . The size A of a relational structure A is defined as Let R be a binary relational symbol. We will sometimes view graphs as {R}structures.
A homomorphism from a relational τ -structure A (with universe A) to a rela- Two structures A and B are homomorphically equivalent if there is a homomorphism from A to B and a homomorphism from B to A.
Let C be a class of relational structures. We say that C has bounded arity if there is a constant r ≥ 1 such that for every τ -structure A ∈ C and R ∈ τ , we have that ar(R) ≤ r.

Treewidth and Minors
The notion of treewidth, introduced by Robertson and Seymour [41], is a wellknown measure of the tree-likeness of a graph [12]. Let G = (V (G), E(G)) be a graph. A tree decomposition of G is a pair (T, β) where T = (V (T ), E(T )) is a tree and β is a function that maps each node t ∈ V (T ) to a subset of V (G) such that The treewidth tw(G) of a graph G is the minimum width over all its tree decompositions. Let A be a relational structure over relational signature τ . The Gaifman graph (also known as primal graph) of A, denoted by G(A), is the graph whose vertex set is the universe of A and whose edges are the pairs (u, v) for which there is a tuple x and a relation symbol R ∈ τ such that u, v appear in x and x ∈ R A . Let C be a class of relational structures. We say that C has bounded treewidth if there exists w ≥ 1 such that tw(A) = tw(G(A)) ≤ w for every A ∈ C.
We say that C has bounded treewidth modulo homomorphic equivalence if there exists w ≥ 1 such that every A ∈ C is homomorphically equivalent to A graph H is a minor of a graph G if H is isomorphic to a graph that can be obtained from a subgraph of G by contracting edges (for more details, see, e.g., [12]). For and an edge between (i, j) and Treewidth and minors are intimately connected via the celebrated Excluded Grid Theorem of Robertson and Seymour.

Theorem 1 ([42]
). For every k there exists a w(k) such that the (k × k)-grid is a minor of every graph of treewidth at least w(k).
Let C be a class of relational structures. We say that C if closed under taking minors if for every A ∈ C and for every minor

Exact Counting CSP
Let C be a class of relational structures. We will be interested in the computational complexity of the following problem.
Name: #CSP(C, −) Input: Two relational structures A and B over the same signature with A ∈ C. Output: The number of homomorphisms from A to B.
We say that #CSP(C, −) is in FP, the class of function problems solvable in polynomial time, if there is a deterministic algorithm that solves any instance We will also consider the parameterised version of #CSP(C, −).
Name: p-#CSP(C, −) Input: Two relational structures A and B over the same signature with A ∈ C. Parameter: A . Output: The number of homomorphisms from A to B.
We say that p-#CSP(C, −) is in FPT, the class of problems that are fixedparameter tractable, if there is a deterministic algorithm that solves any instance The class W [1], introduced in [13], can be seen as an analogue of NP in parameterised complexity theory. Proving W[1]-hardness of a problem (under a parameterised reduction which may be randomised), is a strong indication that the problem is not solvable in fixed-parameter time as it is believed that FPT = W [1]. For counting problems, #W [1] is the parameterised analogue of #P. Similarly to the belief that FP = #P, it is believed that FPT = #W [1]. We refer the reader to [26] for the definitions of W [1] and #W [1], and for more details on parameterised complexity in general.
Dalmau and Jonsson established the following result.
The following problem is an example of a #W[1]-hard problem, as established by Flum and Grohe [25].
Name: p-#CLIQUE Input: A graph G and k ∈ N. Parameter: k. Output: The number of cliques of size k in G.
Note that p-#CLIQUE can be modelled as p-#CSP(C, −) if we set C to be the set of cliques of all possible sizes. The decision version of p-#CLIQUE was shown to be W[1]-hard by Downey and Fellows [14].
Name: p-CLIQUE Input: A graph G and k ∈ N. Parameter: k. Output: Decide if G contains a clique of size k.

Approximate Counting CSP
In view of our complete understanding of the exact complexity of #CSP(C, −) for C of bounded arity (cf. Theorem 2), we will be interested in approximation algorithms for #CSP(C, −). In particular, are there any new classes C of bounded arity for which the problem #CSP(C, −) can be solved efficiently (if only approximately)? We will provide a partial answer to this question (cf. Theorem 3): for certain general bounded-arity classes C (which include classes that are closed under taking minors), the answer is no! The notion of efficiency for approximate counting is that of a fully polynomial randomised approximation scheme [39] and its parameterised analogue, a fixed parameter tractable randomised approximation scheme, originally introduced by Arvind and Raman [1]. We now define both concepts.
A randomised approximation scheme (RAS) for a function f : Σ * → N is a randomised algorithm that takes as input (x, ε) ∈ Σ * × (0, 1) and produces as output an integer random variable X satisfying the condition Pr(|X − f (x)| ≤ εf (x)) ≥ 3/4. A RAS for a counting problem is called fully polynomial (FPRAS) if on input of size n it runs in time p(n, ε −1 ) for some fixed polynomial p. A RAS for a parameterised counting problem is called fixed parameter tractable (FP-TRAS) if on input of size n with parameter k it runs in time f (k)·p(n, ε −1 ), where p is a fixed polynomial and f is an arbitrary computable function.
To compare approximation complexity of (parameterised) counting problems two types of reductions are used. Suppose f, g : Σ * → N. An approximation preserving reduction (AP-reduction) [16] from f to g is a probabilistic oracle Turing machine M that takes as input a pair (x, ε) ∈ Σ * × (0, 1), and satisfies the following three conditions: (i) every oracle call made by M is of the form (w, δ), where w ∈ Σ * is an instance of g, and 0 < δ < 1 is an error bound satisfying δ −1 ≤ poly(|x|, ε −1 ); (ii) the TM M meets the specification for being a randomised approximation scheme for f whenever the oracle meets the specification for being a randomised approximation scheme for g; and (iii) the running time of M is polynomial in |x| and ε −1 .
Similar to [37] we also use the parameterised version of AP-reductions. Again, let f, g : Σ * → N. A parameterised approximation preserving reduction (parameterised AP-reduction) from f to g is a probabilistic oracle Turing machine M that takes as input a triple (x, k, ε) ∈ Σ * × (0, 1), and satisfies the following three conditions: (i) every oracle call made by M is of the form (w, k ′ , δ), where w ∈ Σ * is an instance of g, k ′ ≤ h(k) for some computable function h, and 0 < δ < 1 is an error bound satisfying δ −1 ≤ poly(|x|, ε −1 ); (ii) the TM M meets the specification for being a randomised approximation scheme for f whenever the oracle meets the specification for being a randomised approximation scheme for g; and (iii) M is fixed-parameter tractable with respect to k and polynomial in |x| and ε −1 .
We call a class C of relational structures of bounded arity a fan class if either C has bounded treewidth or for any parameters k, r, ℓ 1 , ℓ 2 ∈ N we have that G(C) contains the fan-grid L(k, r, ℓ 1 , ℓ 2 ).
The following is our main result.

C has bounded treewidth.
Let C be a recursively enumerable class of relational structures of bounded arity and closed under taking minors. We claim that C is a fan class and thus Theorem 3 applies to such C. For this we need Theorem 1. In particular, for any k, r, ℓ 1 , ℓ 2 ∈ N, if C is not of bounded treewidth then, by Theorem 1, G(C) contains an (s × s)grid, where s = max(k + 2ℓ 1 , r + 2ℓ 2 ), and thus also a (k + 2ℓ 1 ) × (r + 2ℓ 2 )-grid.
Proof. Take the subgraph of the (t × t ′ )-grid as shown in Figure 2 and contract the paths shown with thicker edges.
The main idea of the proof is as follows. Assuming that #CSP(C, −) admits an FPTRAS for a fan class C, we will demonstrate that C has bounded treewidth. For the sake of contradiction, assume that C has unbounded treewidth. We will exhibit a parameterised reduction from p-#CLIQUE to p-#CSP(C, −), which gives an FPTRAS for p-#CLIQUE assuming an FPTRAS for p-#CSP(C, −). Given a graph G and an integer k, our reduction builds (in Section 4.1) a graph H = H(G, k, W 1 , W 2 ) in such a way that the number of homomorphisms from a fangrid L = L(k, r, ℓ 1 , ℓ 2 ) (defined in Section 3.3) to H approximates the number of k-cliques in G. Section 4.2 gives details on the number of possible homomorphisms from H to L. (The numbers ℓ 1 , ℓ 2 , W 1 , and W 2 are carefully chosen to make the reduction work.) Section 4.3 then fits the pieces together and describes the reduction in detail.

Construction
Let G = (V, E) be a graph with n = |V | and m = |E|. Let k ∈ N. We construct a graph H(G, k, W 1 , W 2 ) for W 1 , W 2 > 2(n + m) as follows. 4 Let r = k 2 and let ̺ be a correspondence between [r] and the set of 2-element sets {{i, j} | i, j ∈ [k], i = j}. For i ∈ [k] and p ∈ [r], we write i ∈ p as a shorthand for i ∈ ̺(p). The vertex set of H(G, k, W 1 , W 2 ) is the union of two sets H 1 ∪ H 2 , defined by and v ∈ e ⇐⇒ i ∈ p}, where K 1 , . . . , K 12 are disjoint and |K i | = W 1 for i ∈ [4], |K i | = W 2 for i ∈ {5, . . . , 12}.
The edge set of H(G, k, W 1 , W 2 ) consists of the following pairs: • u(v, e, 1, 1) for u ∈ S 1 ⊆ K 1 and (v, e, 1, 1) ∈ H 1 , where S 1 is an arbitrary subset of K 1 whose cardinality is such that the degree of (v, e, 1, 1) is exactly W 1 . (Here we used that where S 2 , . . . , S 12 are arbitrary subsets whose cardinality is such that the degree of (v, e, 1, r), (v, e, k, 1), (v, e, k, r) is exactly W 1 and the degree of the remaining vertices from the list is exactly W 2 .
A homomorphism ϕ is called identity (skew identity) if ϕ(i, p) ∈ {(v, e, i, p) | v ∈ V, e ∈ E} (respectively, ϕ(i, p) ∈ {(v, e, k − i + 1, p) | v ∈ V, e ∈ E}) for all i ∈ [k] and p ∈ [r]. Sometimes we will abuse the terminology and call a (skew) identity homomorphism the restriction of such homomorphism to L 1 (the set of grid vertices).
We define the weight of a homomorphism ϕ from L(k, r, ℓ 1 , ℓ 2 ) restricted to L 1 (the set of grid vertices) to H(G, k, W 1 , W 2 ) as the number of extensions of ϕ to a homomorphism from L(k, r, ℓ 1 , ℓ 2 ).

Weights of Homomorphisms
We start with a simple lemma.

Lemma 5. The weight of an identity or skew identity homomorphism is
Proof. Let ϕ be an identity or a skew identity homomorphism. The images of vertices from L 1 under ϕ are fixed, while vertices from L 2 can be mapped by ϕ to any neighbour of the corresponding fan vertex independently. Since the degree of a corner vertex (v, e, i, p) with i ∈ {1, k} and p ∈ {1, r} is W 1 , and the degree of any other fan vertex is W 2 , the result follows.
The next lemma, which will be proved using Lemma 5, is essentially [10, Lemma 3.1] adapted to our setting, which in turn builds on [31,Lemma 4.4].

Lemma 6. Let N be the number of k-cliques in G. Then the total weight of identity and skew identity homomorphisms is
Proof. We will show that the total weight of identity homomorphisms is N W 4ℓ 1 1 W 8ℓ 2 2 k!. Observe that there is a bijection between the sets of identity and skew identity homomorphisms that maps an identity homomorphism ϕ to a skew identity one, ψ, for which ψ(i, p) = (v, e, k − 1 + 1, p) whenever ϕ(i, p) = (v, e, i, p). Therefore the total weight of skew identity homomorphisms is also N W 4ℓ 1 1 W 8ℓ 2 2 k!. First we give a description of all identity homomorphisms. Let v 1 , . . . , v k be the vertex set of a k-clique in G. For p ∈ [r] with ̺(p) = {a, b}, let e p = v a v b be the edge in G between v a and v b . We define ϕ v 1 ,...,v k : L 1 → H 1 by for every i ∈ [k] and p ∈ [r].
We will need two claims; the first one follows directly from the definition.

Claim 2.
If ϕ is an identity homomorphism from L 1 to H 1 then ϕ = ϕ v 1 ,...,v k for some vertex set v 1 , . . . , v k of a k-clique in G.
Together, claims (A) and (B) imply that there are vertices v 1 , . . . , v k ∈ V and edges e 1 , . . . , e r ∈ E such that for all i ∈ [k] and p ∈ [r] we have ϕ((i, p)) = (v i , e p , i, p). Since ϕ((i, p)) ∈ H 1 , we have v i ∈ e p ⇐⇒ i ∈ p. Hence v 1 , . . . , v k forms a k-clique in G. (End of proof of Claim 2.) Claims 1 and 2 give us a complete description of identity homomorphisms from L 1 to H 1 : a mapping ϕ from L 1 to H 1 is an identity homomorphisms if and only if ϕ = ϕ v 1 ,...,v k for some vertex set v 1 , . . . , v k of a k-clique in G. Hence, the number of such mappings is the number of k-cliques in G multiplied by k!. By Lemma 5, each identity homomorphism can be extended in W 4ℓ 1 1 W 8ℓ 2 2 distinct ways to a homomorphism from L(k, r, ℓ 1 , ℓ 2 ) to H(G, k, W 1 , W 2 ).
We will frequently use the following simple observation. Next we establish an upper bound on the total weight of homomorphisms that are neither identity nor skew identity. Lemma 8. Let G = (V, E) have n = |V | vertices and m = |E| edges, let k = 4k ′ for some k ′ , and let T = log W 2 W 1 . If then the total weight of homomorphisms that are neither identity nor skew identity is at most The key ideas in the proof of Lemma 8 are the following: Firstly, we show that c-c homomorphisms dominate non-c-c homomorphisms. Secondly, using crucially the special structure of fan grids and our choice of k being a multiple of four, we establish an upper bound on any c-c homomorphism that is neither identity nor skew identity. Finally, we give an upper bound on the number of all homomorphisms. These three ingredients together allows us to establish the required bound.
Proof. We prove this lemma in two steps. First, in Claims 1 and 2, we upper bound the weight of a homomorphism that is not identity or skew identity. Second, in Claim 3, we upper bound the number of such homomorphisms. Claim 1. The weight of any c-c homomorphism is greater than the weight of any non c-c homomorphism.
Proof of Claim 1: The weight of a c-c homomorphism ϕ is lower bounded by W 4ℓ 1 1 , since each of the 4ℓ 1 neighbours of a corner vertex in L(k, r, ℓ 1 , ℓ 2 ), say u, can be mapped to any of the W 1 neighbours of the corner vertex ϕ(u) in H(G, k, W 1 , W 2 ).
The weight of any non c-c homomorphism is upper bounded by W 3ℓ 1 +8ℓ 2 1 W ℓ 1 2 , since in a non c-c homomorphism ϕ at least one corner vertex in L(k, r, ℓ 1 , ℓ 2 ), say u, is mapped to a fan vertex ϕ(u) that is not a corner vertex and hence the ℓ 1 neighbours of u can only be mapped to the W 2 neighbours of ϕ(u) in H(G, k, W 1 , W 2 ). The term W 3ℓ 1 +8ℓ 2 1 corresponds to all but one fan vertices in L(k, r, ℓ 1 , ℓ 2 ) being mapped to corner vertices in H(G, k, W 1 , W 2 ).
Take the logarithm base W 2 of the two numbers above. We need to show that which is equivalent to the condition of the lemma. (End of proof of Claim 1.) Claim 2. Let ϕ be a c-c homomorphism that is neither identity nor skew identity. Then its weight does not exceed W 4ℓ 1 1 W 6ℓ 2 2 (2n + m) 2ℓ 2 . Proof of Claim 2: We consider several cases. First observe some symmetries in cc homomorphisms. If ψ is the mapping of H 1 (the "grid" part of H(G, k, W 1 , W 2 )) mapping (v, e, i, p) to (v, e, k − i + 1, p), then the weight of ψ • ϕ equals that of ϕ. Thus we may assume ϕ(1, 1) ∈ {(v, e, 1, 1), (v, e, 1, r) | v ∈ V, e ∈ E}, which gives CASE 1 and CASE 2 below, respectively. Note that by the assumption that k is a multiple of four, both k − 1 and r − 1, where r = k 2 , are odd. CASE 1. ϕ(1, 1) = (v, e, 1, 1) for some v ∈ V, e ∈ E.

Proof of Claim 3:
Since H(G, k, W 1 , W 2 ) has no more than 4W 1 + 8W 2 + nmkr vertices and the (k × r)-grid has kr vertices, the claim follows. (End of proof of Claim 3.) By Claims 1 and 2, the maximum weight of a homomorphism that is not identity or skew identity is W 4ℓ 1 1 W 6ℓ 2 2 (2n + m) 2ℓ 2 . By Claim 3, there are at most (4W 1 + 8W 2 + kr) kr such homomorphisms. The result follows.
Finally, as Lemmas 8 and 9 are only proved for k = 4k ′ , we need to show that the problem for other values of the parameter can be reduced to k of such form. The following lemma takes care of that. Let 4p-#CLIQUE denote the following problem Name: 4p-#CLIQUE Input: A graph G and k ∈ N. Parameter: k. Output: The number of cliques of size 4k in G.
Proof. Let G, k be an instance of p-#CLIQUE and let ε ∈ (0, 1) be an error tolerance. If k = 4k ′ for some k ′ then transform the instance to the instance G, k ′ of 4p-#CLIQUE with the same error tolerance ε. Otherwise repeat the following reduction as many times as required to obtain a parameter of the form 4k ′ .
Suppose there is an FPRAS Alg that approximates the number of (k + 1)cliques in any graph. We construct graph G +s = (V ′ , E ′ ) as follows. Let w 1 , . . . , w s be vertices not belonging to V . Then set V ′ = V ∪ {w 1 , . . . , w s } and E ′ = E ∪ {vw i | v ∈ V, i ∈ [s]}, that is, we connect all the new vertices with all vertices of G. The following claim is easy to verify. Claim 1. Let N be the number of k-cliques in G and let N 1 be the number of (k + 1)-cliques in G. Then the number of (k + 1)-cliques in G +s is sN + N 1 .
Observe also that N 1 < nN , because every (k + 1)-clique contains a k-clique, and for every k-clique C the number of (k + 1)-cliques containing C is at most n − k. Finally, we need the following observation.

Claim 2.
In an instance G, ε of k-#CLIQUE, the number N of k-cliques of G can be assumed to be either 0 or greater than 3/2ε.
Proof of Claim 2. We show that there is a reduction from the general k-#CLIQUE to the probem admitting only instances with the restriction described in Claim 2.
The reduction makes use of the standard idea of blowing up the vertices of G. Let t be a natural number with t > 3 2ε 1/k . Construct G (k) by replacing every vertex v of G with v 1 , . . . , v t , and every edge vw with a complete bipartite graph on the vertices v 1 , . . . , v t , w 1 , . . . , w t . It is easy to see that every k-clique v 1 , . . . , v k in G gives rise to t k k-cliques in G (k) of the form v 1 i 1 , . . . , v k i k . Moreover, every k-clique of G (k) is of this form. Therefore the number of k-cliqes in G (k) equals t k N . By the choice of t t k N > 3 2ε and so if N > 0, this number is greater than 3/2ε. (End of proof of Claim 2.) The reduction works as follows: Apply Alg to the instance G +s , k + 1, where s = 3n ε , with error tolerance ε/3. If it returns a number M output ⌊Q⌋, where Q = M s . We now show that (1 − ε)N < ⌊Q⌋ < (1 + ε)N . By Claim 1 we have or equivalently (by dividing by s), Since by Claim 2 we assume that N > 3/2ε, we obtain On the other hand, we have N 1 < nN and therefore where in the middle inequality we used the choice of s. The result follows.
The rest of the proof establishes "(3) ⇒ (4)". Assume that #CSP(C, −) admits an FPTRAS for a fan class C. Our goal is to show that C has bounded treewidth. For the sake of contradiction, assume that C has unbounded treewidth. We will exhibit a parameterised reduction from p-#CLIQUE to p-#CSP(C, −), which gives an FPTRAS for p-#CLIQUE assuming an FPTRAS for p-#CSP(C, −). Under the assumption that FPT = W [1] (under randomised parameterised reductions [15]), the W[1]-hardness of p-CLIQUE established in [14] implies, by [37,Corollary 3.17], the non-existence of an FPTRAS for the p-#CLIQUE problem, a contradiction.
Let G = (V, E) and k be an instance of the p-#CLIQUE problem. By Lemma 10, we can assume that k = 4k ′ . First, we show that if G has any k-cliques at all, it can be assumed to have many k-cliques. Let s ∈ N and G s be defined as follows. For a given instance G = (V, E), k of p-#CLIQUE and error tolerance ε ∈ (0, 1) using Claim 1, we first reduce it to the instance G s , k of p-#CLIQUE, where Such a choice of s guarantees that if G s contains any k-clique, the number of kcliques it contains is at least 1+ε/2 ε . For simplicity we will have this assumption directly for G. We will also assume that if n = |V | and m = |E|, then 2n+m > 6. Now we construct an instance A, B of p-#CSP(C, −) such that an ε/2-approximation of the number of homomorphisms from A to B yields an ε-approximation of the number of k-cliques in G. Structures A, B will be chosen to be (essentially) A = L(k, r, ℓ 1 , ℓ 2 ) and B = H(G, k, W 1 , W 2 ), where the parameters ℓ 1 , ℓ 2 , W 1 , W 2 are set according to Lemma 9. Since C is a fan class and we assume that C is not of bounded treewidth, there is a structure A in C such that L(k, r, ℓ 1 , ℓ 2 ) is the Gaifman graph G(A) of A.
We enumerate the class C until we find such an A. First we argue that A can be assumed to be a τ -structure where τ consists of a single binary relation symbol; i.e., A is a graph and hence L(k, r, ℓ 1 , ℓ 2 ) itself. Let A be a τ -structure whose Gaifman graph G(A) is L(k, r, ℓ 1 , ℓ 2 ). We show how to construct a τstructure B whose Gaifman graph G(B) is H(G, k, W 1 , W 2 ) such that the set of homomorphisms from A to B is identical to the set of homomorphisms from G(A) to G(B) = H(G, k, W 1 , W 2 ), where W 1 = (2n + m) 4 and W 2 = (2n + m) 2 . The universe of B is the vertex set of H(G, k, W 1 , W 2 ). Let R ∈ τ and take any x ∈ R A . Since L(k, r, ℓ 1 , ℓ 2 ) does not contain triangles, x consists of at most two distinct elements, say a, b ∈ A. Let I ⊆ [ar(R)] be the set of indices i with x[i] = a. For every u, v ∈ B with uv an edge in H(G, k, W 1 , W 2 ), we add (if it is not there already) to R B the tuples y and z defined by y[i] = z[j] = u and y[j] = z[i] = v for every i ∈ I and j ∈ I. Now it is easy to see that a mapping ϕ : A → B is a homomorphism from A to B if and only if ϕ is a homomorphism from G(A) to G(B).
Since the parameters n, m, ℓ 1 , ℓ 2 , W 1 , W 2 satisfy the conditions of Lemma 9, by that lemma we have where N is the number of k-cliques in G, which we want to approximate within ε, and M is the number of homomorphisms from A to B, for which we have an FPTRAS by assumption. Let Q = M/(2W 4ℓ 1 1 W 8ℓ 2 2 k!). The FPTRAS for p-#CSP(C, −) applied with error tolerance ε/2 produces a number M ′ such that We then return ⌊Q ′ ⌋, where It remains to show that (1 − ε)N < ⌊Q ′ ⌋ < (1 + ε)N . On one hand, we have where the first inequality follows from (14) and the definitions of Q and Q ′ , the second inequality follows from (13) and the definitions of Q and N , and the third inequality is trivial provided N is large enough (which we can assume by Claim 2 from the proof of Lemma 10).
Observe that the reduction runs in time f (k) · poly(n + m, ε −1 ) and is a parameterised AP-reduction. Thus, the reduction gives an FPTRAS for N . Theorem 3 is proved.

Conclusions
We do not know whether Theorem 3 holds for all classes of (bounded-arity) relational structures.
With more technicalities (but the same ideas as presented here), one can weaken the assumption on a fan class to obtain the same result (Theorem 3). In particular, it suffices to require that there are polynomials f 1 , f 2 , f 3 , f 4 such that for any parameters k, r, ℓ 1 , ℓ 2 ∈ N, G(C) contains the fan-grid L(k ′ , r ′ , ℓ ′ 1 , ℓ ′ 2 ), where k ′ = f 1 (k, r, ℓ 1 , ℓ 2 ) ≥ k, r ′ = f 2 (k, r, ℓ 1 , ℓ 2 ) ≥ r, ℓ ′ 1 = f 3 (k, r, ℓ 1 , ℓ 2 ) ≥ ℓ 1 , ℓ ′ 2 = f 4 (k, r, ℓ 1 , ℓ 2 ) ≥ ℓ 2 . This can be achieved by making use of Lemma 10 (as it would not be possible to test directly for cliques of all sizes) and by a modification of the construction from Section 4.1 (to accommodate for the fact that some fan-grids may not correspond to cliques due to incompatible numbers).