Lecture 5
Boolean satisfiability
Johannes Korbmacher Lecture slides
Logical methods for AI
Boolean satisfiability
Lecture 5
What you’ll be able to do
Read chapter 5 first; exercise sheet 5 comes after the lecture.
Automating the hard work
In chapter 4 we did it all by hand: list the models, calculate the values, hunt for a countermodel.
- Let the machine do it.
- SAT asks one question: can one valuation make all of these true?
- Two reasoning problems reduce to it.
Reduce the problem to SAT, then run an algorithm on it.
Satisfiability
SUN ∧ ¬RAIN, with v(SUN) = 1, v(RAIN) = 0:
Satisfiable: one valuation settles it.
SUN ∧ ¬SUN:
Unsatisfiable: every valuation must fail.
The SAT problem
- SUN ∨ RAIN, ¬SUN: satisfiable, by v(SUN) = 0, v(RAIN) = 1.
- Add ¬RAIN: unsatisfiable — though each can be satisfied on its own.
Reduction 1: circuit verification
What the circuit does:
What it should do, excluding the row with output 0:
Where do they disagree? SAT? ¬(S ↔ C)
- Satisfiable: that valuation is an input where the circuit is wrong.
- Unsatisfiable: the circuit implements the specification.
Reduction 2: deductive validity
(SUN ∨ RAIN) ∧ ¬SUN ∧ ¬RAIN: no countermodel, so valid.
(SUN ∨ RAIN) ∧ SUN ∧ ¬¬RAIN: v(SUN) = v(RAIN) = 1 is a countermodel, so invalid.
Truth-tables: brute force
- n variables: 2ⁿ assignments.
- Count from 0 in binary to list them all.
- Evaluate the formula in each row.
- No preparation: the formula goes in as it stands.
Evaluating a row
|
|
Every call gets a smaller tree, so evaluation terminates.
Searching the table
Text tree
A decision procedure
- Finitely many rows, so the search finishes.
- A returned valuation makes the formula true.
- “Unsatisfiable” means every valuation was checked.
So SAT is decidable. The finished table also shows a tautology (glossary, opens in a new tab) (all 1s) or a contradiction (glossary, opens in a new tab) (all 0s).
The cost of brute force
For n variables and m operators, worst-case time complexity (glossary, opens in a new tab) :
| Variables | Rows |
|---|---|
| 3 | 8 |
| 10 | 1 024 |
| 20 | 1 048 576 |
| 40 | over a trillion |
Combinatorial explosion (glossary, opens in a new tab) : one more variable doubles the work.
Normal forms
A literal (glossary, opens in a new tab) is a propositional variable or the negation of a propositional variable.
| Formula | DNF? | CNF? |
|---|---|---|
| SUN ∨ ¬RAIN | yes | yes |
| SUN ∧ ¬RAIN | yes | yes |
| SUN ∨ (RAIN ∧ WIND) | yes | no |
| (SUN ∨ RAIN) ∧ WIND | no | yes |
| ¬(SUN ∧ RAIN) | no | no |
A DNF lists alternatives; a CNF lists requirements. Resolution needs CNF.
Rewriting into normal form
Each rule replaces a subformula by an equivalent one. First remove every ↔:
Push negations inward:
The result is in negation normal form (glossary, opens in a new tab) .
For CNF, distribute ∨ over ∧:
For DNF, distribute ∧ over ∨:
The rewriting algorithm
Remove ↔, push negations inward, then distribute — one rule at a time.
Text tree
Preprocessing is the expensive part
Distribution copies subformulas: a compact input can produce exponentially many clauses.
becomes
Each further pair doubles the clauses: n pairs give 2ⁿ.
Truth-tables pay at search time; resolution pays before the search starts.
The resolution rule
Remove only one complementary pair at a time.
The empty clause (glossary, opens in a new tab) ⊥ is false under every valuation.
Refutation search
Text tree
Tseytin: cheap preprocessing
Give each subformula a fresh name and constrain its value, instead of copying it. Name SUN ∧ RAIN by a fresh u:
One fresh variable and a few clauses per connective: the CNF grows linearly.
Worked-out example: the NAND circuit
Text tree
Use ← / →, Page Up / Page Down, or Space to navigate. While you work in an app, only Page Up / Page Down change the slide. Press F for full screen and Esc to exit. Each slide has a shareable URL.
What is on the slidesText of every slide
The text of every slide, in order. Drawings are described in words, and interactive apps are named; the textbook chapter has each of them in full.