2024 CS1200 Lec15 Notes
2024 CS1200 Lec15 Notes
1 Announcements
• SRE next class (10/29). Remember to prepare and come on time!
• Salil’s OH after class today (no OH next week due to conference travel), Anurag Zoom OH
tomorrow 1:30-2:30.
• Remember to acknowledge all sources on your problem sets, including students not currently
in the class and ChatGPT/AI.
• Reflection summaries
2 Propositional Logic
Motivation: Logic is a fundamental building block for computation (e.g. digital circuits) and a
very expressive language for encoding computational problems we want to solve.
Definition 2.1 (boolean formulas, informal). A boolean formula ϕ is a formula built up from a
finite set of variables, say x0 , . . . , xn−1 , using the logical operators ∧ (AND), ∨ (OR), and ¬ (NOT),
and parentheses.
1
Every boolean formula ϕ on n variables defines a boolean function, which we’ll abuse notation
and also denote by ϕ : {0, 1}n → {0, 1}, where we interpret 0 as false and 1 as true, and give ∧, ∨, ¬
their usual semantics (meaning).
The Lewis–Zax text contains a formal, inductive definitions of boolean formulas and the corre-
sponding boolean functions.
Examples:
ϕmaj (x0 , x1 , x2 ) = (x0 ∧ x1 ) ∨ (x1 ∧ x2 ) ∨ (x2 ∧ x0 )
is a boolean formula. It evaluates to 1 if
Definition 2.2 (DNF and CNF formulas). • A literal is a variable (e.g. xi ) or its negation
(¬xi ).
A:
Simplifying clauses. Note terms and clauses may contain duplicate literals, but if a term or
clause contains multiple copies of a variable x, it’s equivalent to a term or clause with just one copy
(since x ∨ x = x and x ∧ x = x). We can also remove any clause or term with both a variable x
and its negation ¬x, as that clause or term will be always true (in the case of a clause) or always
false (in the case of a term). We define a function Simplify which takes a clause and performs those
simplifications: that is, given a clause B, Simplify(B) removes duplicates of literals from clause B,
and returns 1 if B contains both a literal and its negation. Also, if we have an order on variables
(e.g. x0 , x1 , . . . ), Simplify(B) also sorts the literals in order of their variables.
One reason that DNF and CNF are used so commonly is that they can express all boolean
functions:
2
Lemma 2.3. For every boolean function f : {0, 1}n → {0, 1}, there are boolean formulas ϕ and ψ
in DNF and CNF, respectively, such that f ≡ ϕ and f ≡ ψ, where we use ≡ to indicate equivalence
as functions, i.e. f ≡ g iff ∀x : f (x) = g(x).
Proof.
ψ(x0 , x1 , x2 ) =
with the clauses corresponding to the 4 non-satisfying assignments (0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1).
This example shows that the DNF and CNF given by the general construction are not necessarily
the smallest ones possible for a given function, as the majority function can also be expressed by
the following simpler CNF formula:
3
Q: One of these problems is algorithmically very easy. Which one?
2.
3.
For instance, if G is the graph below,
We then call the SAT oracle on φG and get an assignment α. If α =⊥, we say G is not
k-colorable. Otherwise, we construct and output the coloring fα given by:
fα (v) =
4
The runtime essentially follows from our description.
For correctness, we make two claims:
Claim 4.2. If G has a valid k coloring, φG is satisfiable.
=⇒ don’t incorrectly output ⊥.
Claim 4.3. If α satisfies φG , then fα is a proper k-coloring of G.
=⇒ if we output a coloring, it will be proper.
Both of these claims are worth checking. Note that fα is well-defined because α satisfies clauses
of type 1 and is proper due to clauses of type 2.
Unfortunately, the fastest known algorithms for Satisfiability have worst-case runtime expo-
nential in n. However, enormous effort has gone into designing heuristics that complete much
more quickly on many real-world instances. In particular, SAT Solvers—with many additional
optimizations—were used to solve large-scale graph coloring problems arising in the 2016 US Fed-
eral Communications Commission (FCC) auction to reallocate wireless spectrum.
Thus motivated, we will now turn to algorithms for Satisfiability, to get a taste of some of the
ideas that go into SAT Solvers.
5 Resolution
SAT Solvers are algorithms to solve CNF-Satisfiability. Although they have worst-case exponen-
tial running time, on many “real-world” instances, they terminate more quickly with either (a) a
satisfying assignment, or (b) a “proof” that the input formula is unsatisfiable.
The best known SAT solvers implicitly use the technique of resolution. The idea of resolution
is to repeatedly derive new clauses from the original clauses (using a valid deduction rule) until we
either derive an empty clause (which is false, and thus we have a proof that the original formula
is unsatisfiable) or we cannot derive any more clauses (in which case we can efficiently construct a
satisfying assignment).
Definition 5.1 (resolution rule). For clauses C and D, define their resolvent to be
(
if ` is a literal s.t. ` ∈ C and ¬` ∈ D
C D =
if there is no such literal `
Examples:
From now on, it will be useful to view a CNF formula as just a set C of clauses.
5
Definition 5.2. Let C be a set of clauses over variables x0 , . . . , xn−1 . We say that an assignment
α ∈ {0, 1}n satisfies C if α satisfies all of the clauses in C, or equivalently α satisfies the CNF
formula ^
ϕ(x0 , . . . , xn−1 ) = C(x0 , . . . , xn−1 ).
C∈C
Lemma 5.3. Let C be a set of clauses and let C, D ∈ C. Then C and C ∪ {C D} have the same
set of satisfying assignments.
Given this, we can start with a set C of clauses from a CNF formula and keep adding resolvents
of clauses in C until we cannot add any new ones. The Resolution Theorem tells us that this suffices
to solve Satisfiability.
Theorem 5.4 (Resolution Theorem). Let C be a set of clauses over variables x0 , . . . , xn−1 . Suppose
that C is closed under resolution, meaning that for every C, D ∈ C, we have C D ∈ C. Then:
1. C is unsatisfiable iff ∅ ∈ C.
2. If ∅ ∈
/ C, then we can find a satisfying assignment to C in time O(n + k · |C|).