0% found this document useful (0 votes)
39 views

CS 228: Logic in Computer Science: Krishna. S

This document provides an overview of the CS 228 course "Logic in Computer Science". The course will cover several logics including propositional logic, first-order logic, monadic second-order logic, and linear temporal logic. It will teach how to determine if a formula is satisfiable or valid in a given logic, the complexity of these problems, algorithms for solving them, how logic is used in proofs and computer science applications. Example problems will be solved using techniques like natural deduction.

Uploaded by

Mohit Yadav
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)
39 views

CS 228: Logic in Computer Science: Krishna. S

This document provides an overview of the CS 228 course "Logic in Computer Science". The course will cover several logics including propositional logic, first-order logic, monadic second-order logic, and linear temporal logic. It will teach how to determine if a formula is satisfiable or valid in a given logic, the complexity of these problems, algorithms for solving them, how logic is used in proofs and computer science applications. Example problems will be solved using techniques like natural deduction.

Uploaded by

Mohit Yadav
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/ 53

CS 228 : Logic in Computer Science

Krishna. S

1/16
Welcome

What is this course about? A mini-zoo of logics.

2/16
Welcome

What is this course about? A mini-zoo of logics. Here are some


typical questions you will learn to answer:

2/16
Welcome

What is this course about? A mini-zoo of logics. Here are some


typical questions you will learn to answer:
I Q1: Given a formula ϕ in a logic L, is ϕ satisfiable?

2/16
Welcome

What is this course about? A mini-zoo of logics. Here are some


typical questions you will learn to answer:
I Q1: Given a formula ϕ in a logic L, is ϕ satisfiable?
I Q2: Given a formula ϕ in a logic L, is ϕ valid?

2/16
Welcome

What is this course about? A mini-zoo of logics. Here are some


typical questions you will learn to answer:
I Q1: Given a formula ϕ in a logic L, is ϕ satisfiable?
I Q2: Given a formula ϕ in a logic L, is ϕ valid?
I Q3: How easy is to answer Q1 and Q2?

2/16
Welcome

What is this course about? A mini-zoo of logics. Here are some


typical questions you will learn to answer:
I Q1: Given a formula ϕ in a logic L, is ϕ satisfiable?
I Q2: Given a formula ϕ in a logic L, is ϕ valid?
I Q3: How easy is to answer Q1 and Q2?
I Q4: Can you write an algorithm to answer Q1 and Q2?

2/16
Welcome

What is this course about? A mini-zoo of logics. Here are some


typical questions you will learn to answer:
I Q1: Given a formula ϕ in a logic L, is ϕ satisfiable?
I Q2: Given a formula ϕ in a logic L, is ϕ valid?
I Q3: How easy is to answer Q1 and Q2?
I Q4: Can you write an algorithm to answer Q1 and Q2?
I Q5: Can you “prove” any factually correct statement using the
chosen logic L?

2/16
Welcome

What is this course about? A mini-zoo of logics. Here are some


typical questions you will learn to answer:
I Q1: Given a formula ϕ in a logic L, is ϕ satisfiable?
I Q2: Given a formula ϕ in a logic L, is ϕ valid?
I Q3: How easy is to answer Q1 and Q2?
I Q4: Can you write an algorithm to answer Q1 and Q2?
I Q5: Can you “prove” any factually correct statement using the
chosen logic L?
I Q6: How is logic L used in computer science?

2/16
Welcome

What is this course about? A mini-zoo of logics. Here are some


typical questions you will learn to answer:
I Q1: Given a formula ϕ in a logic L, is ϕ satisfiable?
I Q2: Given a formula ϕ in a logic L, is ϕ valid?
I Q3: How easy is to answer Q1 and Q2?
I Q4: Can you write an algorithm to answer Q1 and Q2?
I Q5: Can you “prove” any factually correct statement using the
chosen logic L?
I Q6: How is logic L used in computer science?
I Q7: What are the techniques needed to go about these
questions?

2/16
Members of the mini-zoo

We will restrict ourselves to the following members:

3/16
Members of the mini-zoo

We will restrict ourselves to the following members:


I Propositional Logic

3/16
Members of the mini-zoo

We will restrict ourselves to the following members:


I Propositional Logic
I First Order Logic

3/16
Members of the mini-zoo

We will restrict ourselves to the following members:


I Propositional Logic
I First Order Logic
I Monadic Second Order Logic

