discrete structures predicate logic 1 dr. muhammad humayoun assistant professor comsats institute of...

46
Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. [email protected] https://sites.google.com/a/ciitlahore.edu.p k/dstruct/ 1

Upload: aileen-ray

Post on 21-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

1

Discrete StructuresPredicate Logic 1

Dr. Muhammad HumayounAssistant Professor

COMSATS Institute of Computer Science, [email protected]

https://sites.google.com/a/ciitlahore.edu.pk/dstruct/

Page 2: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

2

Why Predicate Logic?• Propositional Logic is not expressive enough– It cannot adequately express the meaning of

statements in mathematics and in natural languageExample 1: “Every computer connected to the university network is functioning properly.”• No rules of propositional logic allow us to conclude the

truth of the statement that:• “The computer MATH3 is functioning properly.”

Page 3: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

3

Why Predicate Logic?

Example 2: • “There is a computer on the university network that

is under attack by an intruder.”• "CS2 is under attack by an intruder"

Predicate Logic is more expressive and powerful

Page 4: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

4

Predicate LogicProposition, YES or NO?

• 3 + 2 = 5

• X + 2 = 5

• Computer X is under attack by an intruder

• X + 2 = 5 for any choice of X in {1, 2, 3}

• X + 2 = 5 for some X in {1, 2, 3}

• Computer X is under attack by an intruder for some X

in {CS001, MATH034}

Page 5: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

5

Predicate LogicProposition, YES or NO?

• 3 + 2 = 5 YES

• X + 2 = 5 NO

• Computer X is under attack by an intruder NO

• X + 2 = 5 for any choice of X in {1, 2, 3} YES

• X + 2 = 5 for some X in {1, 2, 3} YES

• Computer X is under attack by an intruder for some X

in {CS001, MATH034} YES

Page 6: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

6

Propositional Functions

• Consider – has no truth values ( is not given a value)– is true: The proposition is true– is false: The proposition is false

• will create a proposition when given a valueExercise:1) Let “x is a multiple of 5”

For what values of is true?2)Let

For what values of is true?

Page 7: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

7

Propositional Functions

• Functions with multiple variables:

• is false, is true

• is false, is true

• Anatomy of a propositional function

variable predicate

function

Page 8: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

8

Predicates

• A predicate is a declarative statement with at least one variable (i.e., unknown value).

• A predicate, or propositional function, is a function that takes some variable(s) as arguments and returns True or False.

• Fiaz eats pizza at least once a week.• Define:– P(x) = “x eats pizza at least once a week.”– Note that P(x) is not a proposition, P(Fiaz) is.

Page 9: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

9

Predicates

• Suppose

Proposition, YES or NO? Predicate, YES or NO?

Page 10: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

10

Predicates

• Suppose

Proposition, YES or NO?• NO• YES• NO

Predicate, YES or NO?• YES• NO• YES

Page 11: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

11

Quantification

• Quantification expresses the extent to which a predicate is true over a range of elements.

• In English, the words all, some, many, none, and few are used in quantifications.

• The area of logic that deals with predicates and quantifiers is called the predicate calculus.

Page 12: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

12

Quantifiers

• A quantifier is “an operator that limits the variables of a proposition”

• Two types:–Universal– Existential

Page 13: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

13

Universal quantifierRepresented by an upside-down A: It means “for all”• Let • We can state that: • English translation: – “”

• or English translation:

Besides "for all“, universal quantification can be expressed in many other ways: “for every”, “all of”, “for each”, “given any”, “for arbitrary”, “for each” and “for any”

Page 14: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

14

Universal quantifier• But is that always true?

• Let – Is ?

• Let – Is ?

• You need to specify the universe of quantification!– What values can represent– Called the “domain of discourse” or “universe of

discourse”– Or just “domain” or “universe”

Page 15: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

15

Universal quantifier• Let the universe be the real numbers.• Let – Not true for the negative numbers!– Thus, is false, when the domain is all the real numbers

• In order to prove that a universal quantification is true, it must be shown for ALL cases

• In order to prove that a universal quantification is false, it must be shown to be false for only ONE case

Page 16: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

16

Universal quantifier• Given some propositional function and values in

the universe

• The universal quantification implies:

Page 17: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

17

Quiz

• What is the truth value of , where is the statement and the domain consists of the positive integers not exceeding 4?

Page 18: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

18

Quiz

• What is the truth value of , where is the statement and the domain consists of the positive integers not exceeding 4?

• The statement is the same as the conjunction,

• Because , is false, it follows that is false.

Page 19: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

19

Quiz: Meaning in English

• Let “Computer x is connected to the network”

• Domain: All computers on campus• What does the statement mean in English?

Page 20: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

20

Quiz: Meaning in English

• Let “Computer x is connected to the network”

• Domain: All computers on campus• What does the statement mean in English?

"Every computer on campus is connected to the network."

Page 21: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

21

Example

“x is wearing sneakers.” “x is at least 17 years old.” “x is less than 24 years old.” Universe of discourse: students in this room

Are either of these propositions true?

Page 22: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

22

Example“x is wearing sneakers.” “x is at least 17 years old.” “x is less than 24 years old.” Universe of discourse: students in this room

Are either of these propositions true?

•– For all x, if x < 24 years old, then x is wearing sneakers.– For all people in this room, those who are less than 24

years old are wearing sneakers.

Page 23: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

23

Example“x is wearing sneakers.” “x is at least 17 years old.” “x is less than 24 years old.” Universe of discourse: students in this room

