Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

CS 228 : Logic in Computer Science

S. Krishna

CS 228 : Logic for CS S. Krishna IIT Bombay


Completeness : Recap

I Show that if |= ψ (ψ is valid), then ` ψ (we can prove ψ)


I Assume p1 , . . . , pn as the variables in ψ, and let |= ψ.
I Let pˆ1 , . . . , pˆn be the assignment of p1 , . . . , pn for any line l in the
truth table
I Show that pˆ1 , . . . , pˆn ` ψ
I The above step gives 2n proofs for ψ, starting from 2n different
premises
I Combine all these proofs, and give a proof for ψ starting with no
premises

CS 228 : Logic for CS S. Krishna IIT Bombay


Completeness : Recap

I To combine the proofs, use LEM. That is, use p1 ∨ ¬p1 .


I You need to prove ψ individually from p1 and from ¬p1 (why?)
I Within p1 , use p2 ∨ ¬p2 . This opens up two proof obligations, one
where you have p1 , p2 , and other where you have p1 , ¬p2 .
I The same can be done within ¬p1 , and in fact inside each pi , ¬pi .
I This gives rise to discharging 2n proofs for ψ, which is what you
had.
I This gives a proof of ψ with no premises.

CS 228 : Logic for CS S. Krishna IIT Bombay


Normal Forms

I A literal is a propositional variable p or its negation ¬p. These


are referred to as positive and negative literals respectively.
I A formula F is in CNF if it is a conjunction of a disjunction of
literals.
^n _m
F = Ci , where Ci = Li,j
i=1 j=1

each Ci is a clause and each Li,j is a literal.


I (x1 ∨ ¬x2 ) ∧ (x3 ∨ x4 ∨ x5 ) ∧ (¬x1 ∨ ¬x2 )
I A formula F is in DNF if it is a disjunction of a conjunction of
literals.
_n ^m
F = Li,j
i=1 j=1

each Li,j is a literal.


I (x1 ∧ ¬x2 ) ∨ (x3 ∧ x4 ∧ x5 ) ∨ (¬x1 ∧ ¬x2 )

CS 228 : Logic for CS S. Krishna IIT Bombay


Normal Forms

In the following, equivalent stands for semantically equivalent

Let F be a formula in CNF and let G be a formula in DNF. Then ¬F is


equivalent to a formula in DNF and ¬G is equivalent to a formula in
CNF.

Every formula F is equivalent to some formula F1 in CNF and some


formula F2 in DNF.

CS 228 : Logic for CS S. Krishna IIT Bombay


CNF Algorithm

Given a formula F , (x → [¬(y ∨ z) ∧ ¬(y → x)])


I Replace all subformulae of the form F → G with ¬F ∨ G, and all
subformulae of the form F ↔ G with (¬F ∨ G) ∧ (¬G ∨ F ). When
there are no more occurrences of →, ↔, proceed to the next
step.
I Get rid of all double negations, and replace all subformulae
I ¬(G ∧ H) with ¬G ∨ ¬H
I ¬(G ∨ H) with ¬G ∧ ¬H
When there are no more such subformulae, proceed to the next
step.
I Distribute ∨ wherever possible.
The resultant formula F1 is in CNF and is provably equivalent to F .
[(¬x ∨ ¬y ) ∧ (¬x ∨ ¬z)] ∧ [(¬x ∨ y ) ∧ (¬x ∨ ¬x)]

CS 228 : Logic for CS S. Krishna IIT Bombay


Satisfiability Checking : Horn
Formulae

I A Horn Formula is a particularly nice kind of CNF formula, which


can be quickly checked for satisfiability.
I How hard is checking satisfiability, in general?

CS 228 : Logic for CS S. Krishna IIT Bombay


Satisfiability Checking : Horn
Formulae

I A formula F is a Horn formula if it is in CNF and every disjunction


contains atmost one positive literal.
I p ∧ (¬p ∨ ¬q ∨ r ) ∧ (¬a ∨ ¬b) is Horn, but a ∨ b is not Horn.
I A basic Horn formula is one which has no ∧. Every Horn formula
is a conjunction of basic Horn formulae.

CS 228 : Logic for CS S. Krishna IIT Bombay


Satisfiability Checking : Horn
Formulae

