You are on page 1of 44

CS 228 : Logic in Computer Science

Krishna. S

1/17
Recap

I semantic entailment ϕ |= ψ and entailment ϕ ` ψ


I Soundness : anything that gets proved is sound
I Completeness : any fact is provable using the proof rules

2/17
Completeness

ϕ1 , . . . , ϕn |= ψ ⇒ ϕ1 , . . . , ϕn ` ψ

Whenever ϕ1 , . . . , ϕn semantically entail ψ, then ψ can be proved


from ϕ1 , . . . , ϕn . The proof rules are complete

3/17
Completeness : 3 steps

I Given ϕ1 , . . . , ϕn |= ψ

4/17
Completeness : 3 steps

I Given ϕ1 , . . . , ϕn |= ψ
I Step 1: Show that |= ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . ))

4/17
Completeness : 3 steps

I Given ϕ1 , . . . , ϕn |= ψ
I Step 1: Show that |= ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . ))
I Step 2: Show that ` ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . ))

4/17
Completeness : 3 steps

I Given ϕ1 , . . . , ϕn |= ψ
I Step 1: Show that |= ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . ))
I Step 2: Show that ` ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . ))
I Step 3: Show that ϕ1 , . . . , ϕn ` ψ

4/17
Completeness : Step 1

I Assume ϕ1 , . . . , ϕn |= ψ. Whenever all of ϕ1 , . . . , ϕn evaluate to


true, so does ψ.

5/17
Completeness : Step 1

I Assume ϕ1 , . . . , ϕn |= ψ. Whenever all of ϕ1 , . . . , ϕn evaluate to


true, so does ψ.
I If 2 ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )), then ψ evaluates to false
when all of ϕ1 , . . . , ϕn evaluate to true, a contradiction.

5/17
Completeness : Step 1

I Assume ϕ1 , . . . , ϕn |= ψ. Whenever all of ϕ1 , . . . , ϕn evaluate to


true, so does ψ.
I If 2 ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )), then ψ evaluates to false
when all of ϕ1 , . . . , ϕn evaluate to true, a contradiction.
I Hence, |= ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )).

5/17
Completeness : Step 2

I Given |= ψ, show that ` ψ

6/17
Completeness : Step 2

I Given |= ψ, show that ` ψ


I Assume p1 , . . . , pn are the propositional variables in ψ. We know
that all the 2n assignments of values to p1 , . . . , pn make ψ true.

6/17
Completeness : Step 2

I Given |= ψ, show that ` ψ


I Assume p1 , . . . , pn are the propositional variables in ψ. We know
that all the 2n assignments of values to p1 , . . . , pn make ψ true.
I Using this insight, we have to give a proof of ψ.

6/17
Completeness : Step 2

Truth Table to Proof


Let ϕ be a formula with variables p1 , . . . , pn . Let T be the truth table of
ϕ, and let l be a line number in T . Let p̂i represent pi if pi is assigned
true in line l, and let it denote ¬pi if pi is assigned false in line l. Then
1. p̂1 , . . . , p̂n ` ϕ if ϕ evaluates to true in line l
2. p̂1 , . . . , p̂n ` ¬ϕ if ϕ evaluates to false in line l

7/17
Completeness : Step 2

Truth Table to Proof


Let ϕ be a formula with variables p1 , . . . , pn . Let T be the truth table of
ϕ, and let l be a line number in T . Let p̂i represent pi if pi is assigned
true in line l, and let it denote ¬pi if pi is assigned false in line l. Then
1. p̂1 , . . . , p̂n ` ϕ if ϕ evaluates to true in line l
2. p̂1 , . . . , p̂n ` ¬ϕ if ϕ evaluates to false in line l

I p̂ = p, q̂ = q ` p ∧ q
I p̂ = ¬p, q̂ = q ` ¬(p ∧ q)
I p̂ = p, q̂ = ¬q ` ¬(p ∧ q)
I p̂ = ¬p, q̂ = ¬q ` ¬(p ∧ q)

7/17
Truth Table to Proof

I Structural Induction on ϕ.

8/17
Truth Table to Proof

I Structural Induction on ϕ.
I Base : If ϕ = p, a proposition, then we have p ` p and ¬p ` ¬p.

8/17
Truth Table to Proof

I Structural Induction on ϕ.
I Base : If ϕ = p, a proposition, then we have p ` p and ¬p ` ¬p.
I Assume for formulae of size 6 k − 1 (size=height of the parse
tree). What is a parse tree?

8/17
Truth Table to Proof

