The complexity of and counting for acyclic conjunctive queries

Arnaud Durand

Cambridge, march 2012

Arnaud Durand enumeration and counting for acyclic conjunctive queries Counting and enumeration

Counting Enumeration I Output the number of solutions I Generate all solutions one by one I Example : ]sat, ]Perfect Matching, Permanent, I Output can be large problems on graph, knots I Natural algorithmic task polynomials

This talk: look at these two tasks for fragments of conjunctive (i.e. , ) queries (mainly ACQ) {∃ ∧}

Arnaud Durand enumeration and counting for acyclic conjunctive queries Outline

I Enumeration

I A tour on complexity measure for enumeration I Results for query problems I Complexity characterization for ACQ I Weighted Counting

I Polynomial representation of query I Counting through polynomial evaluation I Characterization of the tractability frontier for ACQ

Common point : role of free variables in formulas.

Arnaud Durand enumeration and counting for acyclic conjunctive queries Enumeration: measure of complexity

Intractability

I NP-completeness of the existence of one solution (hard to start)

I hard after generation of a part of the solution set (hard to continue)

Tractability

I Polynomial total time (succeed but don’t know how)

I Incremental Polynomial Time (harder as the number of generated solutions increases)

I Polynomial delay (regular process)

Arnaud Durand enumeration and counting for acyclic conjunctive queries Example

I Generate all models of a propositional formula (hum... intractable)

I Generate all independant sets of maximum size of a graph (intractable)

I Generate all maximal (for inclusion) independant sets

I polynomial delay for lexicographic ordering I intractable for reverse lexicographic ordering

I Generate all models of a 2-CNF propositional formula (polynomial delay)

Arnaud Durand enumeration and counting for acyclic conjunctive queries Complexity of enumeration of satisfiability problems

I Let ϕ be a formula with variables x1,..., xn. I If ϕ x SAT : enumerate all solutions of ϕ x ∧ ¬ 1 ∈ ∧ ¬ 1 I If ϕ x SAT : enumerate all solutions of ϕ x ∧ 1 ∈ ∧ 1 Theorem (Creignou, Hebrard’97) In the Boolean case, there is no other efficient than the one described above. Consequently, easy (i.e. polynomial delay) cases are Horn, Anti-Horn, 2-CNF and affine.

Schnoor & Schnoor’07 The situation is more complex for CSP on arbitrary finite domain See also Bulatov, Dalmau, Grohe & Marx’10

Arnaud Durand enumeration and counting for acyclic conjunctive queries Enumeration algorithm: some precision

 Precomputation step in two steps: + Enumeration step(s)

I Computation models (in this talk) : RAM with uniform cost (but with bounded values in registers) I Let be an enumeration algorithm for Enum(R) and x I . A ∈ I timei (x) denotes the time when the algorithm finishes to write the ith solution if it exists. I delayi (x) = timei (x) timei (x). +1 − Delay may be : sub-exponential, polynomial, linear, constant (?) Warning: space is an important factor!

Arnaud Durand enumeration and counting for acyclic conjunctive queries Small classes of enumeration problems

I An enumeration algorithm is constant delay if there is a A constant c such that for any x I and i, delayi (x) c. ∈ ≤ I Enum(R) is computable with constant delay (Enum(R) Constant-Delay) if there is a constant delay ∈ algorithm which computes Enum(R). A I Enum(R) Constant-Delaylin if it is reducible in linear ∈ time (in the input size) to a problem in Constant-Delay

precomputation reduction ≡

Arnaud Durand enumeration and counting for acyclic conjunctive queries Query problems

Query

I = set of formulas L I = set of (finite) structures S Enumeration problem Enum( , ) L S input: φ and ∈ L A ∈ S output: enumerate φ( ) = ¯a Dk ( , ¯a) = φ(¯x) A { ∈ | A | } Counting problem Count( , ) L S input: φ and ∈ L A ∈ S output: φ( ) = ¯a Dk ( , ¯a) = φ(¯x) | A | |{ ∈ | A | }|

Arnaud Durand enumeration and counting for acyclic conjunctive queries Complexity Measures