I Three types of basic Horn : no positive literals, no negative


literals, have both positive and negative literals.
I Basic Horn with both positive and negative literals are written as
an implication p ∧ q ∧ · · · ∧ r → s involving only positive literals.
I Basic Horn with no negative literals are of the form p and are
written as > → p.
I Basic Horn with no positive literals are written as
p ∧ q ∧ · · · ∧ r → ⊥.
I Thus, a Horn formula is written as a conjunction of implications.

CS 228 : Logic for CS S. Krishna IIT Bombay


The Horn Algorithm

Given a Horn formula H,


I Mark all occurrences of p, whenever > → p is a subformula.
I If there is a subformula of the form (p1 ∧ · · · ∧ pm ) → q, where
each pi is marked, and q is not marked, mark q. Repeat this until
there are no subformulae of this form and proceed to the next
step.
I Consider subformulae of the form (p1 ∧ · · · ∧ pm ) → ⊥. If there is
one such subformula with all pi marked, then say Unsat,
otherwise say Sat.

CS 228 : Logic for CS S. Krishna IIT Bombay


An Example

(> → A) ∧ (C → D) ∧ ((A ∧ B) → C) ∧ ((C ∧ D) → ⊥) ∧ (> → B).

I (> → A) ∧ (C → D) ∧ ((A ∧ B) → C) ∧ ((C ∧ D) → ⊥) ∧ (> → B).


I (> → A) ∧ (C → D) ∧ ((A ∧ B) → C) ∧ ((C ∧ D) → ⊥) ∧ (> → B).
I (> → A) ∧ (C → D) ∧ ((A ∧ B) → C) ∧ ((C ∧ D) → ⊥) ∧ (> → B).
I (> → A) ∧ (C → D) ∧ ((A ∧ B) → C) ∧ ((C ∧ D) → ⊥) ∧ (> → B).

CS 228 : Logic for CS S. Krishna IIT Bombay


The Horn Algorithm

The Horn algorithm concludes Sat iff H is satisfiable.

I Let S = {C1 , . . . , Cn } be the set of propositions occurring in H. At


the end of the algorithm, some of these are marked.
I Assume H is satisfiable. Then there is an assignment α of S
such that α |= H. For each basic Horn formula B of H, α(B) = 1.
Also, α(⊥) = 0 and α(>) = 1.
I If B has the form > → Ci , then α(Ci ) = 1. If B has the form
(C1 ∧ · · · ∧ Cn ) → D, where each α(Ci ) = 1, then α(D) = 1.
Hence, α(Ci ) agrees with the marking of the algo.

CS 228 : Logic for CS S. Krishna IIT Bombay


The Horn Algorithm

I Assume the algo says H is unsat. Then there is a subformula B


of the form (A1 ∧ · · · ∧ Am ) → ⊥, where each Ai is marked.
Hence, α(Ai ) = 1 for each Ai . Then α(B) = 0, a contradiction to
our assumption that α(B) = 1 for each B.
I Conversely, assume that the algo says Sat. Show that there
exists a satisfying assignment α, using the markings made by
the algo. Let α be the assignment of S defined by α(Ci ) = 1 iff Ci
is marked. We claim that α |= H.
I Show that α |= B for each basic Horn formula B of H.

CS 228 : Logic for CS S. Krishna IIT Bombay


The Horn Algorithm

I If B has the form > → A, then A is marked in step 1 of the algo,


and so α(B) = 1.
I If B has the form A1 ∧ . . . Am → G, then G is either ⊥ or an
atomic formula.
I If some Ai was not marked, then α(Ai ) = 0, and hence α(B) = 1.
I Assume all the Ai ’s were marked. Then α(Ai ) = 1 for all i. Since
the algo said Sat, G 6= ⊥. Then G is also marked (step 2 of
algo). Hence, α(G) = 1, and we have α(B) = 1.
I Thus, the markings of the algorithm gives rise to a satisfying
assignment α if the algorithm said Sat.

CS 228 : Logic for CS S. Krishna IIT Bombay


Complexity of Horn

I Given a Horn formula ψ with n propositions, how many times do


you have to read ψ?
I Step 1: Read once
I Step 2: Read atmost n times
I Step 3: Read once

CS 228 : Logic for CS S. Krishna IIT Bombay

You might also like