A New Hypergraph Measure for #SAT

Florent Capelli

CRIL, Université d’Artois

Dagstuhl Seminar 24421

October 17, 2024

Loosely based on Direct Access for Conjunctive Queries with Negation with Oliver Irwin, ICDT 24

Structural Tractability of #SAT

The #SAT problem

Given CNF FF, return #F\#F, the number of satisfying assignments.

  • #P-hard to solve.
  • Even for very restricted classes: #Mon-2-SAT, #Horn-SAT etc.
  • NP-hard to (even badly) approximate (see ApproxMC for practical work in this direction).

Same story as SAT: hard problem but useful in practice.

  • Reasoning on propositionnal knowledge basis.
  • Solve other counting problems using parcimonious reductions.

When can we solve #SAT more efficiently than bruteforce?

Exploiting clauses-variables interactions

Tractability of #SAT arises from restricted clauses-variables interactions.

If XY=X \cap Y = \emptyset and F(X,z1,z2,Y)G(X,z1,z2)H(Y,z1,z2)F(X,z_1,z_2,Y) \equiv G(X,z_1,z_2) \wedge H(Y,z_1,z_2):

#F=a,b{0,1}2#G[z1=a,z2=b]·#H[z1=a,z2=b] \#F = \sum_{a,b \in \{0,1\}^2}\#G[z_1=a,z_2=b] · \#H[z_1=a,z_2=b]

If we can recursively decompose the formula this way, we can count efficiently.

Structure of CNF formulas

F=F = (x1¬x2x3)(x_1 \vee \neg x_2 \vee x_3) \wedge (x3x4x5)(x_3 \vee x_4 \vee x_5) \wedge (x1¬x5¬x6)(x_1 \vee \neg x_5 \vee \neg x_6) \wedge (x1x3x5x7)(x_1 \vee x_3 \vee x_5 \vee x_7)

Primal graph
Incidence graph
Hypergraph

Structural Tractability

If (primal / incidence) graph of FF of size nn has treewidth kk then #F\#F can be computed in time 2O(k)n2^{O(k)}n. [1]

Tree decomposition of F

Exhaustive DPLL:

#F[Xτ]=#G[Xτ]·#H[Xτ]\#F[X \gets \tau] = \#G[X \gets \tau]·\#H[X \gets \tau]

since YZXY \cap Z \subseteq X

  • Branch on 2k2^k values x1,,xkx_1,\dots,x_k
  • Recursive calls on HH and GG
  • Cache subformulas already solved

[1] Samer, Marko, and Stefan Szeider. “Algorithms for propositional model counting.” Journal of Discrete Algorithms 8.1 (2010): 50-64.

Hypergraph Acyclicities

α\alpha-acyclicity

Generalize acyclicity to hypergraphs:

  • Used in databases/CSP (tractable conjunctive queries / CSPs).
  • Usually defined in terms of tree decompositions of hypergraphs… Not today!

A hypergraph is α\alpha-acyclic if and only if we can obtained the empty graph by iteratively removing α\alpha- leaves.

We call such vertex ordering: α\alpha-elimination order.

α\alpha-leaves

  • H=(V,E)H=(V,E) a hypergraph.
  • N(v)N(v): neighborhood of vv

A vertex vv in a hypergraph is an α\alpha-leave if N(v)eN(v) \subseteq e for some edge ee of HH

  • x6,,x1x_6, \dots, x_1 is an α\alpha-elimination order.
  • Subgraphs may no be α\alpha-acyclic (look, a triangle!)

SAT is hard on α\alpha-acyclic hypergraphs

Not a good variable-clause restriction for tractability:

  • FF a CNF formula
  • F=F(x1xny)F' = F \wedge (x_1 \vee \dots \vee x_n \vee y) is α\alpha-acyclic
  • FF' SAT iff FF is SAT.

Hard subformulas make the formula hard (this does not happen with conjunctive queries).

Enters the rest of greek alphabet

A hypergraph HH is β\beta-acyclic if and only if every HHH' \subseteq H is α\alpha-acyclic.

How can we use it algorithmically?

A hypergraph HH is β\beta-acyclic if and only if there exists an order on VV that is an α\alpha-elimination order for every HHH' \subseteq H.

We call such ordering a β\beta-elimination order.

Side note: this is not how β\beta-elimination order is usually defined.

SAT and β\beta-acyclicity

SAT is easy on β\beta-acyclic instances, with a classical algorithm [2]:

Davis-Putnam resolution following a β\beta-elimination order terminates in polynomial time!

[2] Ordyniak, Sebastian, Daniël Paulusma, and Stefan Szeider. “Satisfiability of acyclic and almost acyclic CNF formulas.” Theoretical Computer Science, 2013.

#SAT and β\beta-acyclicity

#SAT is easy on β\beta-acyclic instances, with classical algorithm [3]:

Exhaustive DPLL following a reversed β\beta-elimination order terminates in polynomial time!

  • Tractable case not captured by bounded treewidth or other existing graph measures
  • Only works for a very restricted set of instances.

