Professional Documents
Culture Documents
(Aug-Nov 2022)
Lectures 11 & 12 (Horn-SAT, 2-SAT, DPLL)
Kumar Madhukar
madhukar@cse.iitd.ac.in
1 / 30
Horn formulas
• for a variable x, we have a positive literal (x) and a negative literal (¬x)
• a horn clause is a finite disjunction of literals with at most one positive literal
• example
(x ∨¬y ∨¬z ∨¬w )∧(¬x ∨¬y ∨¬w )∧(¬x ∨¬z ∨w )∧(¬x ∨y )∧(x)∧(¬z)∧(¬x ∨¬y ∨w )
2 / 30
Horn-SAT
• this may generate new unit clauses, which are propagated similarly
• if there are no unit clauses left, the formula can be satisfied by setting every remaining
variable to false
3 / 30
2-SAT
• example
(¬x ∨ y ) ∧ (¬y ∨ z) ∧ (x ∨ ¬z) ∧ (z ∨ y )
4 / 30
2-SAT satisfiability check
5 / 30
2-SAT satisfiability check
• claim: if the graph contains a path from α to β, then it also contains a path from ¬β to
¬α
6 / 30
2-SAT satisfiability check
• claim: if the graph contains a path from α to β, then it also contains a path from ¬β to
¬α
• claim: a 2-CNF formula is unsat iff there exists a variable x such that:
• there is a path from x to ¬x
• there is a path from ¬x to x
7 / 30
2-SAT satisfying assignment
• assign true to l and all vertices reachable from l (and assign false to their negations)
8 / 30
Example
(¬x ∨ y ) ∧ (¬y ∨ z) ∧ (x ∨ ¬z) ∧ (z ∨ y )
9 / 30
Another example
10 / 30
Tseitin transformation
• Tseitin transformation is guaranteed to only linearly increase the size of the formula
11 / 30
Tseitin transformation: Example (source: Wikipedia)
12 / 30
1-SAT to 3-SAT
c = (l )
c 0 = (l ∨ u ∨ v ) ∧ (l ∨ ¬u ∨ v ) ∧ (l ∨ u ∨ ¬v ) ∧ (l ∨ ¬u ∨ ¬v )
13 / 30
2-SAT to 3-SAT
c = (l1 ∨ l2 )
c 0 = (l1 ∨ l2 ∨ u ) ∧ (l1 ∨ l2 ∨ ¬u )
14 / 30
k(>3)-SAT to (k-1)-SAT
c = (l1 ∨ l2 ∨ . . . ∨ lk )
15 / 30
breaking 3SAT similarly to get 2SAT fails!
c = (l1 ∨ l2 ∨ l3 )
16 / 30
Davis-Putnam Algorithm
• unit-clause – if there is a unit clause l , delete all clauses containing l , and delete all
occurrences of ¬l from other clauses
• eliminate a variable by resolution – choose an atom p and perform all possible resolutions
on clauses that clash on p and ¬p. Add these resolvents to the set of clauses and then
delete all the clauses containing p or ¬p.
• use these repeatedly; but use resolution only if the the first two rules do not apply
17 / 30
Davis-Putnam Algorithm
18 / 30
DPLL Algorithm
• DPLL improves on the DP algorithm by replacing the variable elimination with a search
for a model of the formula
19 / 30
DPLL
20 / 30
DPLL Algorithm
• a conflict state is one where A sets every literal in some clause to false
• let F|A denote the formula that we get after simplifying F using A
21 / 30
DPLL Algorithm
4. if (F, A) is a conflict state then apply clause learning to get a new clause C
• if C is then stop and output unsat
• add C to F; backtrack to the highest level at which C is a unit clause; goto 2
22 / 30
Example1
C1 : {¬p1 , ¬p4 , p5 }
C2 : {¬p1 , p6 , ¬p5 }
C3 : {¬p1 , ¬p6 , p7 }
C4 : {¬p1 , ¬p7 , ¬p5 }
C5 : {p1 , p4 , p6 }
A: hp1 7→ 1, p2 7→ 0, p3 7→ 0, p4 7→ 1i
C
1 C2 C 3
unit propagation generates a sequence of implied assignments: hp5 7−→ 1, p6 7−→ 1, p7 7−→ 1i
conflict: C4 becomes false!
1
https://www.cs.ox.ac.uk/people/james.worrell/lec7-2015.pdf
23 / 30
Learned clause
• F ≡F∪C
24 / 30
Correctness
25 / 30
Clause learning
C C C
A: hp1 7→ 1, p2 7→ 0, p3 7→ 0, p4 7→ 1, p5 7−→
1 2
1, p6 7−→ 3
1, p7 7−→ 1i
26 / 30
Clause learning
C C C
A: hp1 7→ 1, p2 7→ 0, p3 7→ 0, p4 7→ 1, p5 7−→
1 2
1, p6 7−→ 3
1, p7 7−→ 1i
what about the things that were desirable from a learned clause?
27 / 30
Syllabus for Minor exam
28 / 30
Next week
29 / 30
Thank you!
30 / 30