Framework for complexity analysis of multi-parameterized problems Parameters , ϕ (inputs) A ϕ( ) A But also: number of free variables, of quantified variables, alternation, arity...

I , ϕ and ϕ( ) : Combined Complexity. |A| | | | A | I and ϕ( ) : Data Complexity |A| | A | I ϕ and ϕ( ) : Expression Complexity | | | A | Parameterized complexity: express the complexity in terms of , ϕ and ϕ( ) but consider ϕ as a parameter. |A| | | | A | | |

Arnaud Durand enumeration and counting for acyclic conjunctive queries Some tractable cases for enumeration

Data complexity τ I degd : the class of τ-structures of maximal degree d. τ ≤ Enum(fo, deg ) constant-delaylin. (D. Grandjean’07, Lindell’08) d ∈ Delay : triply exponential in the size of formula (Kazana, Segoufin’10) τ I twk : the class of τ-structures of treewidth at most k. τ Enum(mso, tw ) linear-delaylin. (Bagan’06, Courcelle’07, Frick, ..) k ∈

Arnaud Durand enumeration and counting for acyclic conjunctive queries Conjunctive Queries

Conjunctive Queries (CQ)

I : , -fragment of first-order logic i.e. formulas L {∃ ∧} ϕ(¯x) y¯ψ(¯x, y¯) where ψ is a conjunction of atoms. ≡ ∃ I Combined complexity of : NP-complete. No hope for enumeration.

I Tractable fragments for decision by restricting the formula (acyclicity, decomposition methods).

Arnaud Durand enumeration and counting for acyclic conjunctive queries Hypergraph associated to formulas

I The hypergraph of a formula ϕ is the hypergraph H = (V , E) such that

I V is the set of variables of ϕ I for each atom R(¯v) of ϕ, we associate a hyperedge var(R(¯v))

t u

x

v y

z

Arnaud Durand enumeration and counting for acyclic conjunctive queries Acyclic Hypergraph

Most general notion: α-acyclicity. An hypergraph is α-acyclic if the application of the following rules as long as possible outputs the empty hypergraph:

1. Remove hyperedges contained in other hyperedges; 2. Remove vertices that appear in at most one hyperedge.

A conjunctive query is acyclic if its associated hypergraph is acyclic.

Arnaud Durand enumeration and counting for acyclic conjunctive queries Acyclic hypergraph/query: examples

Acyclic Cyclic Acyclic

Large class of hypergraph/queries. Base case for more evolved decomposition methods. Remark: Adding an edge to a cyclic hypergraph may result in an acyclic hypergraph.

Arnaud Durand enumeration and counting for acyclic conjunctive queries Acyclic Hypergraph: alternative definition

A join tree of a hypergraph = (V , E) is a pair ( , λ) where H T = (VT , T ) is a tree and λ is a function from VT to E such that: T I For each e E, there is a t VT such that λ(t) = e (each ∈ ∈ vertex of is a bag containing one edge) T I For each v V , the set t VT : v λ(t) is a connected ∈ { ∈ ∈ } subtree of T . Equivalent characterization : is acyclic iff it has a join tree. H

Arnaud Durand enumeration and counting for acyclic conjunctive queries Acyclic Hypergraph: alternative definition Acyclic

I organize the edges of a graph into a “join tree”

e a, c, e, g

f d g a, b, c a, e, f c, d, e a b c

I with a connectivity condition: edges that contain vertex v are connected in the tree

I hypergraph is acyclic if it has a join tree

Arnaud Durand enumeration and counting for acyclic conjunctive queries

8/20 Complexity of acyclic conjunctive queries

ACQ Acyclic Conjunctive Queries. ACQ=6 Acyclic Conjunctive Queries with inequalities Example: ϕ(x, y) z t u(Rxyz Ryzt Rztu Syt x = u) ≡ ∃ ∃ ∃ ∧ ∧ ∧ ∧ 6 Known results ACQ solvable in O( ϕ ϕ( ) ) times (Yannakakis’81) | | × |A| × | A | ACQ=6 solvable in O(2O(|ϕ|) ϕ( ) log2( )) times × |A| × | A | × |A| (Papadimitriou & Yannakakis-99) or in O(( ϕ !) ϕ( ) ) (Bagan-D.-Grandjean-07) | | × |A| × | A |