[3] Florent Capelli, Understanding the complexity of #SAT using knowledge compilation, LICS, 2017.

Hyperorder widths

Non acyclic hypergraphs

How do we measure how far we are from acyclicity?

  • α\alpha-acyclicity naturally generalizes to hypertree width: htw(H)htw(H) \in \mathbb{N}.
  • Usually defined via tree decomposition.
  • We give an order based definition.

Width of an elimination order

  • H=(V,E)H=(V,E), π=(v1,,vn)\pi = (v_1,\dots,v_n) order on VV.
  • Iteratively add edge N(vi)N(v_i) and remove viv_i
  • Hyperorder width how(H,π)how(H,\pi) of π=(v1,,vn)\pi = (v_1,\dots,v_n): maximum number of edges from HH to cover the neighborhood of viv_i in HiH_i.
Original hypergraph

N(x1)N(x_1) covered by 22 edges of HH

N(x2)N(x_2) covered by 33 edges of HH

N(x3)N(x_3) covered by 33 edges of HH

N(x4)N(x_4) covered by 33 edges of HH

N(x5)N(x_5) covered by 22 edges of HH

how(H,(x1,,x6))=3how(H,(x_1,\dots,x_6)) = 3

how(H,(x6,,x1))=1how(H,(x_6,\dots,x_1)) = 1

Hyperorder width and Hypertree width

Hypertree width of HH : htw(H)=minThtw(H,T)htw(H) = \min_T htw(H,T) where TT is a tree decomposition

Hyperorder width of HH : how(H)=minπhow(H,π)how(H) = \min_\pi how(H,\pi) where π\pi is an elimination order.

how(H)=htw(H).how(H) = htw(H).

  • how(H)=1how(H) = 1 iff HH is α\alpha-acyclic
  • For how(·), the order is the decomposition.

β\beta-Hypertree Width

Sometimes, there is HHH' \subseteq H st htw(H)>htw(H)htw(H')>htw(H).

Same trick as before:

βhtw(H)=maxHHhtw(H) \beta htw(H) = \max_{H' \subseteq H} htw(H')

How can we use it algorithmically?

We do not know…

Problem with β\beta-Hypertree Width

Expanding the definition:

βhtw(H)=maxHHminThtw(H,T) \beta htw(H) = \max_{H' \subseteq H} \min_T htw(H',T)

Problem: a different decomposition can be used for different subhypergraphs…

Swap quantifiers!

βhtw(H)=minTmaxHHhtw(H,T) \beta' htw(H) = \min_T \max_{H' \subseteq H} htw(H',T)

S_4

Problem: βhtw(Sn)=n\beta'htw(S_n) = n

Bringing Order

For HH β\beta-acyclic:

  • H1,H2HH_1,H_2 \subseteq H may have very different tree decompositions.
  • Tree decomposition is not the right tool here.

A hypergraph HH is β\beta-acyclic if and only if there exists an order on VV that is an α\alpha-elimination order for every HHH' \subseteq H.

βhtw(H)=maxHHminThtw(H,T)=maxHHminπhow(H,π)\begin{align} \beta htw(H) & = \max_{H' \subseteq H} \min_T htw(H',T)\\ & = \max_{H' \subseteq H} \min_\pi how(H',\pi) \end{align}

Swap quantifier in the second equality:

βhow(H)=minπmaxHHhow(H,π)\beta how(H) = \min_\pi \max_{H' \subseteq H} how(H',\pi)

#SAT and βhow(H)\beta how(H)

#SAT can be solved in time nO(k)n^{O(k)} for a formula FF of size nn and βhow(F)=k\beta how(F)=k.

  • Algorithm: exhaustive DPLL following a reversed optimal elimination order.
  • Generalizes tractability of β\beta-acyclic formulas and bounded nest set width [4]
  • Algorithm implicitly constructs decision-DNNF for FF:
    • gives tractable weighted model counting
    • tractable direct access

[4] Lanzinger, M.. Tractability beyond β-acyclicity for conjunctive queries with negation and SAT. Theoretical Computer Science, 2023.

Wrapping up

Structural complexity of #SAT:

FPT XP open #P-hard

  • Where does β\beta-how sit in this diagram?
  • Where is the frontier for SAT?

References

[1] Samer, Marko, and Stefan Szeider. “Algorithms for propositional model counting.” Journal of Discrete Algorithms 8.1 (2010): 50-64.

[2] Ordyniak, Sebastian, Daniël Paulusma, and Stefan Szeider. “Satisfiability of acyclic and almost acyclic CNF formulas.” Theoretical Computer Science, 2013.

[3] Florent Capelli, “Understanding the complexity of #SAT using knowledge compilation”, LICS, 2017.

[4] Lanzinger Matthias. “Tractability beyond β-acyclicity for conjunctive queries with negation and SAT”. Theoretical Computer Science, 2023.