33
CSCI2110 Tutorial 9: Propositional Logic Chow Chi Wang (cwchow ‘at’ cse.cuhk.edu.hk)

CSCI2110 Tutorial 9: Propositional Logic

  • Upload
    crwys

  • View
    71

  • Download
    0

Embed Size (px)

DESCRIPTION

CSCI2110 Tutorial 9: Propositional Logic. Chow Chi Wang ( cwchow ‘at’ cse.cuhk.edu.hk). Propositional Logic. I am lying right now…. Is he telling the truth or lying?. Propositional Statement. A Statement is a sentence that is either True or False . - PowerPoint PPT Presentation

Citation preview

Page 1: CSCI2110  Tutorial 9: Propositional Logic

CSCI2110 Tutorial 9:Propositional Logic

Chow Chi Wang (cwchow ‘at’ cse.cuhk.edu.hk)

Page 2: CSCI2110  Tutorial 9: Propositional Logic

Propositional Logic

I am lying right now…

Is he telling the truth or lying?

Page 3: CSCI2110  Tutorial 9: Propositional Logic

Propositional Statement• A Statement is a sentence that is either True or False.

• Which of these are propositional statements?1. The sun is shining.2. 3 + 4 = 7.3. It rained this morning.4. .5. for .6. Is it raining?7. Come to tutorial!8. 2012 is a prime number.9. Hello world!10. Discrete Maths is very interesting.

Page 4: CSCI2110  Tutorial 9: Propositional Logic

Basic Logic Operators

P PT F

F T

, ~ (NOT) – Truth Table

∧ (AND) – Truth TableP Q PQT T T

T F FF T FF F F

∨ (OR) – Truth TableP Q PQT T T

T F TF T TF F F

• We can construct more complicated statements from these basic operators. (e.g. )

Page 5: CSCI2110  Tutorial 9: Propositional Logic

XOR (Exclusive-OR)• When OR is used in its exclusive sense, “p xor q” means

“p or q but not both”.

• How to express XOR in terms of AND, OR and NOT?

(XOR) – Truth TableP Q PQT T F

T F TF T TF F F

Page 6: CSCI2110  Tutorial 9: Propositional Logic

Writing Logical Formula for a Truth Table

• Idea 1: Look at the true rows and take the OR.

• For each true row:• Construct a clause that is an AND of the true variables.

• Take the OR of all the clauses obtained from the for loop.

P Q fT T FT F TF T FF F T

𝑃∧ 𝑄

𝑃∧ 𝑄(𝑃∧ 𝑄 )∨( 𝑃∧ 𝑄)

Page 7: CSCI2110  Tutorial 9: Propositional Logic

Writing Logical Formula for a Truth Table

• Idea 2: Look at the false rows and take the AND.

• For each false row:• Construct a clause that is an AND of the true variables.

• Take the AND of all the negated clauses obtained from the for loop.

P Q fT T FT F TF T FF F T

(𝑃∧𝑄)

( 𝑃∧𝑄)~

Page 8: CSCI2110  Tutorial 9: Propositional Logic

Logical Equivalence• Two statements are logically equivalent if they have the

same truth table.

• e.g.

Page 9: CSCI2110  Tutorial 9: Propositional Logic

Tautology, Contradiction• A tautology is a statement that is always true.

• ,

• A contradiction is a statement that is always false.• ,

Page 10: CSCI2110  Tutorial 9: Propositional Logic

Summary of Basic Logical Rules

Commutative laws:

Associative laws:

Distributive laws:

Identity laws:

Negation laws:

Double negative law:

Idempotent laws:

Universal bound laws:

De Morgan’s laws:

Absorption laws:

= tautology, = contradiction

Page 11: CSCI2110  Tutorial 9: Propositional Logic

Simplifying Statements

(Distribution law)(Idempotent law)

(Identity law)

~(De Morgan’s law)

(Distributive law)(Idempotent law)

(Identity law)

Page 12: CSCI2110  Tutorial 9: Propositional Logic

Conditional StatementIf P then Q

p is called the hypothesis; q is called the conclusion

P implies Q

P QT T T

T F FF T TF F T

𝑃→𝑄

– Truth Table

Page 13: CSCI2110  Tutorial 9: Propositional Logic

Conditional Statement• is equivalent to .

• The contrapositive of “” is “”.

• (Statement) Every CUHK student has CULINK.• (Contrapositive) If someone doesn’t have CULINK, then

(s)he is not a CUHK student.

Important factA conditional statement is logically equivalent to its contrapositive.

Page 14: CSCI2110  Tutorial 9: Propositional Logic

Argument• An argument is a sequence of statements.

• All statements but the final one are called assumptions or hypothesis.

• The final statement is called the conclusion.

• An argument is valid if whenever all the assumptions are true, then

the conclusion is true.

If today is Sunday, then it is holiday. Today is Sunday. Today is holiday.

Page 15: CSCI2110  Tutorial 9: Propositional Logic

Valid Argument?

T T T T T T

T T F T F F

T F T F T T

T F F T T F

F T T T F T

F T F T F T

F F T T T T

F F F T T T

Invalid argument!

Page 16: CSCI2110  Tutorial 9: Propositional Logic

Valid Argument?

T T T T T

T T F T F

T F T F T

T F F F T

F T T T T

F T F T F

F F T T T

F F F T T

Valid argument!

Page 17: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves

Page 18: CSCI2110  Tutorial 9: Propositional Logic

Knights and KnavesSuppose you are visiting an island containing two types of people – knights and knaves.

Two natives and address you as follow:

: Both of us are knights.: is a knave.

What are and ?

Knights always tell the truth.Knaves always lie.

Page 19: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves: Both of us are knights.: is a knave.

Knights always tell the truth.Knaves always lie.

If is a knaveÞ is a knightÞ Both of them are knightsÞ In particular, is a knight Contradiction!

Therefore must be a knightÞ is a knave

Page 20: CSCI2110  Tutorial 9: Propositional Logic

Knights and KnavesAnother two natives and approach you but only speaks.

: Both of us are knaves.

What are and ?

Knights always tell the truth.Knaves always lie.

Page 21: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves

: Both of us are knaves.

Knights always tell the truth.Knaves always lie.

If is a knightÞ Both of them are knavesÞ In particular, is a knaveContradiction!

Therefore must be a knaveÞ One of them is a knightÞ is a knight

Page 22: CSCI2110  Tutorial 9: Propositional Logic

Knights and KnavesYou then encounter natives and .

: is a knave.: is a knave.

How many knaves are there?

Knights always tell the truth.Knaves always lie.

Page 23: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves: is a knave.: is a knave.

Knights always tell the truth.Knaves always lie.

If is a knightÞ is a knaveÞ is a knightÞ There is a knight and a knave

Similarly, if is a knightÞ is a knaveÞ is a knightÞ There is a knight and a knave

Page 24: CSCI2110  Tutorial 9: Propositional Logic

Knights and KnavesFinally, you meet a group of six natives, and , who speak to you as follow:

: None of us is a knight.: At least three of us are knights.: At most three of us are knights.: Exactly five of us are knights.: Exactly two of us are knights.: Exactly one of us is a knight.

Knights always tell the truth.Knaves always lie.

Which are knights and which are knaves?

Page 25: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves: None of us is a knight.: At least three of us are knights.: At most three of us are knights.: Exactly five of us are knights.: Exactly two of us are knights.: Exactly one of us is a knight.

Knights always tell the truth.Knaves always lie.

Suppose is a knightÞ None of them is a knightÞ is a knaveContradiction!

So can only be a knave.

Page 26: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves: None of us is a knight.: At least three of us are knights.: At most three of us are knights.: Exactly five of us are knights.: Exactly two of us are knights.: Exactly one of us is a knight.

Knights always tell the truth.Knaves always lie.

Suppose is a knightÞ Exactly five of them are knightsÞ are knights (because at this

stage we already know is a knave)

Þ In particular, is a knightÞ Exactly one of them is a knightContradiction!

So can only be a knave. What we know at this stage:• is a knave

Page 27: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves: None of us is a knight.: At least three of us are knights.: At most three of us are knights.: Exactly five of us are knights.: Exactly two of us are knights.: Exactly one of us is a knight.

Knights always tell the truth.Knaves always lie.

Suppose is a knightÞ At least three of them can be

knightsÞ At least three people among

are knightsÞ Either or must be a knight (by

pigeon-hole principle)Þ Exactly one(or two) of them is a

knightContradiction!

So can only be a knave.

What we know at this stage:• is a knave• is a knave

Page 28: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves: None of us is a knight.: At least three of us are knights.: At most three of us are knights.: Exactly five of us are knights.: Exactly two of us are knights.: Exactly one of us is a knight.

Knights always tell the truth.Knaves always lie.

At this stage we already identify three people as knavesÞ There can be at most three of

them are knightsÞ is a knight

What we know at this stage:• is a knave• is a knave• is a knave

Page 29: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves: None of us is a knight.: At least three of us are knights.: At most three of us are knights.: Exactly five of us are knights.: Exactly two of us are knights.: Exactly one of us is a knight.

Knights always tell the truth.Knaves always lie.

Suppose is a knightÞ Exactly one of them is a knightContradiction!(because both are knights in this case)

Therefore must be a knave.

What we know at this stage:• is a knave• is a knave• is a knight• is a knave

Page 30: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves: None of us is a knight.: At least three of us are knights.: At most three of us are knights.: Exactly five of us are knights.: Exactly two of us are knights.: Exactly one of us is a knight.

Knights always tell the truth.Knaves always lie.

Suppose is a knaveÞ is the only knightÞ There is exactly one knightÞ is a knightContradiction!

Therefore must be a knight.

What we know at this stage:• is a knave• is a knave• is a knight• is a knave• is a knave

Page 31: CSCI2110  Tutorial 9: Propositional Logic

Knights and Knaves: None of us is a knight.: At least three of us are knights.: At most three of us are knights.: Exactly five of us are knights.: Exactly two of us are knights.: Exactly one of us is a knight.

Knights always tell the truth.Knaves always lie.

Therefore:

• is a knave• is a knave• is a knight• is a knave• is a knight• is a knave

What we know at this stage:• is a knave• is a knave• is a knight• is a knave• is a knave

Page 32: CSCI2110  Tutorial 9: Propositional Logic

Summary• How to write logical formula from a truth table?

• How to check whether two logical formulas are equivalent?

• How to simplify logical formula using rules including (but not limited to) De Morgan’s law?

• What are conditional statements and contrapositive?

• How to check whether an argument is valid or not?

Page 33: CSCI2110  Tutorial 9: Propositional Logic

Thank You!