Arnaud Durand enumeration and counting for acyclic conjunctive queries Yannakakis algorithm

Input:( , ϕ), a tree decomposition T A - Take a leaf t VT , let R(¯x, z¯) ∈ the associated atom. - Take its father associated to S(¯x, y¯)( y¯ z¯ = ) { } ∩ { } ∅ Filter relation S in by relation A R : S(x,y)

S := (¯a, b¯) S and c¯(¯a, c¯) R { ∈ ∃ ∈ } R(x,z)

Arnaud Durand enumeration and counting for acyclic conjunctive queries Yannakakis algorithm

Input:( , ϕ), a tree decomposition T A - Take a leaf t VT , let R(¯x, z¯) ∈ the associated atom. - Take its father associated to S(¯x, y¯)( y¯ z¯ = ) { } ∩ { } ∅ Filter relation S in by relation A R :

S(x,y) S := (¯a, b¯) S and c¯(¯a, c¯) R { ∈ ∃ ∈ }

Continue bottom up with new data and drop R(¯x, z¯) from the list of atoms

Arnaud Durand enumeration and counting for acyclic conjunctive queries Enumeration of ACQ

Enumeration Can we enumerate the results efficiently ?

Easy but not that fast!

0 I let ϕ (x1) x2 ... xk y¯ϕ(¯x, y¯) ≡ ∃ 0 ∃ ∃ I For a ENUM(ϕ , ) ∈ A I let ϕa ϕ(a, x ,..., xk , y¯) ≡ 2 I For b¯ ENUM(ϕa, ) : output (a, b¯) ∈ A Linear O( ϕ ) delay. | | × |A| Similarities with the SAT enumeration in easy cases.

Arnaud Durand enumeration and counting for acyclic conjunctive queries Enumeration of ACQ

Easy and fast if all variables are free (i.e. participate to the result).

I Compute a tree decomposition

I Filter each parent with its children so that only tuples that can be extended to a solution remain (”local” consistency)

I run through the tree and output the solutions

Linear O( ϕ ) precomputation and constant O( ϕ ) delay. | | × |A| | | Works also with disequalities (but delay exponential in ϕ ) | |

Arnaud Durand enumeration and counting for acyclic conjunctive queries What’s the point with enumeration

Tree decomposition T for ϕ

- Blue boxes : quantified variables only - Yellow boxes : free variables only - In real life : green boxes also...

Good situation

Arnaud Durand enumeration and counting for acyclic conjunctive queries What’s the point with enumeration

Tree decomposition T for ϕ

- Blue boxes : quantified variables only - Yellow boxes : free variables only - In real life : green boxes also...

Bad situation

Arnaud Durand enumeration and counting for acyclic conjunctive queries Further question

I Can we do better than linear delay (with linear precomputation) ?

I Can we find other fragments with constant delay ?

I Can we fully characterize the enumeration complexity of acyclic conjunctive queries?

Arnaud Durand enumeration and counting for acyclic conjunctive queries Free-connex acyclic formulas

I Let H = (V , E) be an acyclic hypergraph and S V . ⊆ I H is S-connex acyclic if there is an acyclic hypergraph H0 = (V , E 0) and a tree-structure T of H0 such that 0 I E E ⊆0 0 0 0 I e E e E : e e (H inclusive extension of H) ∀ ∈ ∃ ∈ ⊆ I there is a connex subset A of vertices of T such that S t∈A λ(t) = S =6 I A formula ϕ is free-connex acyclic or CCQ if its hypergraph is free(ϕ)-connex acyclic.

Arnaud Durand enumeration and counting for acyclic conjunctive queries Example of S-connex acyclic hypergraph

I Let H = (V , E) with V = a, b, c, d, e, f and { } E = a, b, c , c, d, e , c, d, f and S = b, c, d {{ } { } { }} { } a, b, c

b, c

c, d, ec, d c, d, f

Arnaud Durand enumeration and counting for acyclic conjunctive queries Other characterisation of free-connex acyclic formulas