3/16
Members of the mini-zoo

We will restrict ourselves to the following members:


I Propositional Logic
I First Order Logic
I Monadic Second Order Logic
I Linear Temporal Logic

3/16
Members of the mini-zoo

We will restrict ourselves to the following members:


I Propositional Logic
I First Order Logic
I Monadic Second Order Logic
I Linear Temporal Logic
I Their applications in CS
More if time permits!

3/16
References

I To start with, the text book of Huth and Ryan : Logic for CS.

4/16
References

I To start with, the text book of Huth and Ryan : Logic for CS.
I As we go ahead, lecture notes/monographs/other text books.

4/16
References

I To start with, the text book of Huth and Ryan : Logic for CS.
I As we go ahead, lecture notes/monographs/other text books.
I Classes : Slot 5. Tutorial: To discuss.
I Confirmed TAs: Anish Yogesh Kulkarni, Ameya Vikrama Singh,
Om Swostik Mishra, Agnipratim Das, Nilabha Saha, Ashwin
Abraham

4/16
Propositional Logic

5/16
Syntax

I Finite set of propositional variables p, q, . . .

6/16
Syntax

I Finite set of propositional variables p, q, . . .


I Each of these can be true/false

6/16
Syntax

I Finite set of propositional variables p, q, . . .


I Each of these can be true/false
I Combine propositions using ¬, ∨, ∧, →

6/16
Syntax

I Finite set of propositional variables p, q, . . .


I Each of these can be true/false
I Combine propositions using ¬, ∨, ∧, →
I Parantheses as required

6/16
Syntax

I Finite set of propositional variables p, q, . . .


I Each of these can be true/false
I Combine propositions using ¬, ∨, ∧, →
I Parantheses as required
I Example : [p ∧ (q ∨ r )] → [¬r ∧ p]
I ¬ binds tighter than ∨, ∧, which bind tighter than →. In the
absence of parantheses, p → q → r is read as p → (q → r )

6/16
Natural Deduction

I If it rains, Tia is outside and does not have any raingear with her,
she will get wet. ϕ = (R ∧ TiaOut ∧ ¬RG) → TiaWet

7/16
Natural Deduction

I If it rains, Tia is outside and does not have any raingear with her,
she will get wet. ϕ = (R ∧ TiaOut ∧ ¬RG) → TiaWet
I It is raining, and Tia is outside, and is not wet.
ψ = (R ∧ TiaOut ∧ ¬TiaWet)

7/16
Natural Deduction

I If it rains, Tia is outside and does not have any raingear with her,
she will get wet. ϕ = (R ∧ TiaOut ∧ ¬RG) → TiaWet
I It is raining, and Tia is outside, and is not wet.
ψ = (R ∧ TiaOut ∧ ¬TiaWet)
I So, Tia has her rain gear with her. RG
I Thus, χ = ϕ ∧ ψ → RG. You can deduce RG from ϕ ∧ ψ.
I Is χ valid? Is χ satisfiable?

7/16
Two Examples of Natural Deduction

8/16
Solve Sudoku

Consider the following kid’s version of Sudoku.

2 4
1 3
4 2
1 3

Rules:
I Each row must contain all numbers 1-4
I Each column must contain all numbers 1-4
I Each 2 × 2 block must contain all numbers 1-4
I No cell contains 2 or more numbers

9/16
Encoding as Propositional
Satisfiability

I Proposition P(i, j, n) is true when cell (i, j) has number n

10/16
Encoding as Propositional
Satisfiability

I Proposition P(i, j, n) is true when cell (i, j) has number n


I 4 × 4 × 4 propositions

10/16
Encoding as Propositional
Satisfiability

I Proposition P(i, j, n) is true when cell (i, j) has number n


I 4 × 4 × 4 propositions
I Each row must contain all 4 numbers
I Row 1: [P(1, 1, 1) ∨ P(1, 2, 1) ∨ P(1, 3, 1) ∨ P(1, 4, 1)]∧
[P(1, 1, 2) ∨ P(1, 2, 2) ∨ P(1, 3, 2) ∨ P(1, 4, 2)]∧
[P(1, 1, 3) ∨ P(1, 2, 3) ∨ P(1, 3, 3) ∨ P(1, 4, 3)]∧
[P(1, 1, 4) ∨ P(1, 2, 4) ∨ P(1, 3, 4) ∨ P(1, 4, 4)]