I Structural Induction on ϕ.
I Base : If ϕ = p, a proposition, then we have p ` p and ¬p ` ¬p.
I Assume for formulae of size 6 k − 1 (size=height of the parse
tree). What is a parse tree?
I Case Negation : ϕ = ¬ϕ1

8/17
Truth Table to Proof

I Structural Induction on ϕ.
I Base : If ϕ = p, a proposition, then we have p ` p and ¬p ` ¬p.
I Assume for formulae of size 6 k − 1 (size=height of the parse
tree). What is a parse tree?
I Case Negation : ϕ = ¬ϕ1
I Assume ϕ evaluates to true in line l of T . Then ϕ1 evaluates to
false in line l. By inductive hypothesis, p̂1 , . . . , p̂n ` ¬ϕ1 .

8/17
Truth Table to Proof

I Structural Induction on ϕ.
I Base : If ϕ = p, a proposition, then we have p ` p and ¬p ` ¬p.
I Assume for formulae of size 6 k − 1 (size=height of the parse
tree). What is a parse tree?
I Case Negation : ϕ = ¬ϕ1
I Assume ϕ evaluates to true in line l of T . Then ϕ1 evaluates to
false in line l. By inductive hypothesis, p̂1 , . . . , p̂n ` ¬ϕ1 .
I Assume ϕ evaluates to false in line l of T . Then ϕ1 evaluates to
true in line l. By inductive hypothesis, p̂1 , . . . , p̂n ` ϕ1 . Use the ¬¬i
rule to obtain a proof of p̂1 , . . . , p̂n ` ¬¬ϕ1 .

8/17
Truth Table to Proof

I Case → : ϕ = ϕ1 → ϕ2 .

9/17
Truth Table to Proof

I Case → : ϕ = ϕ1 → ϕ2 .
I If ϕ evaluates to false in line l, then ϕ1 evaluates to true and ϕ2 to
false. Let {q1 , . . . , qk } be the variables of ϕ1 and let {r1 , . . . , rj } be
the variables in ϕ2 . {q1 , . . . , qk } ∪ {r1 , . . . , rj } = {p1 , . . . , pn }.

9/17
Truth Table to Proof

I Case → : ϕ = ϕ1 → ϕ2 .
I If ϕ evaluates to false in line l, then ϕ1 evaluates to true and ϕ2 to
false. Let {q1 , . . . , qk } be the variables of ϕ1 and let {r1 , . . . , rj } be
the variables in ϕ2 . {q1 , . . . , qk } ∪ {r1 , . . . , rj } = {p1 , . . . , pn }.
I By inductive hypothesis, qˆ1 , . . . , qˆk |= ϕ1 and rˆ1 , . . . , rˆj |= ¬ϕ2 .
Then, pˆ1 , . . . , pˆn |= ϕ1 ∧ ¬ϕ2 .

9/17
Truth Table to Proof

I Case → : ϕ = ϕ1 → ϕ2 .
I If ϕ evaluates to false in line l, then ϕ1 evaluates to true and ϕ2 to
false. Let {q1 , . . . , qk } be the variables of ϕ1 and let {r1 , . . . , rj } be
the variables in ϕ2 . {q1 , . . . , qk } ∪ {r1 , . . . , rj } = {p1 , . . . , pn }.
I By inductive hypothesis, qˆ1 , . . . , qˆk |= ϕ1 and rˆ1 , . . . , rˆj |= ¬ϕ2 .
Then, pˆ1 , . . . , pˆn |= ϕ1 ∧ ¬ϕ2 .
I Prove that ϕ1 ∧ ¬ϕ2 ` ¬(ϕ1 → ϕ2 ).

9/17
Truth Table to Proof

I Case → : ϕ = ϕ1 → ϕ2 .

10/17
Truth Table to Proof

I Case → : ϕ = ϕ1 → ϕ2 .
I If ϕ evaluates to true in line l, then there are 3 possibilities. If both
ϕ1 , ϕ2 evaluate to true, then we have pˆ1 , . . . , pˆn |= ϕ1 ∧ ϕ2 . Proving
ϕ1 ∧ ϕ2 ` ϕ1 → ϕ2 , we are done.

10/17
Truth Table to Proof