I Let H = (V , E) be a hypergraph and S V . An S-path is a ⊆ path (x, y1,... yn, z) of size at least 2 such that I x S, z S ∈ ∈ I for any i, yi / S ∈ I there is no hyperedge e E such that x, z e ∈ ∈ Lemma H is S-connex acyclic iff H is acyclic and doesn’t admit any S-path. This property can be checked in polynomial time.

Free-connex acyclicity: ”being grouped” up to hypergraph padding

Arnaud Durand enumeration and counting for acyclic conjunctive queries Matrix Multiplication

Matrix Product Enumeration Given two matrices A and B (with coefficients in some space), - enumerate all Ci,j or - enumerate the indices (i, j) of C = A B such that Ci,j = 0. × 6 Boolean case: solutions of

Φ(x, z) y E(x, y) E(y, z). ≡ ∃ ∧

Arnaud Durand enumeration and counting for acyclic conjunctive queries Dichotomy result (Bagan-D.-Grandjean’07)

Theorem: Let ϕ be a simple ACQ (resp. ACQ=6 ) formula and assume that the boolean matrix product cannot be done in linear time. Then one of the two following cases hold:

I ϕ is free-connex acyclic

I Enum(ϕ) Constant-Delaylin ∈ I Eval(ϕ) can be evaluated in time O( + ϕ( ) ) |A| | A | or

I ϕ is not free-connex acyclic

I Enum(ϕ) / Constant-Delaylin ∈ I Eval(ϕ) cannot be evaluated in time O( + ϕ( ) ) |A| | A |

Arnaud Durand enumeration and counting for acyclic conjunctive queries Proof of hardness

ϕ ACQ CCQ i.e., acyclic but not free(ϕ)-connex. ∈ − Main steps :

I Find a S-path (recall : S = free(ϕ))

I From two boolean matrices, A and B construct a structure , A in linear time, such that:

I encodes A and B. A I Data for A and B are on each side of the S-path I indices of non zero coefficients of A B are (pairs of) vertices related in the path. × Some problems to solve : the path may be arbitrary, there are other ”parts” in the query, ...

Skip rest of proof

Arnaud Durand enumeration and counting for acyclic conjunctive queries Proof of hardness

ϕ ACQ CCQ i.e., acyclic but not free-connex. ∈ − Hφ admits a chordless S-path P = (x, z ,..., zk , y) with k 1, so 1 ≥ that

I P is a path: there are k + 1 hyperedges 0 0 e0, e1,..., ek−1, ek E that contain e0 = x, z1 , e1 = 0 ∈ 0 { } z , z ,..., e = zk− , zk , e = zk , y { 1 2} k−1 { 1 } k { } I P is an S-path: x, y S and z1,..., zk−1 / S ∈ ∈ 0 I P is chordless: for each e E, e P 1 or e P = e for ∈ | ∩ | ≤ | ∩ | i some i, (0 i k) ≤ ≤

Skip rest of proof

Arnaud Durand enumeration and counting for acyclic conjunctive queries Proof of hardness

ϕ simple formula ϕ of the form:

ϕ(x, y, ¯t) z ... zk u¯ψ(x, y, z¯, ¯t, u¯) ≡ ∃ 1 ∃ ∃ with ψ conjunction of atoms Ae , e E of the following form ∈ (¯v ¯t, u¯ ): ⊆ { } 1. Re (x, z1, v¯)

2. Re (zk , y, v¯)

3. Re (zi , zi , v¯) where 1 i < k +1 ≤ 4. Re (w, v¯) where w x, y, z ,..., zk ∈ { 1 } 5. Re (¯v)

Arnaud Durand enumeration and counting for acyclic conjunctive queries Proof of hardness

Transformation r of the structure: to each σAB -structure = (D, A, B) associates the following 0: A A 0 0 I = (D , (Re )e∈E ) A0 I D = D : here is a new special ”padding“ symbol ∪ {⊥} ⊥ I For each e E define the relation of arity p, Re according to the form of∈ its (unique) occurrence in ϕ p−2 1. Re = A × {⊥}p−2 2. Re = B × {⊥}p−2 3. Re = I where I is the identity (equality) relation of D (I =×( {⊥}a, a): a D ) { p−1∈ } 4. Re = D ×p {⊥} 5. Re = {⊥}

