Propositional Logic and the Satisfiability Problem

Propositional Logic and the Satisfiability Problem
I Propositional Logic
I The Satisfiability Problem
I Semantic Equivalence
I Normal Forms
I Complexity
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 1
Propositional Logic
I Definition An alphabet of propositional logic consists of
. a (countably) infinite set R = {p1, p2, . . .} of propositional variables,
. the set {¬/1, ∧/2, ∨/2, → /2, ↔ /2} of connectives, and
. the special characters “(” and “)”.
I Indices are sometimes omitted.
I We will occasionally use other letters to denote variables.
I Different alphabets of propositional logic differ in R.
I Instead of pi we could have used i as propositional variable.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 2
Propositional Formulas
I Definition An atomic formula, briefly called atom, is a propositional variable.
I Definition The set of propositional formulas is the smallest set L(R) of strings
over an alphabet of propositional logic with the following properties:
1 If F is an atomic formula, then F ∈ L(R).
2 If F ∈ L(R), then ¬F ∈ L(R).
3 If ◦/2 is a binary connective, F, G ∈ L(R), then (F ◦ G) ∈ L(R).
I Definition A literal is an atom, or a negated atom.
The complement L of a literal L is defined as follows:
. If L is an atom A, then L = ¬A,
. if L is a negated atom ¬A, then L = A.
A pair L, L of literals is said to be complementary.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 3
Some Notation
I Notation
A
L
F , G, H
F , G, H
(possibly indexed) denotes an atom,
(possibly indexed) denotes a literal,
(possibly indexed) denote propositional formulas,
denote sets of propositional formulas.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 4
3.2 Semantics
I The set of truth values W is the set {>, ⊥}.
I We consider the following functions on W :
. Negation ¬∗/1.
. Conjunction ∧∗/2.
. Disjunction ∨∗/2.
. Implication →∗ /2.
. Equivalence ↔∗ /2.
>
>
⊥
⊥
>
⊥
>
⊥
¬∗
⊥
⊥
>
>
∧∗
>
⊥
⊥
⊥
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 5
∨∗
>
>
>
⊥
→∗
>
⊥
>
>
↔∗
>
⊥
⊥
>
3.2.2 Interpretations, Models and Logic Consequences
I Definition An interpretation I = (W, ·I ) consists of the set W and a mapping
·I : L(R) → W with:
8
< w∈W
I
[F ] =
¬∗[G]I
:
([G1]I ◦∗ [G2]I )
if F ∈ R,
if F is of the form ¬G,
if F is of the form (G1 ◦ G2).
I Definition An interpretation I = (W, ·I ) is called a model for a propositional
formula F , in symbols I |= F , if [F ]I = >; in this case we say that I satisfies F .
I Definition F is unsatisfiable if it has no models.
F is valid if all interpretations are models.
I Definition An interpretation I = (W, ·I ) is called a model for a set G of
propositional formulas, in symbols I |= G , if [F ]I = > for all F ∈ G ;
in this case we say that I satisfies G .
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 6
Representation of Interpretations
I An interpretation I = (W, ·I ) is uniquely defined by specifying
how ·I acts on atoms.
. I can be represented by Iˆ = {L ∈ L(R) | [L]I = >}.
I Note
. Iˆ does not contain a complementary pair of literals.
. ·I is a total mapping from L(R) to W .
II Hence, for each A ∈ L(R) either A ∈ Iˆ or A ∈ Iˆ but not both.
I In the sequel, we will identify I with Iˆ.
I Definition Let J be a set of literals not containing a complementary pair.
J is a partial interpretation if there is an A such that neither A ∈ J nor A ∈ J .
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 7
Some Additional Notation
I I, J (possibly indexed) denote interpretations.
I We often write F I instead of [F ]I .
I We define the following precedence hierarchy among connectives:
¬ {∨, ∧} → ↔ .
I We sometimes omit parentheses taking into account that conjunction and
disjunction are associative and commutative.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 8
Propositional Satisfiability Problems
I Definition A propositional satisfiability problem, briefly called SAT, consists of a
formula F ∈ L(R), and is the problem to decide whether F is satisfiable.
I SAT is a combinatorial decision problem.
. Decision variant yes/no answer.
. Search variant find a model if F is satisfiable.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 9
A Simple SAT Instance
I Let F = p1
∧ (p 1 ∨ p 2 )
∧ (p 1 → p 3 )
∧ (p 1 ∧ p 3 → p 4 )
∧ (p 5 ∨ p 6 )
∧ (p 5 → p 7 )
∧ (¬p5 ∨ p8)
∧ (¬p7 ∨ ¬p8).
I {p1, p2, p3, p4, ¬p5, p6, ¬p7, ¬p8} ∪ {pi | 8 < i} is a model for F .
I Hence, F is satisfiable.
I How can we find such a model?
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 10
Subformulas
I Definition Let F be a propositional formula. The set of subformulas of F is the
smallest set of formulas S (F ) satisfying the following conditions:
1. F ∈ S (F ).
2. If ¬G ∈ S (F ), then G ∈ S (F ).
3. If (G1 ◦ G2) ∈ S (F ), then G1, G2 ∈ S (F ).
I Example
S (¬((p1 → p2) ∨ p1))
= {¬((p1 → p2) ∨ p1), ((p1 → p2) ∨ p1), (p1 → p2), p1, p2}.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 11
Semantic Equivalence
I Definition Two propositional formulas F and G are semantically equivalent,
in symbols F ≡ G, if for all interpretations I we have: I |= F iff I |= G.
I Some equivalence laws:
¬¬F
≡
F
double negation
¬(F ∧ G)
¬(F ∨ G)
≡
≡
(¬F ∨ ¬G)
(¬F ∧ ¬G)
de Morgan
(F ∧ (G ∨ H ))
(F ∨ (G ∧ H ))
≡
≡
((F ∧ G) ∨ (F ∧ H ))
((F ∨ G) ∧ (F ∨ H ))
distributivity
(F ↔ G )
≡
((F ∧ G) ∨ (¬G ∧ ¬F ))
equivalence
(F → G )
≡
(¬F ∨ G)
implication
(F ∨ G )
(F ∧ G )
≡
≡
F , if F is valid
G, if F is valid
tautology
(F ∨ G )
(F ∧ G )
≡
≡
G, if F is unsatisfiable
F , if F is unsatisfiable
unsatisfiability
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 12
Replacement
I F dG 7→ He denotes the formula obtained from F
by replacing an occurrence of G ∈ S (F ) by H .
. Usually, the context determines which occurrence is meant.
. Sometimes the condition G ∈ S (F ) is omitted.
In this case, if G 6∈ S (F ), then F dG 7→ He = F .
I Replacement Theorem If G ≡ H , then F dG 7→ He ≡ F .
I Exercise Proof the replacement theorem by structural induction.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 13
Generalized Disjunctions and Conjunctions
I Generalized disjunction
[F1, . . . , Fn] = (. . . ((F1 ∨ F2) ∨ F3) ∨ . . . ∨ Fn)
I Generalized conjunction
hF1, . . . , Fni = (. . . ((F1 ∧ F2) ∧ F3) ∧ . . . ∧ Fn)
I Empty generalized disjunction: [ ] with [ ]I = ⊥ for all I .
I Empty generalized conjunction: hi with hiI = > for all I .
I We may extend our language by adding h i and [ ] to the alphabet and treating
them as atoms.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 14
Conjunctive Normal Form
I Definition
. A clause is a generalized disjunction [L1, . . . , Ln], n ≥ 0,
where every Li, 1 ≤ i ≤ n, is a literal.
. A formula is in conjunctive normal form (clause form, CNF) iff it is of the form
hC1, . . . , Cmi, m ≥ 0, and if every Cj , 1 ≤ j ≤ m, is a clause.
I A formula F in CNF is said to be in n-CNF
if each clause occurring in F has at most n literals.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 15
More on Clauses
I A clause is a Horn clause if at most one disjunct is an atom.
I A formula F in CNF is a Horn formula if it contains only Horn clauses.
I A clause is a unit clause if it contains precisely one literal.
I A clause is a binary clause if it contains precisely two literals.
I Observation A clause containing a complementary pair of literals is valid.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 16
More Notation
I C (possibly indexed) denotes a clause.
I Clauses and formulas in CNF are sometimes considered as
sets of literals and clauses, respectively, in which case
. Li, 1 ≤ i ≤ n, are said to be elements of [L1, . . . , Ln] and
. Cj , 1 ≤ j ≤ m, are said to be elements of hC1, . . . , Cmi.
Note that in sets duplicates are removed!
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 17
Transformation into Clause Form
I Theorem There is an algorithm which transforms any propositional formula into a
semantically equivalent formula in clause form.
I Observation
. All equivalences can be eliminated using the law
F ↔ G ≡ (F ∧ G) ∨ (¬F ∧ ¬G).
. All implications can be eliminated using the law
F → G ≡ ¬F ∨ G.
. Hence, we can assume that only the connectives ¬, ∧ and ∨ occur in formulas.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 18
An Algorithm for the Transformation into Clause Form
I Input: A propositional formula F .
Output: A formula, which is in conjunctive normal form and is equivalent to F .
G := h[F ]i. (G is a conjunction of disjunctions.)
While G is not in conjunctive normal form do:
Select a non-clausal element H from G.
Select a non-literal element K from H .
Apply the rule among the following ones which is applicable.
¬¬D
D
(D1 ∧ D2)
D1 | D2
¬(D1 ∧ D2)
¬D1, ¬D2
(D1 ∨ D2)
D1, D2
¬(D1 ∨ D2)
¬D1 | ¬D2
D
I A rule D
0 is applicable to K if K is of the form D .
If applied, then K is replaced by D 0.
I A rule D D|D is applicable to K if K is of the form D .
1 2
If applied, H is replaced by two disjunctions:
The first one is obtained from H by replacing the occurrence of D by D1.
The second one is obtained from H by replacing the occurrence of D by D2.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 19
An Example
I Let F = (p ∧ (p → q )) → q .
I F is valid.
I Eliminating implications yields:
¬(p ∧ (¬p ∨ q )) ∨ q.
I Applying the algorithm yields:
h[¬(p ∧ (¬p ∨ q )) ∨ q ]i
h[¬(p ∧ (¬p ∨ q ), q ]i
h[¬p, ¬(¬p ∨ q ), q ]i
h[¬p, ¬¬p ∧ ¬q, q ]i
h[¬p, ¬¬p, q ], [¬p, ¬q, q ]i
h[¬p, p, q ], [¬p, ¬q, q ]i
I Both clauses in the final formula contain a complementary pair of literals.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 20
Definitional Transformation
I The size of a formula may grow exponentially during normalization.
I Can we do better?
. Unfortunately, the shortest CNF of some F is exponential in the size of F .
. Luckily, we may use a weaker concept.
I Definitional transformation (Eder, 1985)
. Let F be a formula, G ∈ S (F ) and p 6∈ S (F ) a propositional variable.
. Replace F by F dG 7→ pe ∧ (p ↔ G).
I Some observations
. F 6≡ F dG 7→ pe ∧ (p ↔ G).
. F is satisfiable iff F dG 7→ pe ∧ (p ↔ G) is satisfiable.
. The above mentioned exponential growth can be avoided.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 21
Reduct of a CNF-Formula
I Definition Let F be a CNF-formula and J a partial interpretation. The reduct of F
wrt J , in symbols FJ , is obtained by applying the following transformations to F :
. For all L ∈ J do:
if L = A, then replace each occurrence of A in F by h i.
if L = A, then replace each occurrence of A in F by [ ].
. Eliminate all occurrences of [ ] and h i
by applying the replacement theorem using
the laws of validity and unsatisfiability.
I Let F be the following formula:
h[p1], [p1, p2], [¬p1, p3], [¬p1, ¬p3, p4], [p5, p6], [¬p5, p7], [¬p5, p8], [¬p7, ¬p8]i.
Then,
F{p1}
F{p1,p3}
F{p1,p3,p4}
=
=
=
h[p3], [¬p3, p4], [p5, p6], [¬p5, p7], [¬p5, p8], [¬p7, ¬p8]i.
h[p4], [p5, p6], [¬p5, p7], [¬p5, p8], [¬p7, ¬p8]i.
h[p5, p6], [¬p5, p7], [¬p5, p8], [¬p7, ¬p8]i.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 22
Computational Complexity
I Let P be the class of problems that can be solved by a deterministic Turing
machine in polynomial time.
I Let N P be the class of problems that can be solved by a nondeterministic Turing
machine in polynomial time.
I Obviously, P ⊆ N P .
I The question whether N P ⊆ P holds is open.
I A problem that is at least as hard as any other problem in N P is called N P -hard
(in the sense that each problem in N P can be polynomially reduced to it).
I An N P -hard problem which is in N P is called N P -complete.
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 23
Computational Complexity and SAT
I Let F be a formula containing 1000 different propositional variables.
I There are 21000 different interpretations for F .
I A truth table for F has 21000 rows.
I SAT is N P -complete.
I This holds even if SAT is restricted to CNF or even 3-CNF formulae
(Garey, Johnson 1979).
I SAT is decidable in linear time for DNF, for 2-CNF (Cook 1971) or for Horn formulae
(Dowling, Gallier 1984; Scutella 1990).
Steffen Hölldobler
Propositional Logic and the Satisfiability Problem (15th April 2009) 24