I Case → : ϕ = ϕ1 → ϕ2 .
I If ϕ evaluates to true in line l, then there are 3 possibilities. If both
ϕ1 , ϕ2 evaluate to true, then we have pˆ1 , . . . , pˆn |= ϕ1 ∧ ϕ2 . Proving
ϕ1 ∧ ϕ2 ` ϕ1 → ϕ2 , we are done.
I If both ϕ1 , ϕ2 evaluate to false, then we have
pˆ1 , . . . , pˆn |= ¬ϕ1 ∧ ¬ϕ2 . Proving ¬ϕ1 ∧ ¬ϕ2 ` ϕ1 → ϕ2 , we are
done.

10/17
Truth Table to Proof

I Case → : ϕ = ϕ1 → ϕ2 .
I If ϕ evaluates to true in line l, then there are 3 possibilities. If both
ϕ1 , ϕ2 evaluate to true, then we have pˆ1 , . . . , pˆn |= ϕ1 ∧ ϕ2 . Proving
ϕ1 ∧ ϕ2 ` ϕ1 → ϕ2 , we are done.
I If both ϕ1 , ϕ2 evaluate to false, then we have
pˆ1 , . . . , pˆn |= ¬ϕ1 ∧ ¬ϕ2 . Proving ¬ϕ1 ∧ ¬ϕ2 ` ϕ1 → ϕ2 , we are
done.
I Last, if ϕ1 evaluates to false and ϕ2 evaluates to true, then we have
pˆ1 , . . . , pˆn |= ¬ϕ1 ∧ ϕ2 . Proving ¬ϕ1 ∧ ϕ2 ` ϕ1 → ϕ2 , we are done.

10/17
Truth Table to Proof

I Prove the cases ∧, ∨.

11/17
On An Example

We know |= (p ∧ q) → p. Using this fact, show that ` (p ∧ q) → p.


I p, q ` (p ∧ q) → p
I ¬p, q ` (p ∧ q) → p
I p, ¬q ` (p ∧ q) → p
I ¬p, ¬q ` (p ∧ q) → p
Now, combine the 4 proofs above to give a single proof for
` (p ∧ q) → p.

12/17
Completeness : Steps 2, 3

I Step 2: From |= ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )), use LEM on all


the propositional variables of ϕ1 , . . . , ϕn , ψ to obtain
` ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )).

13/17
Completeness : Steps 2, 3

I Step 2: From |= ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )), use LEM on all


the propositional variables of ϕ1 , . . . , ϕn , ψ to obtain
` ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )).
I Step 3: Take the proof ` ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )). This
proof has n nested boxes, the ith box opening with the
assumption ϕi . The last box closes with the last line ψ. Hence,
the line immediately after the last box is ϕn → ψ.

13/17
Completeness : Steps 2, 3

I Step 2: From |= ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )), use LEM on all


the propositional variables of ϕ1 , . . . , ϕn , ψ to obtain
` ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )).
I Step 3: Take the proof ` ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )). This
proof has n nested boxes, the ith box opening with the
assumption ϕi . The last box closes with the last line ψ. Hence,
the line immediately after the last box is ϕn → ψ.
I In a similar way, the (n − 1)th box has as its last line ϕn → ψ, and
hence, the line immediately after this box is ϕn−1 → (ϕn → ψ)
and so on.

13/17
Completeness : Steps 2, 3

I Step 2: From |= ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )), use LEM on all


the propositional variables of ϕ1 , . . . , ϕn , ψ to obtain
` ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )).
I Step 3: Take the proof ` ϕ1 → (ϕ2 → (. . . (ϕn → ψ) . . . )). This
proof has n nested boxes, the ith box opening with the
assumption ϕi . The last box closes with the last line ψ. Hence,
the line immediately after the last box is ϕn → ψ.
I In a similar way, the (n − 1)th box has as its last line ϕn → ψ, and
hence, the line immediately after this box is ϕn−1 → (ϕn → ψ)
and so on.
I Add premises ϕ1 , . . . , ϕn on the top. Use MP on the premises,
and the lines after boxes 1 to n in order to obtain ψ.

13/17
Summary

Propositional Logic is sound and complete.

14/17
Normal Forms

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


are referred to as positive and negative literals respectively.

15/17
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 = Li,j
i=1 j=1

each Li,j is a literal.

15/17
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 = Li,j
i=1 j=1

each Li,j is a literal.


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.

15/17
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.

16/17
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.

16/17
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.

17/17
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 : Replace all subformulae
I ¬¬G with G,
I ¬(G ∧ H) with ¬G ∨ ¬H
I ¬(G ∨ H) with ¬G ∧ ¬H
When there are no more such subformulae, proceed to the next
step.

17/17
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 : Replace all subformulae
I ¬¬G with G,
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)]

17/17

You might also like