Arnaud Durand enumeration and counting for acyclic conjunctive queries Proof of hardness

Π( ) = A B A × Fact 1: The map r : 0 is computable in time O( ) A → A |A| Fact 2: ϕ0( 0) = Π( ) m A A × {⊥} Fact 3: The projection (a, b, c¯) (a, b) is a one-one mapping → from ϕ( 0) onto Π( ) A A

Arnaud Durand enumeration and counting for acyclic conjunctive queries Conclusion for enumeration

I Preceeding result shows some dichotomy in the complexity of enumeration (not in the same sense as usual dichotomy results in complexity).

I Dichotomy distinguishes tractable and very tractable cases

I Dichotomy based on positions of free variables in the formula

Arnaud Durand enumeration and counting for acyclic conjunctive queries #ACQ

Here, situation differs more drastically if quantified variables are allowed. Theorem (Pichler, Skritek’11)

I If only quantifier free formulas are authorized as inputs, then #ACQ is computable in polynomial time.

I #ACQ is #P-complete even for formulas with only one existentially quantified variable.

Hardness result (interpretation)

Given bipartite graph G, one construct a structure G and an A acyclic conjunctive formula ϕG (¯x) = yφ(¯x, y) such that : ∃ The number of perfect matching in G = ϕG ( G ) | A |

Arnaud Durand enumeration and counting for acyclic conjunctive queries #ACQ

End of the story for #ACQ?

I What about weighted counting for ACQ?

I Hardness or tractability for counting the disjunction (or conjunction) of, say, two ACQ?

I One quantifier is enough to design hard instance but is that all we can say?

I Can we isolate island of tractability for #ACQ with quantified variables? or better chart the tractability frontier for quantified #ACQ?

Arnaud Durand enumeration and counting for acyclic conjunctive queries Weighted counting

I F: ring with operations + and × I : finite structure of domain D S I F-weight function for : mapping w : D F k S → I If ¯a D , the weight of ¯a is ∈ k Y w(¯a) = w(ai ). i=1

#FCQ (resp. #FACQ) Input: A conjunctive query (resp. acyclic) Φ = ( , φ) and an S F-weighted function w P Output: ¯a∈φ(S) w(¯a). When w is the constant function 1, this value is equal to φ( ) . | S |

Arnaud Durand enumeration and counting for acyclic conjunctive queries Weighted counting

What is the complexity of #FACQ for quantifier free formulas? Either in terms of number of symbolic operation or in number of bits (for spaces where iterated multiplication and addition is polynomial time) Strategy

I Consider query instances as polynomials

I Construct efficiently arithmetic circuits that ”recognize” these polynomials

I Evaluate the polynomial to solve the weighted counting problem

Arnaud Durand enumeration and counting for acyclic conjunctive queries Arithmetic circuits

Arithmetic circuit over F

I Labeled directed acyclic graph (DAG) with vertices (gates) with indegree (fanin) 0 or 2.

I Input gates have fanin 0 and are labeled with constants from F or variables X1, X2,..., Xn. I Computation gates have fanin 2 and are labeled with or +. × I One gate with fanout 0: the output gate

I The size of the circuit is the number of gates

I The depth is the length of the longest path form an input gate to the output gate

Arnaud Durand enumeration and counting for acyclic conjunctive queries 872 G. Malod

x1 x1 x2 x1 x2 x2

++

Formules VPe NC1 ××

+

x2 x1 x2 x2

++ Circuits faiblement VPws NL ×× asym´etriques

+

x1 x2 x2

++ Circuits Arithmetic circuit: example multiplicativement VP LOGCFL ×× disjoints

+

x1 x2

++ P(X1, X2) = 2X1X2 + (X1 + X2)X2 2 Circuits VPnb P = 3X1X2 + X2 × ×

+

Figure 1. Classes d´efinies par des circuits arithm´etiques.

Arnaud Durand enumeration and counting for acyclic conjunctive queries 872 G. Malod

x1 x1 x2 x1 x2 x2

++

Formules VPe NC1 ××

+

x2 x1 x2 x2

