0% found this document useful (0 votes)
20 views6 pages

2024 CS1200 Lec15 Notes

Uploaded by

heenaknoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views6 pages

2024 CS1200 Lec15 Notes

Uploaded by

heenaknoor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CS1200: Intro.

to Algorithms and their Limitations Anshu & Vadhan

Lecture 15: Logic


Harvard SEAS - Fall 2024 2024-10-24

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.

• Problem Set 6 distributed, due 10/30.

• Reflection summaries

1. PS3: most of you found RAM/WordRAM Models useful in concretizing constant-time


operations and connecting to real-world computing, though some (10+) didn’t see value
in covering it.
2. PS4: Top two topics that you all wanted to study more (pre-midterm) were RAM/Word-
RAM and BSTs. Also want better understanding of what constitutes a rigorous proof,
how to perform reductions, and intuition for randomness being useful.
3. SRE3 (connected components): Found to be our hardest SRE so far. Students felt that
examples and diagrams would have been helpful. We are hoping that you (senders) will
try to come up with them!
4. SRE4 (coloring): You all seemed to enjoy this one, and benefitted from past experience
with SREs. Again visuals very helpful!

Recommended Reading (good for practice problems, too):

• Lewis–Zax Ch. 9–10.

• Roughgarden IV, Sec. 21.5, Ch. 24.

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

ϕpal (x0 , x1 , x2 , x3 ) = ((x0 ∧ x3 ) ∨ (¬x0 ∧ ¬x3 )) ∧ ((x1 ∧ x2 ) ∨ (¬x1 ∧ ¬x2 ))


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 term is an AND of a sequence of literals.

• A clause is an OR of a sequence of literals.

• A boolean formula is in disjunctive normal form (DNF) if it is the OR of a sequence of terms.

• A boolean formula is in conjunctive normal form (CNF) if it is the AND of a sequence of


clauses.
By convention, an empty term is always true and an empty clause is always false. (Q: Why is
this a sensible convention?)

Q: For exach of the examples above, is it in DNF or CNF?

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.

Example: The majority function on 3 bits can be written in CNF as follows:

ψ(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:

(x0 ∨ x1 ) ∧ (x0 ∨ x2 ) ∧ (x1 ∨ x2 ).

3 Computational Problems in Propositional Logic


Here are three natural computational problems about Boolean formulas:

Input : A boolean formula ϕ on n variables


Output : An α ∈ {0, 1}n such that ϕ(α) = 1, or ⊥ if no satisfying assignment exists
Computational Problem Satisfiability
Input : A CNF formula ϕ on n variables
Output : An α ∈ {0, 1}n such that ϕ(α) = 1, or ⊥ if no satisfying assignment exists
Computational Problem CNF-Satisfiability
Input : A DNF formula ϕ on n variables
Output : An α ∈ {0, 1}n such that ϕ(α) = 1, or ⊥ if no satisfying assignment exists
Computational Problem DNF-Satisfiability

3
Q: One of these problems is algorithmically very easy. Which one?

4 Modelling using Satisfiability


One of the reasons for the importance of Satisfiability is its richness in encoding other problems.
Thus any effort gone into optimizing algorithms for (CNF-)Satisfiability (aka “SAT Solvers”) can
be easily be applied to other problems we want to solve.
Theorem 4.1. Graph k-Coloring on graphs with n nodes and m edges can be reduced in time
O(n + km) to (CNF-)Satisfiability with kn variables and n + km clauses.
Proof. Given G = (V, E) and k ∈ N, we will construct a CNF φG that captures the graph k-coloring
problem. In φG , we introduce indicator variables xv,i where v ∈ V and i ∈ [k], which intuitively
are meant to correspond to vertex v being assigned to color i.
We then have a few types of clauses:
1.

2.

3.
For instance, if G is the graph below,

then we make the following SAT instance φG :

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

The validity of the resolution deduction rule is given by the following:

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|).

Example: φ(x0 , x1 , x2 ) = (¬x0 ∨ x1 ) ∧ (¬x1 ∨ x2 ) ∧ (x0 ∨ x1 ∨ x2 ) ∧ (¬x2 )

Example 2: ψ(x0 , x1 , x2 , x3 ) = (¬x0 ∨ x3 ) ∧ (x0 ∨ ¬x3 ) ∧ (¬x1 ∨ x2 ) ∧ (¬x2 ∨ x1 ) ∧ (¬x3 )

You might also like