10/16
Encoding as Propositional
Satisfiability

I Proposition P(i, j, n) is true when cell (i, j) has number n


I 4 × 4 × 4 propositions
I Each row must contain all 4 numbers
I Row 1: [P(1, 1, 1) ∨ P(1, 2, 1) ∨ P(1, 3, 1) ∨ P(1, 4, 1)]∧
[P(1, 1, 2) ∨ P(1, 2, 2) ∨ P(1, 3, 2) ∨ P(1, 4, 2)]∧
[P(1, 1, 3) ∨ P(1, 2, 3) ∨ P(1, 3, 3) ∨ P(1, 4, 3)]∧
[P(1, 1, 4) ∨ P(1, 2, 4) ∨ P(1, 3, 4) ∨ P(1, 4, 4)]
I Row 2: [P(2, 1, 1) ∨ . . .
I Row 3: [P(3, 1, 1) ∨ . . .
I Row 4: [P(4, 1, 1) ∨ . . .

10/16
Encoding as Propositional
Satisfiability

Each column must contain all numbers 1-4

11/16
Encoding as Propositional
Satisfiability

Each column must contain all numbers 1-4


I Column 1: [P(1, 1, 1) ∨ P(2, 1, 1) ∨ P(3, 1, 1) ∨ P(4, 1, 1)]∧
[P(1, 1, 2) ∨ P(2, 1, 2) ∨ P(3, 1, 2) ∨ P(4, 1, 2)]∧
[P(1, 1, 3) ∨ P(2, 1, 3) ∨ P(3, 1, 3) ∨ P(4, 1, 3)]∧
[P(1, 1, 4) ∨ P(2, 1, 4) ∨ P(3, 1, 4) ∨ P(4, 1, 4)]

11/16
Encoding as Propositional
Satisfiability

Each column must contain all numbers 1-4


I Column 1: [P(1, 1, 1) ∨ P(2, 1, 1) ∨ P(3, 1, 1) ∨ P(4, 1, 1)]∧
[P(1, 1, 2) ∨ P(2, 1, 2) ∨ P(3, 1, 2) ∨ P(4, 1, 2)]∧
[P(1, 1, 3) ∨ P(2, 1, 3) ∨ P(3, 1, 3) ∨ P(4, 1, 3)]∧
[P(1, 1, 4) ∨ P(2, 1, 4) ∨ P(3, 1, 4) ∨ P(4, 1, 4)]
I Column 2: [P(1, 2, 1) ∨ . . .
I Column 3: [P(1, 3, 1) ∨ . . .
I Column 4: [P(1, 4, 1) ∨ . . .

11/16
Encoding as Propositional
Satisfiability
Each 2 × 2 block must contain all numbers 1-4

12/16
Encoding as Propositional
Satisfiability
Each 2 × 2 block must contain all numbers 1-4
I Upper left block contains all numbers 1-4:

[P(1, 1, 1) ∨ P(1, 2, 1) ∨ P(2, 1, 1) ∨ P(2, 2, 1)]∧


[P(1, 1, 2) ∨ P(1, 2, 2) ∨ P(2, 1, 2) ∨ P(2, 2, 2)]∧
[P(1, 1, 3) ∨ P(1, 2, 3) ∨ P(2, 1, 3) ∨ P(2, 2, 3)]∧
[P(1, 1, 4) ∨ P(1, 2, 4) ∨ P(2, 1, 4) ∨ P(2, 2, 4)]

12/16
Encoding as Propositional
Satisfiability
Each 2 × 2 block must contain all numbers 1-4
I Upper left block contains all numbers 1-4:

[P(1, 1, 1) ∨ P(1, 2, 1) ∨ P(2, 1, 1) ∨ P(2, 2, 1)]∧


[P(1, 1, 2) ∨ P(1, 2, 2) ∨ P(2, 1, 2) ∨ P(2, 2, 2)]∧
[P(1, 1, 3) ∨ P(1, 2, 3) ∨ P(2, 1, 3) ∨ P(2, 2, 3)]∧
[P(1, 1, 4) ∨ P(1, 2, 4) ∨ P(2, 1, 4) ∨ P(2, 2, 4)]

I Upper right block contains all numbers 1-4:


[P(1, 3, 1) ∨ P(1, 4, 1) ∨ P(2, 3, 1) ∨ P(2, 4, 1)] ∧ . . .
I Lower left block contains all numbers 1-4:
[P(3, 1, 1) ∨ P(3, 2, 1) ∨ P(4, 1, 1) ∨ P(4, 2, 1)] ∧ . . .
I Lower right block contains all numbers 1-4:
[P(3, 3, 1) ∨ P(3, 4, 1) ∨ P(4, 3, 1) ∨ P(4, 4, 1)] ∧ . . .
12/16
Encoding as Propositional
Satisfiability

No cell contains 2 or more numbers


I For cell(1,1):

P(1, 1, 1) → [¬P(1, 1, 2) ∧ ¬P(1, 1, 3) ∧ ¬P(1, 1, 4)]∧

P(1, 1, 2) → [¬P(1, 1, 1) ∧ ¬P(1, 1, 3) ∧ ¬P(1, 1, 4)]∧


P(1, 1, 3) → [¬P(1, 1, 1) ∧ ¬P(1, 1, 2) ∧ ¬P(1, 1, 4)]∧
P(1, 1, 4) → [¬P(1, 1, 1) ∧ ¬P(1, 1, 2) ∧ ¬P(1, 1, 3)]∧
I Similar for other cells

13/16
Encoding as Propositional
Satisfiability

Encoding Initial Configuration:

P(1, 2, 2) ∧ P(1, 3, 4) ∧ P(2, 1, 1) ∧ P(2, 4, 3)∧

P(3, 1, 4) ∧ P(3, 4, 2) ∧ P(4, 2, 1) ∧ P(4, 3, 3)

Solving Sodoku
To solve the puzzle, just conjunct all the above formulae and find a
satisfiable truth assignment!

14/16
Gold Rush

(Box1) The gold is not here


(Box2) The gold is not here
(Box3) The gold is in Box 2

Only one message is true; the other two are false. Which box has the
gold?

15/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you

16/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you
I M1 ↔ ¬G1,

16/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you
I M1 ↔ ¬G1, M2 ↔ ¬G2,

16/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you
I M1 ↔ ¬G1, M2 ↔ ¬G2, M3 ↔ G2

16/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you
I M1 ↔ ¬G1, M2 ↔ ¬G2, M3 ↔ G2
I ¬(M1 ∧ M2 ∧ M3),

16/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you
I M1 ↔ ¬G1, M2 ↔ ¬G2, M3 ↔ G2
I ¬(M1 ∧ M2 ∧ M3), M1 ∨ M2 ∨ M3,

16/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you
I M1 ↔ ¬G1, M2 ↔ ¬G2, M3 ↔ G2
I ¬(M1 ∧ M2 ∧ M3), M1 ∨ M2 ∨ M3,
I (¬M1 ∧ ¬M2) ∨ (¬M1 ∧ ¬M3) ∨ (¬M2 ∧ ¬M3)

16/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you
I M1 ↔ ¬G1, M2 ↔ ¬G2, M3 ↔ G2
I ¬(M1 ∧ M2 ∧ M3), M1 ∨ M2 ∨ M3,
I (¬M1 ∧ ¬M2) ∨ (¬M1 ∧ ¬M3) ∨ (¬M2 ∧ ¬M3)
I Conjunct all these, and call the formula ϕ.

16/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you
I M1 ↔ ¬G1, M2 ↔ ¬G2, M3 ↔ G2
I ¬(M1 ∧ M2 ∧ M3), M1 ∨ M2 ∨ M3,
I (¬M1 ∧ ¬M2) ∨ (¬M1 ∧ ¬M3) ∨ (¬M2 ∧ ¬M3)
I Conjunct all these, and call the formula ϕ.
I Is there a unique satisfiable assignment for ϕ?

16/16
Solve Gold Rush

I Propositions M1, M2, M3 representing messages in boxes 1,2,3


I Propositions G1, G2, G3 representing gold in boxes 1,2,3
I Formalize what is given to you
I M1 ↔ ¬G1, M2 ↔ ¬G2, M3 ↔ G2
I ¬(M1 ∧ M2 ∧ M3), M1 ∨ M2 ∨ M3,
I (¬M1 ∧ ¬M2) ∨ (¬M1 ∧ ¬M3) ∨ (¬M2 ∧ ¬M3)
I Conjunct all these, and call the formula ϕ.
I Is there a unique satisfiable assignment for ϕ?
I For example, is M1 = true a part of the satisfiable assignment?

16/16

You might also like