++ Circuits Multiplicatively disjoint circuits faiblement VPws NL ×× asym´etriques

+

x1 x2 x2

A circuit is multiplicatively ++ Circuits disjoint if, for each -gate, its × multiplicativement VP LOGCFL two input subcircuits are disjoint. ×× disjoints

+

x1 x2

++

Arnaud Durand enumeration and counting for acyclic conjunctive queries Circuits VPnb P × ×

+

Figure 1. Classes d´efinies par des circuits arithm´etiques. Arithmetic circuits

Valiant’s setting for computation of families of polynomials by families of circuits. Same computational power

I polynomial size circuits of polynomial degree

I multiplicatively disjoint circuits

I logarithmic depth semi-unbounded circuits.

Algebraic equivalent of LOGCFL...

See: Valiant, Burgisser, Koiran, Malod, ...

Arnaud Durand enumeration and counting for acyclic conjunctive queries Polynomials representing queries

Q-Polynomials Φ = ( , φ) : conjunctive query with domain D. The following S polynomial Q(Φ) in the variables Xd d D is assigned to Φ: { | ∈ }

X Y X Y µd (a) Q(Φ) := Xa(x) = Xd , a∈φ(S) x∈var(φ) a∈φ(S) d∈D

where µd (a) = x var(φ) a(x) = d is the number of variables |{ ∈ | }| mapped to d by a. Example Φ = ( , φ) such that S φ( ) = (1, 3, 2, 5), (1, 2, 1, 3), (5, 2, 3, 1), (1, 1, 2, 1), (4, 2, 1, 2) . S { } Then:

2 3 2 Q(Φ) := 2X1X2X3X5 + X1 X2X3 + X1 X2 + X2 X1X4.

Arnaud Durand enumeration and counting for acyclic conjunctive queries Polynomials representing queries

I The number of variables in Q(Φ) is D , the size of the | | domain of S I Q(Φ) is homogeneous of degree free(Φ) | | I No bijective correspondence between solutions of the query and monomials

I Existential quantification in formulas does not correspond to projection on some polynomial variable.

Arnaud Durand enumeration and counting for acyclic conjunctive queries #FACQ for quantifier free acyclic formulas

Here and after: joint work with Stefan Mengel. Φ = + φ k k |S| | |

Theorem Given an acyclic quantifier free conjunctive query Φ = ( , φ), we S can in time polynomial in Φ compute a multiplicatively disjoint k k arithmetic circuit C that computes Q(Φ). Corollary

The problem #FACQ is computable in polynomial time

Skip proof

Arnaud Durand enumeration and counting for acyclic conjunctive queries Computation of Q(Φ) for Φ acyclic: proof

By induction, adapting Yannakakis algorithms for ACQ

I Φ = ( , φ): the input S I ( , λ): the join tree associated with φ T I For t VT , φt : conjunction of constraints corresponding to ∈ the subtree t rooted at t T S 0 0 I Set et = var(φt ) = t ∈Tt var(λ(t ))

Skip rest of proof

Arnaud Durand enumeration and counting for acyclic conjunctive queries Computation of Q(Φ) for Φ acyclic: proof

Compute the more general polynomial: X Y ft,¯a,c = Xα(x). α¯∈φt (S) x∈c α¯∼¯a Where c λ(t), ¯a is an assignment of some variable of φ and ⊆ α¯ ¯a means ”¯α agrees with ¯a on common variables”. ∼ Strategy and Problems

I Compute inductively from some fti ,¯ai ,ci where ti is a child of t. I If two children share a variable there is a risk of overcounting so...

I Partition the variables in λ(t) and assign parts to children

Skip rest of proof

Arnaud Durand enumeration and counting for acyclic conjunctive queries Computation of Q(Φ) for Φ acyclic: proof

I The case of a leaf t VT is immediate. ∈ I Let t VT and t , ..., tk its children in VT ∈ 1 I c0, c1, ..., ck : partition of c into disjoint sets such that Sk ci ei c, for i = 1, ..., k and c c et ⊆ ∩ 0 ⊆ \ i=1 i X Y ft,¯a,c = Xα(x) α¯∈φt (S) x∈c α∼a X¯ ¯ Y Y Y = X X X α¯(x) ··· α¯(x) α¯(x) α¯∈φt (S) x∈c1 x∈ck x∈c0 α¯∼¯a