– For all x, x is less than 24 years old or x is at least 17 years old.

– For all people in this room, they are less than 24 or at least 17 years old.

Page 24: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

24

Existential quantification • Represented by an backwards E: – It means “there exists”, “there is”, “for some”, etc.

• Let • We can state the following:

•– English translation: • “there exists (a value of) such that ”

– English translation: • “for at least one value of ”

– English translation: • “”

Page 25: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

25

Existential quantification • Suppose is a predicate on some universe of

discourse.• The existential quantifier of is the proposition:– “ is true for some in the universe of discourse.”– is TRUE if there is an for which is true.– is FALSE if is false for every single .

• Ex. “x has a red pen” • Domain of discourse: is set of CSC102 students.

Page 26: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

26

Existential quantification

Let There is no numerical value x for which Thus, is false

Note that you still have to specify your universe

Page 27: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

27

Existential quantification • Let • There is a numerical value for which • In fact, it’s true for all of the values of • Thus, is true

• In order to show an existential quantification is true, you only have to find ONE value

• In order to show an existential quantification is false, you have to show it’s false for ALL values

Page 28: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

28

Existential quantification

• Given some propositional functionAnd values in the universe

• The existential quantification implies:

Page 29: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

29

Example“x is wearing sneakers.”“x is at least 20 years old.” “x is less than 24 years old.”Universe of discourse is people in this room

Are either of these propositions true?

•– There exists an x such that x is wearing sneakers.

– There is an x such that x is less than 24 years old and x is at least 21 years old.

Page 30: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

30

Example“x is wearing sneakers.”“x is at least 20 years old.” “x is less than 24 years old.”Universe of discourse is people in this room

Are either of these propositions true?

•– There exists an x such that x is wearing sneakers.

– There is an x such that x is less than 24 years old and x is at least 20 years old.

Page 31: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

31

Examples

“x is a lion.” “x is fierce.” “x drinks coffee.”Universe of discourse is all creatures

All lions are fierce.

Page 32: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

32

Examples

“x is a lion.” “x is fierce.” “x drinks coffee.”Universe of discourse is all creatures

All lions are fierce. [For all x, if x is a lion then x is fierce]

Page 33: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

33

Examples

“x is a lion.” “x is fierce.” “x drinks coffee.”Universe of discourse is all creatures

All lions are fierce. [For all x, if x is a lion then x is fierce]

Page 34: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

34

Examples

“x is a lion.” “x is fierce.” “x drinks coffee.”Universe of discourse is all creatures

All lions are fierce. [For all x, if x is a lion then x is fierce]

• Caution! Our statement cannot be expressed with conjunction instead; because:

• statement says that “all creatures are lion and they are fierce”

Page 35: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

35

Examples

“x is a lion.” “x is fierce.” “x drinks coffee.”Universe of discourse is all creatures

Some lions don’t drink coffee.

Page 36: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

36

Examples

“x is a lion.” “x is fierce.” “x drinks coffee.”Universe of discourse is all creatures

Some lions don’t drink coffee.

[There is an x such that x is a lion and x does not drink coffee]

Page 37: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

37

Examples

“x is a lion.” “x is fierce.” “x drinks coffee.”Universe of discourse is all creatures

Some fierce creatures don’t drink coffee.

Page 38: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

38

Examples

“x is a lion.” “x is fierce.” “x drinks coffee.”Universe of discourse is all creatures

Some fierce creatures don’t drink coffee.[There exists an x such that x is fierce and x does not drink

coffee]

Page 39: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

39

B(x) = “x is a hummingbird.”L(x) = “x is a large bird.”H(x) = “x lives on honey.”R(x) = “x is richly colored.”Universe of discourse is all creatures.

All hummingbirds are richly colored.

Page 40: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

40

B(x) = “x is a hummingbird.”L(x) = “x is a large bird.”H(x) = “x lives on honey.”R(x) = “x is richly colored.”Universe of discourse is all creatures.

All hummingbirds are richly colored.

Page 41: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

41

B(x) = “x is a hummingbird.”L(x) = “x is a large bird.”H(x) = “x lives on honey.”R(x) = “x is richly colored.”Universe of discourse is all creatures.

No large birds live on honey.

Page 42: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

42

B(x) = “x is a hummingbird.”L(x) = “x is a large bird.”H(x) = “x lives on honey.”R(x) = “x is richly colored.”Universe of discourse is all creatures.

No large birds live on honey.

Page 43: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

43

B(x) = “x is a hummingbird.”L(x) = “x is a large bird.”H(x) = “x lives on honey.”R(x) = “x is richly colored.”Universe of discourse is all creatures.

No large birds live on honey.

All birds that are large do not live on honey

Page 44: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

44

B(x) = “x is a hummingbird.”L(x) = “x is a large bird.”H(x) = “x lives on honey.”R(x) = “x is richly colored.”Universe of discourse is all creatures.

Birds that do not live on honey are dully colored.

Page 45: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

45

B(x) = “x is a hummingbird.”L(x) = “x is a large bird.”H(x) = “x lives on honey.”R(x) = “x is richly colored.”Universe of discourse is all creatures.

Birds that do not live on honey are dully colored.

Page 46: Discrete Structures Predicate Logic 1 Dr. Muhammad Humayoun Assistant Professor COMSATS Institute of Computer Science, Lahore. mhumayoun@ciitlahore.edu.pk

46

Do Exercises