#SAT

A tutorial

Florent Capelli

CRIL, Université d’Artois

JITA 2025

October 16, 2025

A primer on SAT

The puzzling SAT puzzle

+ + -
+ - - +
- + +
+ +

This problem is known as the SAT problem.

SAT as Propositional Logic

xx yy zz ww
+ + - x∨z∨¬wx \vee z \vee \neg w
+ - - + x∨¬y∨¬z∨wx \vee \neg y \vee \neg z \vee w
- + + ¬x∨y∨w\neg x \vee y \vee w
+ + x∨wx \vee w

(x∨z∨¬w)∧(x∨¬y∨¬z∨w)∧(¬x∨y∨w)∧(x∨w)(x \vee z \vee \neg w) \wedge (x \vee \neg y \vee \neg z \vee w) \wedge (\neg x \vee y \vee w) \wedge (x \vee w)

SAT is Hard

Strong Exponential Time Hypothesis: we believe SAT cannot be solved in time 2αn2^{\alpha n} for α<1\alpha < 1 in the worst case.

SAT as a “Programming Language”

A reason for the hardness of SAT: its expressivity.

We can “efficiently” encode many types of problem in a CNF formula.

Modeling reasoning

Modeling computation

We can actually encode any non-deterministic Turing machine:

0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0
↥ ↥ ↥
q′q' qq q′q'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
xq″6,t+1x_{q''}^{6,t+1} xq7,tx_{q}^{7,t} xq′8,t+1x_{q'}^{8,t+1}

NP-completeness

This shows that SAT is NP-complete! (Cook, Levin, 1973)

We need SAT solvers!

A Branching algorithm

F=(x1∨x4)∧(¬x1∨¬x2)∧(x1∨x3∨¬x4)∧(¬x1∨x2∨¬x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)F = (x_1 \vee x_4) \wedge (\neg x_1 \vee \neg x_2) \wedge (x_1 \vee x_3 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)

N x1 Nx1 x2 N--Nx1 Nnx1 x4 N--Nnx1 Nx1x2 Conflict Nx1--Nx1x2 Nx1nx2 x4 Nx1--Nx1nx2 Nx1nx2nx4 Conflict Nx1nx2--Nx1nx2nx4 Nx1nx2x4 Conflict Nx1nx2--Nx1nx2x4 Nnx1x4 x3 Nnx1--Nnx1x4 Nnx1x3x4 SAT Nnx1x4--Nnx1x3x4
(x1∨x4)∧(¬x1∨¬x2)∧(x1∨x3∨¬x4)∧(¬x1∨x2∨¬x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_4) \wedge (\neg x_1 \vee \neg x_2) \wedge (x_1 \vee x_3 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)
⟨⟩\langle \rangle
(x1∨x4)∧(¬x1∨¬x2)∧(x1∨x3∨¬x4)∧(¬x1∨x2∨¬x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_4) \wedge (\neg x_1 \vee \neg x_2) \wedge (x_1 \vee x_3 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)
⟨x1↦1⟩\langle x_1 \mapsto 1 \rangle
(x2∨x4)∧(x2∨¬x4)∧(¬x2)(x_2 \vee x_4) \wedge (x_2 \vee \neg x_4) \wedge (\neg x_2)
⟨x1↦1⟩\langle x_1 \mapsto 1 \rangle
(x2∨x4)∧(x2∨¬x4)∧(¬x2)(x_2 \vee x_4) \wedge (x_2 \vee \neg x_4) \wedge (\neg x_2)
⟨x1↦1,x2↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 1 \rangle
()()
⟨x1↦1,x2↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 1 \rangle
(x2∨x4)∧(x2∨¬x4)∧(¬x2)(x_2 \vee x_4) \wedge (x_2 \vee \neg x_4) \wedge (\neg x_2)
⟨x1↦1,x2↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0 \rangle
(¬x4)∧(x4)(\neg x_4) \wedge (x_4)
⟨x1↦1,x2↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0 \rangle
(¬x4)∧(x4)(\neg x_4) \wedge (x_4)
⟨x1↦1,x2↦0,x4↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_4 \mapsto 0 \rangle
()()
⟨x1↦1,x2↦0,x4↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_4 \mapsto 0 \rangle
(¬x4)∧(x4)(\neg x_4) \wedge (x_4)
⟨x1↦1,x2↦0,x4↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_4 \mapsto 1 \rangle
()()
⟨x1↦1,x2↦0,x4↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_4 \mapsto 1 \rangle
(x1∨x4)∧(¬x1∨¬x2)∧(x1∨x3∨¬x4)∧(¬x1∨x2∨¬x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_4) \wedge (\neg x_1 \vee \neg x_2) \wedge (x_1 \vee x_3 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(¬x2∨¬x3∨x4)∧(x3∨¬x4)∧(x4)(\neg x_2 \vee \neg x_3 \vee x_4) \wedge (x_3 \vee \neg x_4) \wedge (x_4)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(¬x2∨¬x3∨x4)∧(x3∨¬x4)∧(x4)(\neg x_2 \vee \neg x_3 \vee x_4) \wedge (x_3 \vee \neg x_4) \wedge (x_4)
⟨x1↦0,x4↦1⟩\langle x_1 \mapsto 0,x_4 \mapsto 1 \rangle
(x3)(x_3)
⟨x1↦0,x4↦1⟩\langle x_1 \mapsto 0,x_4 \mapsto 1 \rangle
(x3)(x_3)
⟨x1↦0,x3↦1,x4↦1⟩\langle x_1 \mapsto 0,x_3 \mapsto 1,x_4 \mapsto 1 \rangle
()()
⟨x1↦0,x3↦1,x4↦1⟩\langle x_1 \mapsto 0,x_3 \mapsto 1,x_4 \mapsto 1 \rangle

Adding Unit Propagation

F=(x1∨x4)∧(¬x1∨¬x2)∧(x1∨x3∨¬x4)∧(¬x1∨x2∨¬x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)F = (x_1 \vee x_4) \wedge (\neg x_1 \vee \neg x_2) \wedge (x_1 \vee x_3 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)

N x1 Nx1 x2 N--Nx1 Nnx1 x4 N--Nnx1 Nx1nx2 x4 Nx1--Nx1nx2 UP Nx1nx2nx4 Conflict Nx1nx2--Nx1nx2nx4 UP Nnx1x4 x3 Nnx1--Nnx1x4 UP Nnx1x3x4 SAT Nnx1x4--Nnx1x3x4 UP
(x1∨x4)∧(¬x1∨¬x2)∧(x1∨x3∨¬x4)∧(¬x1∨x2∨¬x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_4) \wedge (\neg x_1 \vee \neg x_2) \wedge (x_1 \vee x_3 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)
⟨⟩\langle \rangle
(x1∨x4)∧(¬x1∨¬x2)∧(x1∨x3∨¬x4)∧(¬x1∨x2∨¬x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_4) \wedge (\neg x_1 \vee \neg x_2) \wedge (x_1 \vee x_3 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)
⟨x1↦1⟩\langle x_1 \mapsto 1 \rangle
(x2∨x4)∧(x2∨¬x4)∧(x_2 \vee x_4) \wedge (x_2 \vee \neg x_4) \wedge (¬x2)(\neg x_2)
⟨x1↦1⟩\langle x_1 \mapsto 1 \rangle
(x2∨x4)∧(x2∨¬x4)∧(x_2 \vee x_4) \wedge (x_2 \vee \neg x_4) \wedge (¬x2)(\neg x_2)
⟨x1↦1,\langle x_1 \mapsto 1, x2↦0x_2 \mapsto 0 ⟩\rangle
(¬x4)∧(x4)(\neg x_4) \wedge (x_4)
⟨x1↦1,x2↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0 \rangle
(¬x4)∧(x4)(\neg x_4) \wedge (x_4)
⟨x1↦1,x2↦0,x4↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_4 \mapsto 0 \rangle
()()
⟨x1↦1,x2↦0,x4↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_4 \mapsto 0 \rangle
(x1∨x4)∧(¬x1∨¬x2)∧(x1∨x3∨¬x4)∧(¬x1∨x2∨¬x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_4) \wedge (\neg x_1 \vee \neg x_2) \wedge (x_1 \vee x_3 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee \neg x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(¬x2∨¬x3∨x4)∧(x3∨¬x4)∧(x4)(\neg x_2 \vee \neg x_3 \vee x_4) \wedge (x_3 \vee \neg x_4) \wedge (x_4)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(¬x2∨¬x3∨x4)∧(x3∨¬x4)∧(x4)(\neg x_2 \vee \neg x_3 \vee x_4) \wedge (x_3 \vee \neg x_4) \wedge (x_4)
⟨x1↦0,x4↦1⟩\langle x_1 \mapsto 0,x_4 \mapsto 1 \rangle
(x3)(x_3)
⟨x1↦0,x4↦1⟩\langle x_1 \mapsto 0,x_4 \mapsto 1 \rangle
(x3)(x_3)
⟨x1↦0,x3↦1,x4↦1⟩\langle x_1 \mapsto 0,x_3 \mapsto 1,x_4 \mapsto 1 \rangle
()()
⟨x1↦0,x3↦1,x4↦1⟩\langle x_1 \mapsto 0,x_3 \mapsto 1,x_4 \mapsto 1 \rangle

DPLL

  • UNIT PROPAGATION: If there is a clause with one variable not set, pick it and satisfy it, e.g C=¬xC = \neg x, pick x=0,b=0x=0,b=0
  • PURE LITERAL ELIMINATION: If there is a variable xx appearing only positively (resp negatively), pick xx and b=1b=1 (resp. b=0b=0).

Problem: Backtracks are dealt with independently, some insights are lost.

CDCL Solvers

Conflict Driven Clause Learning: try to learn why.

CDCL-solvers (+good heuristics, +good data structures, +“agressive restarts”):

  • really efficient on many instances
  • bruteforce at its finest
  • naturally unravel hidden structures in the encoding

#SAT

Counting the number of solutions

+ + -
+ - - +
- + +
+ +

This problem is known as #SAT: given a CNF FF, return #F\#F, its number of solutions.

Why counting?

Modeling constraints: counting enables better “reasoning”.

How hard is it?

Counting by enumeration

(x1∨x3∨¬x4)∧(x1∨x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_3 \vee \neg x_4) \wedge (x_1 \vee x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)

N x1 Nx1 x2 N--Nx1 Nnx1 x4 N--Nnx1 Nx1x2 SAT (4 sol) Nx1--Nx1x2 Nx1nx2 x4 Nx1--Nx1nx2 Nx1nx2x4 SAT (2 sol) Nx1nx2--Nx1nx2x4 UP Nnx1x4 x3 Nnx1--Nnx1x4 UP Nnx1x3x4 SAT (2 sol) Nnx1x4--Nnx1x3x4 UP
(x1∨x3∨¬x4)∧(x1∨x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_3 \vee \neg x_4) \wedge (x_1 \vee x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)
⟨⟩\langle \rangle
(x1∨x3∨¬x4)∧(x1∨x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_3 \vee \neg x_4) \wedge (x_1 \vee x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)
⟨x1↦1⟩\langle x_1 \mapsto 1 \rangle
(x2∨x4)(x_2 \vee x_4)
⟨x1↦1⟩\langle x_1 \mapsto 1 \rangle
(x2∨x4)(x_2 \vee x_4)
⟨x1↦1,x2↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 1 \rangle
()()
⟨x1↦1,x2↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 1 \rangle
(x2∨x4)(x_2 \vee x_4)
⟨x1↦1,x2↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0 \rangle
(x4)(x_4)
⟨x1↦1,x2↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0 \rangle
(x4)(x_4)
⟨x1↦1,x2↦0,x4↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_4 \mapsto 1 \rangle
()()
⟨x1↦1,x2↦0,x4↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_4 \mapsto 1 \rangle
(x1∨x3∨¬x4)∧(x1∨x4)∧(¬x1∨x2∨x4)∧(x1∨¬x2∨¬x3∨x4)(x_1 \vee x_3 \vee \neg x_4) \wedge (x_1 \vee x_4) \wedge (\neg x_1 \vee x_2 \vee x_4) \wedge (x_1 \vee \neg x_2 \vee \neg x_3 \vee x_4)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(¬x2∨¬x3∨x4)∧(x3∨¬x4)∧(x4)(\neg x_2 \vee \neg x_3 \vee x_4) \wedge (x_3 \vee \neg x_4) \wedge (x_4)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(¬x2∨¬x3∨x4)∧(x3∨¬x4)∧(x4)(\neg x_2 \vee \neg x_3 \vee x_4) \wedge (x_3 \vee \neg x_4) \wedge (x_4)
⟨x1↦0,x4↦1⟩\langle x_1 \mapsto 0,x_4 \mapsto 1 \rangle
(x3)(x_3)
⟨x1↦0,x4↦1⟩\langle x_1 \mapsto 0,x_4 \mapsto 1 \rangle
(x3)(x_3)
⟨x1↦0,x3↦1,x4↦1⟩\langle x_1 \mapsto 0,x_3 \mapsto 1,x_4 \mapsto 1 \rangle
()()
⟨x1↦0,x3↦1,x4↦1⟩\langle x_1 \mapsto 0,x_3 \mapsto 1,x_4 \mapsto 1 \rangle

Counting by enumeration

#F=#F[x=0]+#F[x=1]\#F = \#F[x=0]+\#F[x=1]

g N x1 Nx1 x2 N--Nx1 Nnx1 x4 N--Nnx1 Nx1x2 SAT (4 solutions) Nx1--Nx1x2 Nnx2x1 x4 Nx1--Nnx2x1 Nnx2x1x4 SAT (2 solutions) Nnx2x1--Nnx2x1x4 UP Nnx1x4 x3 Nnx1--Nnx1x4 UP Nnx1x3x4 SAT (2 solutions) Nnx1x4--Nnx1x3x4 UP
  • Run DPLL with a counter.
  • When a model is found: add 2Y2^Y to the counter where YY are unassigned variables.
  • Keep backtracking until every branch are explored.
  • Use unit propagation: #F=#F[x=1]\#F = \#F[x=1] if there is a clause (x)(x).
  • Pure literal cannot be eliminated: (x∨y)∧(x∨¬z)(x \vee y) \wedge (x \vee \neg z) has solutions with x=0x=0!

Improvements possible: sometimes, we are redoing expensive computation.

Caching in Exhaustive DPLL

g N x1 Nx1 x4 N--Nx1 Nnx1 x4 N--Nnx1 Nnx4x1 x2 Nx1--Nnx4x1 UP Nnx4x1x2 SAT (2 sol) Nnx4x1--Nnx4x1x2 Nnx4nx2x1 x3 Nnx4x1--Nnx4nx2x1 Nnx4nx2x1x3 SAT (1 sol) Nnx4nx2x1--Nnx4nx2x1x3 UP Nnx4nx1 x2 Nnx1--Nnx4nx1 UP Nnx4nx1x2 SAT (2 sol) Nnx4nx1--Nnx4nx1x2 Nnx4nx2nx1 x3 Nnx4nx1--Nnx4nx2nx1 Nnx4nx2nx1x3 SAT (1 sol) Nnx4nx2nx1--Nnx4nx2nx1x3 UP
g N x1 Nx1 x4 N--Nx1 N--Nx1 Nnx4x1 x2 Nx1--Nnx4x1 UP Nnx4x1x2 SAT (2 sol) Nnx4x1--Nnx4x1x2 Nnx4nx2x1 x3 Nnx4x1--Nnx4nx2x1 Nnx4nx2x1x3 SAT (1 sol) Nnx4nx2x1--Nnx4nx2x1x3 UP
  • Cache precomputed values
  • Example: F=(x1∨x2∨x3)∧(¬x1∨x2∨x3)∧(x1∨¬x4)∧(¬x1∨¬x4)F = (x_1 \vee x_2 \vee x_3) \wedge (\neg x_1 \vee x_2 \vee x_3) \wedge (x_1 \vee \neg x_4) \wedge (\neg x_1 \vee \neg x_4)
    • F[x1=1]=(x2∨x3)∧¬x4F[x_1=1] = (x_2 \vee x_3) \wedge \neg x_4 has 3 solutions
    • F[x1=0]=F[x_1=0]= (x2∨x3)∧¬x4=F[x1=1](x_2 \vee x_3) \wedge \neg x_4 = F[x_1=1], also has 33 solutions!
  • 6 solutions in total.

Exploiting SAT solver efficiency

Exhaustive DPLL for F=(¬x1∨x2∨x3)∧(¬x2∨¬x5)∧(x2∨x4∨x5)∧(¬x3∨¬x5)∧(x1)∧(¬x2∨¬x4)∧(¬x3∨¬x4)F = (\neg x_1 \vee x_2 \vee x_3) \wedge (\neg x_2 \vee \neg x_5) \wedge (x_2 \vee x_4 \vee x_5) \wedge (\neg x_3 \vee \neg x_5) \wedge (x_1) \wedge (\neg x_2 \vee \neg x_4) \wedge (\neg x_3 \vee \neg x_4)

N x1 Nx1 x5 N--Nx1 UP Nx1nx5 x2 Nx1--Nx1nx5 Nx1x5 x3 Nx1--Nx1x5 Nx1x2nx5 x4 Nx1nx5--Nx1x2nx5 Nx1nx2nx5 x3 Nx1nx5--Nx1nx2nx5 Nx1x2nx4nx5 SAT Nx1x2nx5--Nx1x2nx4nx5 UP Nx1nx2x3nx5 x4 Nx1nx2nx5--Nx1nx2x3nx5 UP Nx1nx2x3nx4nx5 Conflict Nx1nx2x3nx5--Nx1nx2x3nx4nx5 UP Nx1nx3x5 x2 Nx1x5--Nx1nx3x5 UP Nx1x2nx3x5 Conflict Nx1nx3x5--Nx1x2nx3x5 UP
(¬x1∨x2∨x3)∧(¬x2∨¬x5)∧(x2∨x4∨x5)∧(¬x3∨¬x5)∧(x1)∧(¬x2∨¬x4)∧(¬x3∨¬x4)(\neg x_1 \vee x_2 \vee x_3) \wedge (\neg x_2 \vee \neg x_5) \wedge (x_2 \vee x_4 \vee x_5) \wedge (\neg x_3 \vee \neg x_5) \wedge (x_1) \wedge (\neg x_2 \vee \neg x_4) \wedge (\neg x_3 \vee \neg x_4)
⟨⟩\langle \rangle
(¬x1∨x2∨x3)∧(¬x2∨¬x5)∧(x2∨x4∨x5)∧(¬x3∨¬x5)∧(x1)∧(¬x2∨¬x4)∧(¬x3∨¬x4)(\neg x_1 \vee x_2 \vee x_3) \wedge (\neg x_2 \vee \neg x_5) \wedge (x_2 \vee x_4 \vee x_5) \wedge (\neg x_3 \vee \neg x_5) \wedge (x_1) \wedge (\neg x_2 \vee \neg x_4) \wedge (\neg x_3 \vee \neg x_4)
⟨x1↦1⟩\langle x_1 \mapsto 1 \rangle
(¬x3∨¬x5)∧(¬x2∨¬x4)∧(x2∨x3)∧(¬x3∨¬x4)∧(¬x2∨¬x5)∧(x2∨x4∨x5)(\neg x_3 \vee \neg x_5) \wedge (\neg x_2 \vee \neg x_4) \wedge (x_2 \vee x_3) \wedge (\neg x_3 \vee \neg x_4) \wedge (\neg x_2 \vee \neg x_5) \wedge (x_2 \vee x_4 \vee x_5)
⟨x1↦1⟩\langle x_1 \mapsto 1 \rangle
(¬x3∨¬x5)∧(¬x2∨¬x4)∧(x2∨x3)∧(¬x3∨¬x4)∧(¬x2∨¬x5)∧(x2∨x4∨x5)(\neg x_3 \vee \neg x_5) \wedge (\neg x_2 \vee \neg x_4) \wedge (x_2 \vee x_3) \wedge (\neg x_3 \vee \neg x_4) \wedge (\neg x_2 \vee \neg x_5) \wedge (x_2 \vee x_4 \vee x_5)
⟨x1↦1,x5↦0⟩\langle x_1 \mapsto 1,x_5 \mapsto 0 \rangle
(x2∨x4)∧(¬x2∨¬x4)∧(x2∨x3)∧(¬x3∨¬x4)(x_2 \vee x_4) \wedge (\neg x_2 \vee \neg x_4) \wedge (x_2 \vee x_3) \wedge (\neg x_3 \vee \neg x_4)
⟨x1↦1,x5↦0⟩\langle x_1 \mapsto 1,x_5 \mapsto 0 \rangle
(x2∨x4)∧(¬x2∨¬x4)∧(x2∨x3)∧(¬x3∨¬x4)(x_2 \vee x_4) \wedge (\neg x_2 \vee \neg x_4) \wedge (x_2 \vee x_3) \wedge (\neg x_3 \vee \neg x_4)
⟨x1↦1,x2↦1,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 1,x_5 \mapsto 0 \rangle
(¬x4)∧(¬x3∨¬x4)(\neg x_4) \wedge (\neg x_3 \vee \neg x_4)
⟨x1↦1,x2↦1,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 1,x_5 \mapsto 0 \rangle
(¬x4)∧(¬x3∨¬x4)(\neg x_4) \wedge (\neg x_3 \vee \neg x_4)
⟨x1↦1,x2↦1,x4↦0,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 1,x_4 \mapsto 0,x_5 \mapsto 0 \rangle
()()
⟨x1↦1,x2↦1,x4↦0,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 1,x_4 \mapsto 0,x_5 \mapsto 0 \rangle
(x2∨x4)∧(¬x2∨¬x4)∧(x2∨x3)∧(¬x3∨¬x4)(x_2 \vee x_4) \wedge (\neg x_2 \vee \neg x_4) \wedge (x_2 \vee x_3) \wedge (\neg x_3 \vee \neg x_4)
⟨x1↦1,x2↦0,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_5 \mapsto 0 \rangle
(x3)∧(¬x3∨¬x4)∧(x4)(x_3) \wedge (\neg x_3 \vee \neg x_4) \wedge (x_4)
⟨x1↦1,x2↦0,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_5 \mapsto 0 \rangle
(x3)∧(¬x3∨¬x4)∧(x4)(x_3) \wedge (\neg x_3 \vee \neg x_4) \wedge (x_4)
⟨x1↦1,x2↦0,x3↦1,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_3 \mapsto 1,x_5 \mapsto 0 \rangle
(¬x4)∧(x4)(\neg x_4) \wedge (x_4)
⟨x1↦1,x2↦0,x3↦1,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_3 \mapsto 1,x_5 \mapsto 0 \rangle
(¬x4)∧(x4)(\neg x_4) \wedge (x_4)
⟨x1↦1,x2↦0,x3↦1,x4↦0,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_3 \mapsto 1,x_4 \mapsto 0,x_5 \mapsto 0 \rangle
()()
⟨x1↦1,x2↦0,x3↦1,x4↦0,x5↦0⟩\langle x_1 \mapsto 1,x_2 \mapsto 0,x_3 \mapsto 1,x_4 \mapsto 0,x_5 \mapsto 0 \rangle
(¬x3∨¬x5)∧(¬x2∨¬x4)∧(x2∨x3)∧(¬x3∨¬x4)∧(¬x2∨¬x5)∧(x2∨x4∨x5)(\neg x_3 \vee \neg x_5) \wedge (\neg x_2 \vee \neg x_4) \wedge (x_2 \vee x_3) \wedge (\neg x_3 \vee \neg x_4) \wedge (\neg x_2 \vee \neg x_5) \wedge (x_2 \vee x_4 \vee x_5)
⟨x1↦1,x5↦1⟩\langle x_1 \mapsto 1,x_5 \mapsto 1 \rangle
(¬x2∨¬x4)∧(x2∨x3)∧(¬x3∨¬x4)∧(¬x3)∧(¬x2)(\neg x_2 \vee \neg x_4) \wedge (x_2 \vee x_3) \wedge (\neg x_3 \vee \neg x_4) \wedge (\neg x_3) \wedge (\neg x_2)
⟨x1↦1,x5↦1⟩\langle x_1 \mapsto 1,x_5 \mapsto 1 \rangle
(¬x2∨¬x4)∧(x2∨x3)∧(¬x3∨¬x4)∧(¬x3)∧(¬x2)(\neg x_2 \vee \neg x_4) \wedge (x_2 \vee x_3) \wedge (\neg x_3 \vee \neg x_4) \wedge (\neg x_3) \wedge (\neg x_2)
⟨x1↦1,x3↦0,x5↦1⟩\langle x_1 \mapsto 1,x_3 \mapsto 0,x_5 \mapsto 1 \rangle
(x2)∧(¬x2∨¬x4)∧(¬x2)(x_2) \wedge (\neg x_2 \vee \neg x_4) \wedge (\neg x_2)
⟨x1↦1,x3↦0,x5↦1⟩\langle x_1 \mapsto 1,x_3 \mapsto 0,x_5 \mapsto 1 \rangle
(x2)∧(¬x2∨¬x4)∧(¬x2)(x_2) \wedge (\neg x_2 \vee \neg x_4) \wedge (\neg x_2)
⟨x1↦1,x2↦1,x3↦0,x5↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 1,x_3 \mapsto 0,x_5 \mapsto 1 \rangle
()∧(¬x4)() \wedge (\neg x_4)
⟨x1↦1,x2↦1,x3↦0,x5↦1⟩\langle x_1 \mapsto 1,x_2 \mapsto 1,x_3 \mapsto 0,x_5 \mapsto 1 \rangle
  • Spend time maintaining caching in dead branches
  • Call to SAT solver at each level:
    • cut conflict branches
    • CDCL : learn some conflict that can be used
    • E.g., SAT call learns ¬x5\neg x_5 in the first call.
N x1 Nx1 x5 N--Nx1 UP Nx1nx5 x2 Nx1--Nx1nx5 UP (¬x5 learnt) Nx1x2nx5 x4 Nx1nx5--Nx1x2nx5 C Conflict (call) Nx1nx5--C Nx1x2nx4nx5 SAT Nx1x2nx5--Nx1x2nx4nx5 UP

Connected components

Observation: F=F1∧F2F = F_1 \wedge F_2 with var(F1)∩var(F2)=∅var(F_1) \cap var(F_2) = \emptyset then

#F=#F1×#F2 \#F = \#F_1 \times \#F_2

because solutions of F1F_1 and F2F_2 can be recombined independently to form a solution of FF.

Example with connected components

(x1∨x2)∧(x1∨x3)(x_1 \vee x_2) \wedge (x_1 \vee x_3) ∧\wedge (x4∨x5)∧(x4∨x6)(x_4 \vee x_5) \wedge (x_4 \vee x_6) ∧\wedge (x7∨x9)∧(¬x7∨x8)(x_7 \vee x_9) \wedge (\neg x_7 \vee x_8)
5 solutions ×\times 5 solution ×\times 4 solutions

5×5×4=1005 \times 5 \times 4 = 100

N1 × N2 x4 N1--N2 N7 x1 N1--N7 N11 x8 N1--N11 N3 SAT N2--N3 N4 × N2--N4 N5 x5 N4--N5 N6 x6 N4--N6 N5--N3 UP N6--N3 UP N7--N3 N8 × N7--N8 N9 x3 N8--N9 N10 x2 N8--N10 N9--N3 UP N10--N3 UP N12 x9 N11--N12 N14 x7 N11--N14 N12--N3 N13 x7 N12--N13 N13--N3 UP N15 x9 N14--N15 UP N15--N3 UP
(x1∨x2)∧(x1∨x3)∧(x4∨x5)∧(x4∨x6)∧(x7∨x9)∧(¬x7∨x8)(x_1 \vee x_2) \wedge (x_1 \vee x_3) \wedge (x_4 \vee x_5) \wedge (x_4 \vee x_6) \wedge (x_7 \vee x_9) \wedge (\neg x_7 \vee x_8)
⟨⟩\langle \rangle
(x4∨x6)∧(x1∨x2)∧(x4∨x5)∧(x7∨x9)∧(¬x7∨x8)∧(x1∨x3)(x_4 \vee x_6) \wedge (x_1 \vee x_2) \wedge (x_4 \vee x_5) \wedge (x_7 \vee x_9) \wedge (\neg x_7 \vee x_8) \wedge (x_1 \vee x_3)
⟨⟩\langle \rangle
(x4∨x5)∧(x4∨x6)(x_4 \vee x_5) \wedge (x_4 \vee x_6)
⟨⟩\langle \rangle
(x4∨x5)∧(x4∨x6)(x_4 \vee x_5) \wedge (x_4 \vee x_6)
⟨x4↦1⟩\langle x_4 \mapsto 1 \rangle
()()
⟨x4↦1⟩\langle x_4 \mapsto 1 \rangle
(x4∨x5)∧(x4∨x6)(x_4 \vee x_5) \wedge (x_4 \vee x_6)
⟨x4↦0⟩\langle x_4 \mapsto 0 \rangle
(x5)∧(x6)(x_5) \wedge (x_6)
⟨x4↦0⟩\langle x_4 \mapsto 0 \rangle
(x5)∧(x6)(x_5) \wedge (x_6)
⟨x4↦0⟩\langle x_4 \mapsto 0 \rangle
(x5)(x_5)
⟨x4↦0⟩\langle x_4 \mapsto 0 \rangle
(x5)(x_5)
⟨x4↦0,x5↦1⟩\langle x_4 \mapsto 0,x_5 \mapsto 1 \rangle
(x5)∧(x6)(x_5) \wedge (x_6)
⟨x4↦0⟩\langle x_4 \mapsto 0 \rangle
(x6)(x_6)
⟨x4↦0⟩\langle x_4 \mapsto 0 \rangle
(x6)(x_6)
⟨x4↦0,x6↦1⟩\langle x_4 \mapsto 0,x_6 \mapsto 1 \rangle
(x4∨x6)∧(x1∨x2)∧(x4∨x5)∧(x7∨x9)∧(¬x7∨x8)∧(x1∨x3)(x_4 \vee x_6) \wedge (x_1 \vee x_2) \wedge (x_4 \vee x_5) \wedge (x_7 \vee x_9) \wedge (\neg x_7 \vee x_8) \wedge (x_1 \vee x_3)
⟨⟩\langle \rangle
(x1∨x3)∧(x1∨x2)(x_1 \vee x_3) \wedge (x_1 \vee x_2)
⟨⟩\langle \rangle
(x1∨x3)∧(x1∨x2)(x_1 \vee x_3) \wedge (x_1 \vee x_2)
⟨x1↦1⟩\langle x_1 \mapsto 1 \rangle
(x1∨x3)∧(x1∨x2)(x_1 \vee x_3) \wedge (x_1 \vee x_2)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(x3)∧(x2)(x_3) \wedge (x_2)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(x3)∧(x2)(x_3) \wedge (x_2)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(x3)(x_3)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(x3)(x_3)
⟨x1↦0,x3↦1⟩\langle x_1 \mapsto 0,x_3 \mapsto 1 \rangle
(x3)∧(x2)(x_3) \wedge (x_2)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(x2)(x_2)
⟨x1↦0⟩\langle x_1 \mapsto 0 \rangle
(x2)(x_2)
⟨x1↦0,x2↦1⟩\langle x_1 \mapsto 0,x_2 \mapsto 1 \rangle
(x4∨x6)∧(x1∨x2)∧(x4∨x5)∧(x7∨x9)∧(¬x7∨x8)∧(x1∨x3)(x_4 \vee x_6) \wedge (x_1 \vee x_2) \wedge (x_4 \vee x_5) \wedge (x_7 \vee x_9) \wedge (\neg x_7 \vee x_8) \wedge (x_1 \vee x_3)
⟨⟩\langle \rangle
(¬x7∨x8)∧(x7∨x9)(\neg x_7 \vee x_8) \wedge (x_7 \vee x_9)
⟨⟩\langle \rangle
(¬x7∨x8)∧(x7∨x9)(\neg x_7 \vee x_8) \wedge (x_7 \vee x_9)
⟨x8↦1⟩\langle x_8 \mapsto 1 \rangle
(x7∨x9)(x_7 \vee x_9)
⟨x8↦1⟩\langle x_8 \mapsto 1 \rangle
(x7∨x9)(x_7 \vee x_9)
⟨x8↦1,x9↦1⟩\langle x_8 \mapsto 1,x_9 \mapsto 1 \rangle
(x7∨x9)(x_7 \vee x_9)
⟨x8↦1,x9↦0⟩\langle x_8 \mapsto 1,x_9 \mapsto 0 \rangle
(x7)(x_7)
⟨x8↦1,x9↦0⟩\langle x_8 \mapsto 1,x_9 \mapsto 0 \rangle
(x7)(x_7)
⟨x7↦1,x8↦1,x9↦0⟩\langle x_7 \mapsto 1,x_8 \mapsto 1,x_9 \mapsto 0 \rangle
(¬x7∨x8)∧(x7∨x9)(\neg x_7 \vee x_8) \wedge (x_7 \vee x_9)
⟨x8↦0⟩\langle x_8 \mapsto 0 \rangle
(x7∨x9)∧(¬x7)(x_7 \vee x_9) \wedge (\neg x_7)
⟨x8↦0⟩\langle x_8 \mapsto 0 \rangle
(x7∨x9)∧(¬x7)(x_7 \vee x_9) \wedge (\neg x_7)
⟨x7↦0,x8↦0⟩\langle x_7 \mapsto 0,x_8 \mapsto 0 \rangle
(x9)(x_9)
⟨x7↦0,x8↦0⟩\langle x_7 \mapsto 0,x_8 \mapsto 0 \rangle
(x9)(x_9)
⟨x7↦0,x8↦0,x9↦1⟩\langle x_7 \mapsto 0,x_8 \mapsto 0,x_9 \mapsto 1 \rangle

Exhaustive DPLL: summary

Choosing variables

Compile !

Trace of counting algorithm

N1 × N2 x4 N1--N2 N7 x1 N1--N7 N11 x8 N1--N11 N3 SAT N2--N3 N4 × N2--N4 N5 x5 N4--N5 N6 x6 N4--N6 N5--N3 UP N6--N3 UP N7--N3 N8 × N7--N8 N9 x3 N8--N9 N10 x2 N8--N10 N9--N3 UP N10--N3 UP N12 x9 N11--N12 N14 x7 N11--N14 N12--N3 N13 x7 N12--N13 N13--N3 UP N15 x9 N14--N15 UP N15--N3 UP
  • Exhaustive DPLL construct a factorized representation of the set of solutions.
  • This “data structured” can be used to:
    • count,
    • count with weights (compute probabilities),
    • count how many solutions have x9=0x9=0
    • enumerate,
    • optimize (find the “best” model) etc.

Knowledge compilation is the field studying how to construct tractable data structures representing Boolean function.

Syntactic restriction of Boolean circuits

g N 0 M 1
Constants
g N y A A N--A B B N--B
Decision gate
g N ∧ A A N--A B B N--B
Decomposable ∧\wedge-gate: var(A)∩var(B)=∅var(A) \cap var(B) = \emptyset

Limits of DPLL

Bottom up compilation

Build a tractable circuit by assembling base tractable circuits:

OBDD example

(x1⊕x2=0)(x_1 \oplus x_2 = 0) ∧\wedge (x3⊕x4=0)(x_3 \oplus x_4 = 0) ∧\wedge (x1∨x4)(x_1 \vee x_4)
c1 x30 x2 1 1 x30--1 0 0 x30--0 x31 x2 x31--1 x31--0 x1 x1 x1--x30 x1--x31 ∧\wedge c1 x30 x4 1 1 x30--1 0 0 x30--0 x31 x4 x31--1 x31--0 x3 x3 x3--x30 x3--x31 ∧\wedge x1∨x4x_1 \vee x_4
c1 x20 x2 x3 x3 x20--x3 0 0 x20--0 x21 x2 x21--x3 x21--0 x1 x1 x1--x20 x1--x21 x30 x4 x3--x30 x31 x4 x3--x31 x30--0 1 1 x30--1 x31--0 x31--1 ∧\wedge c1 x1 x1 1 1 x1--1 x4 x4 x1--x4 x4--1 0 0 x4--0
c1 x20 x2 x3 x3 x20--x3 0 0 x20--0 x21 x2 x21--x3 x21--0 x1 x1 x1--x20 x1--x21 x3--0 x41 x4 x3--x41 x41--0 1 1 x41--1

Conclusion

Slides you could have seen today

More general Circuits

d-DNNF, SDD, DNNF, ADD and other mouthful.

Complexity of DPLL

  • Leverage structure of CNF formulas
  • Eg, bounded treewidth, see sharpSAT-TD.

Approximating #SAT

  • Approximating #F is NP-hard
  • Some tools: see approxmc, based on SAT solvers.
  • Not always better than exact model counting

Lower bounds

  • can we always find small circuits? No.
  • We can prove unconditional lower bounds.

Implementation

  • What heuristics for picking variables?
  • What kind of data structure?

More queries

  • Ranked enumeration
  • Direct access etc.

Applications

  • Database theory (factorised databases)
  • Optimization
  • etc.