Arnaud Durand enumeration and counting for acyclic conjunctive queries Computation of Q(Φ) for Φ acyclic: proof

Last remark

I Let At = ((λt ( ) n φt1 ( )) n φt2 ( )) n ... n φtk ( ). S S S S I Each solutionα ¯ φt ( ) can be uniquely expressed as the ∈ S natural join of a β¯ At with someα ¯i φt ( ), i = 1, ..., k, ∈ ∈ i S compatible with β (converse also true)

X Y Y Y ft,a,c = X X X ¯ α¯(x) ··· α¯(x) α¯(x) α¯∈φt (S) x∈c1 x∈ck x∈c0 α∼a X¯ ¯ X X Y Y Y = X X X ¯ ··· α¯1(x) ··· α¯k (x) β(x) ¯ x∈c x∈ck x∈c β∈At α¯1∈φt1 (S) α¯k ∈φtk (S) 1 0 β¯∼¯a α¯ ∼β¯ α¯ ∼β¯ X 1 k Y = ft ,β,c ft ,β,c X ¯ 1 1 ··· k k · β(x) β¯∈At x∈c0 β¯∼¯a

Arnaud Durand enumeration and counting for acyclic conjunctive queries Union and intersection of acyclic queries

Theorem Computing the size of the union and the intersection of query results to two quantifier free #ACQ-instances are both #P-complete. This result remains true for #ACQ on boolean domain and arity at most 3. Proof by chain of reductions

I #circuitSAT

I #( - -grid)-circuitSAT: circuit sat with and gate on a ∧ ¬ ∧ ¬ grid.

I #CQ on a grid

Arnaud Durand enumeration and counting for acyclic conjunctive queries Pause to ponder Quantified #ACQ is hard [Pichler, Skritek 2011] Bad news

I The conjunctionI (or#ACQ disjunction) clearly of in two #PACQ (guessmakes assignment counting to the free variables, hard solve remaining BACQ instance with standard algorithm)

I Idem for ACQ forI one#ACQ existentially is #P-hard quantified already variable. with a single -quantifier and 9 simple structure

But... formula in Pichler and Skritek’s hardness proof looks like that: 9 Is it a sign of hardness?

Arnaud Durand enumeration and counting for acyclic conjunctive queries Can we find tractable subclasses? 12 / 20 S-components

A hypergraph = (V , E) and S V . H ⊆ Let E S = e E : e * S . * { ∈ } S-component The S-component of e E is the hypergraph [E 0] where E 0 is ∈ *S H the set of all edges e0 E such that there is a path from e S ∈ *S − to e0 S in [V S]. − H − A subhypergraph 0 of is an S-component if there is an edge H H e E such that 0 is the S-component of e. ∈ *S H

Arnaud Durand enumeration and counting for acyclic conjunctive queries Decomposition into S-components: example

S vertices in red

Arnaud Durand enumeration and counting for acyclic conjunctive queries Decomposition into S-components: example

S vertices in red

Arnaud Durand enumeration and counting for acyclic conjunctive queries S-star size

Definition (S-k-star, S-star size) Let = (V , E) be a hypergraph, S V and k N. The H ⊆ ∈ subhypergraph 0 = (V 0, E 0) of is a S-k-star if: 0 H H I is an S-component of . H 0 H I there exist y , ..., yk V S such that there is no edge e E 1 ∈ ∩ ∈ that contains more than one of the yi .

y1,..., yk are ”independant” and form the S-k-star. The S-star size of is the maximum k such that there is a H S-k-star in . H

Arnaud Durand enumeration and counting for acyclic conjunctive queries S-star size : example

S-star size is 4

Arnaud Durand enumeration and counting for acyclic conjunctive queries quantified-star size

Quantified star size The quantified star size of an acyclic conjunctive formula φ(¯x) is the S-star size of the hypergraph associated to φ(¯x), where S is H the set of free variables in φ(¯x).

Arnaud Durand enumeration and counting for acyclic conjunctive queries quantified-star size: example

Formula φ(x, y) t zR(x, y, t) S(x, z, t) ≡ ∃ ∃ ∧ Quantified star size = 1

Path formulas (of arbitrary length), e.g. φ(x, y, z) t t R(x, t ) R(t , z) R(z, t ) R(t , y) ≡ ∃ 1∃ 2 1 ∧ 1 ∧ 2 ∧ 2 Quantified star size = 2.

Star formulas, e.g. φ(x, y, z, t) uR(u, x) R(u, y) R(u, z) R(u, t) ≡ ∃ ∧ ∧ ∧ Quantified star size = degree of the center of the star (here 4).

Arnaud Durand enumeration and counting for acyclic conjunctive queries S-star size: main results I

Query evaluation is easy

Theorem There is an algorithm that given an acyclic conjunctive query Φ computes an arithmetic circuit C that computes Q(Φ). The runtime of the algorithm is Φ O(k) where k is the quantified star k k size of Φ. Corollary There is an algorithm for the problem #ACQ that runs in time Φ O(k) where k is the quantified star size of the input query Φ. k k

Arnaud Durand enumeration and counting for acyclic conjunctive queries Some remarks on the proof

Star size expresses how pieces of the result are spread

I Computation of the result is made component by component

I For each component, if quantified-star size is k and R1(¯z1), ..., Rk (¯zk ) atoms of φ containing all free variables of φ, one needs to pre-compute all k-tuples

¯a R , ..., ¯ak Rk 1 ∈ 1 ∈ and check if they lead to a solution of φ( ) (by the method S for Q(Φ) when Φ acyclic and quantified free)

Arnaud Durand enumeration and counting for acyclic conjunctive queries S-star size: main results II

Computing S-star is easy Theorem There is a polynomial time algorithm that, given a hypergraph = (V , E) and S V , computes the S-star size of . H ⊆ H Proof Equivalent to finding a maximal independant set (and a minimal edge cover) in an acyclic hypergraph. Ad hoc algorithm.

Conclusion: Classes of #ACQ-instances of bounded quantified star size are efficiently decidable.

Go to: star size needed

Arnaud Durand enumeration and counting for acyclic conjunctive queries Parametrizations of #ACQ

I p-star-#ACQ: counting parameterized by the quantified star size,

I p-var-#ACQ: counting parameterized by the number of free variables,

I p-#ACQ: counting parameterized by the size of the conjunctive formula.

Lemma p-star-#ACQ, p-var-#ACQ and p-#ACQ are all #W[1]-hard.

Arnaud Durand enumeration and counting for acyclic conjunctive queries Bounded quantified star size is necessary

S-hypergraph: pair ( , S) where = (V , E) is a hypergraph and H H S V . ⊆ Definition #ACQ is tractable for a class of S-hypergraphs if for all #ACQ G instances Φ with the associated hypergraph of Φ and the set S H of free variables of Φ with ( , S) we can solve #ACQ in H ∈ G polynomial time

Arnaud Durand enumeration and counting for acyclic conjunctive queries Bounded quantified star size is necessary

Theorem Assume FPT = #W[1], and let be a recursively enumerable 6 G class of acyclic S-hypergraphs. Then #ACQ is polynomial time solvable for if and only if is of bounded S-star size. G G

Arnaud Durand enumeration and counting for acyclic conjunctive queries Proof sketch

I First prove that #ACQ is hard on S the class of k-stars (in G the graph sense)

I Consider an instance Φ = ( , ϕ(¯x)) with Vk A ϕ(¯x) = y Ri (y, xi ) ∃ i=1 I Suppose there is a class of unbounded S-star size which is G tractable.

I Embed efficiently Φ into a suitable instance (with big enough star) Ψ whose associated hypergraph is in . G I Deduce that #ACQ is not hard on S . G

Arnaud Durand enumeration and counting for acyclic conjunctive queries Conclusion

I Complete characterization of tractability frontier for #ACQ

I Easy evaluation for counting on bounded S-star size extend to generalized hypertree width

I S-k-star size recognition seem to depend on k for some decomposition

Arnaud Durand enumeration and counting for acyclic conjunctive queries