Predicates and Quantifiers CSAPMA 202 Spring 2005 Rosen

  • Slides: 41
Download presentation
Predicates and Quantifiers CS/APMA 202, Spring 2005 Rosen, section 1. 3 Aaron Bloomfield 1

Predicates and Quantifiers CS/APMA 202, Spring 2005 Rosen, section 1. 3 Aaron Bloomfield 1

Terminology review Proposition: a statement that is either true or false n n n

Terminology review Proposition: a statement that is either true or false n n n Must always be one or the other! Example: “The sky is red” Not a proposition: x + 3 > 4 Boolean variable: A variable (usually p, q, r, etc. ) that represents a proposition 2

Propositional functions Consider P(x) = x < 5 n n P(x) has no truth

Propositional functions Consider P(x) = x < 5 n n P(x) has no truth values (x is not given a value) P(1) is true The proposition 1<5 is true n P(10) is false The proposition 10<5 is false Thus, P(x) will create a proposition when given a value 3

Propositional functions 2 Let P(x) = “x is a multiple of 5” n For

Propositional functions 2 Let P(x) = “x is a multiple of 5” n For what values of x is P(x) true? Let P(x) = x+1 > x n For what values of x is P(x) true? Let P(x) = x + 3 n For what values of x is P(x) true? 4

Anatomy of a propositional function P(x) = x + 5 > x variable predicate

Anatomy of a propositional function P(x) = x + 5 > x variable predicate 5

Propositional functions 3 Functions with multiple variables: n P(x, y) = x + y

Propositional functions 3 Functions with multiple variables: n P(x, y) = x + y == 0 P(1, 2) is false, P(1, -1) is true n P(x, y, z) = x + y == z P(3, 4, 5) is false, P(1, 2, 3) is true n P(x 1, x 2, x 3 … xn) = … 6

So, why do we care about quantifiers? Many things (in this course and beyond)

So, why do we care about quantifiers? Many things (in this course and beyond) are specified using quantifiers n In some cases, it’s a more accurate way to describe things than Boolean propositions 8

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

Quantifiers A quantifier is “an operator that limits the variables of a proposition” Two types: n n Universal Existential 9

Universal quantifiers 1 Represented by an upside-down A: n n It means “for all”

Universal quantifiers 1 Represented by an upside-down A: n n It means “for all” Let P(x) = x+1 > x We can state the following: n n n x P(x) English translation: “for all values of x, P(x) is true” English translation: “for all values of x, x+1>x is true” 10

Universal quantifiers 2 But is that always true? n x P(x) Let x =

Universal quantifiers 2 But is that always true? n x P(x) Let x = the character ‘a’ n Is ‘a’+1 > ‘a’? Let x = the state of Virginia n Is Virginia+1 > Virginia? You need to specify your universe! n n What values x can represent Called the “domain” or “universe of discourse” by the textbook 11

Universal quantifiers 3 Let the universe be the real numbers. n Then, x P(x)

Universal quantifiers 3 Let the universe be the real numbers. n Then, x P(x) is true Let P(x) = x/2 < x n n Not true for the negative numbers! Thus, x P(x) 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 12

Universal quantification 4 Given some propositional function P(x) And values in the universe x

Universal quantification 4 Given some propositional function P(x) And values in the universe x 1. . xn The universal quantification x P(x) implies: P(x 1) P(x 2) … P(xn) 13

Universal quantification 5 Think of as a for loop: x P(x), where 1 ≤

Universal quantification 5 Think of as a for loop: x P(x), where 1 ≤ x ≤ 10 … can be translated as … for ( x = 1; x <= 10; x++ ) is P(x) true? If P(x) is true for all parts of the for loop, then x P(x) n Consequently, if P(x) is false for any one value of the for loop, then x P(x) is false 14

Quick survey n a) b) c) d) I understand universal quantification Very well With

Quick survey n a) b) c) d) I understand universal quantification Very well With some review, I’ll be good Not really Not at all 15

Chapter 2: Computer bugs 16

Chapter 2: Computer bugs 16

Existential quantification 1 Represented by an bacwards E: n n It means “there exists”

Existential quantification 1 Represented by an bacwards E: n n It means “there exists” Let P(x) = x+1 > x We can state the following: n n n x P(x) English translation: “there exists (a value of) x such that P(x) is true” English translation: “for at least one value of x, x+1>x is true” 17

Existential quantification 2 Note that you still have to specify your universe n If

Existential quantification 2 Note that you still have to specify your universe n If the universe we are talking about is all the states in the US, then x P(x) is not true Let P(x) = x+1 < x n n There is no numerical value x for which x+1<x Thus, x P(x) is false 18

Existential quantification 3 Let P(x) = x+1 > x n There is a numerical

Existential quantification 3 Let P(x) = x+1 > x n There is a numerical value for which x+1>x In fact, it’s true for all of the values of x! n Thus, x P(x) 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 19

Existential quantification 4 Given some propositional function P(x) And values in the universe x

Existential quantification 4 Given some propositional function P(x) And values in the universe x 1. . xn The existential quantification x P(x) implies: P(x 1) P(x 2) … P(xn) 20

Quick survey n a) b) c) d) I understand existential quantification Very well With

Quick survey n a) b) c) d) I understand existential quantification Very well With some review, I’ll be good Not really Not at all 21

A note on quantifiers Recall that P(x) is a propositional function n Let P(x)

A note on quantifiers Recall that P(x) is a propositional function n Let P(x) be “x == 0” Recall that a proposition is a statement that is either true or false n P(x) is not a proposition There are two ways to make a propositional function into a proposition: n Supply it with a value For example, P(5) is false, P(0) is true n Provide a quantifiaction For example, x P(x) is false and x P(x) is true n Let the universe of discourse be the real numbers 22

Binding variables Let P(x, y) be x > y Consider: x P(x, y) n

Binding variables Let P(x, y) be x > y Consider: x P(x, y) n n This is not a proposition! What is y? If it’s 5, then x P(x, y) is false If it’s x-1, then x P(x, y) is true Note that y is not “bound” by a quantifier 23

Binding variables 2 ( x P(x)) Q(x) n The x in Q(x) is not

Binding variables 2 ( x P(x)) Q(x) n The x in Q(x) is not bound; thus not a proposition ( x P(x)) ( x Q(x)) n Both x values are bound; thus it is a proposition ( x P(x) Q(x)) ( y R(y)) n All variables are bound; thus it is a proposition ( x P(x) Q(y)) ( y R(y)) n The y in Q(y) is not bound; this not a proposition 24

Negating quantifications Consider the statement: n All students in this class have red hair

Negating quantifications Consider the statement: n All students in this class have red hair What is required to show the statement is false? n There exists a student in this class that does NOT have red hair To negate a universal quantification: n n n You negate the propositional function AND you change to an existential quantification ¬ x P(x) = x ¬P(x) 25

Negating quantifications 2 Consider the statement: n There is a student in this class

Negating quantifications 2 Consider the statement: n There is a student in this class with red hair What is required to show the statement is false? n All students in this class do not have red hair Thus, to negate an existential quantification: n n n Tou negate the propositional function AND you change to a universal quantification ¬ x P(x) = x ¬P(x) 26

Quick survey n a) b) c) d) I understand about bound variables and negating

Quick survey n a) b) c) d) I understand about bound variables and negating quantifiers Very well With some review, I’ll be good Not really Not at all 27

Translating from English This is example 17, page 36 Consider “For every student in

Translating from English This is example 17, page 36 Consider “For every student in this class, that student has studied calculus” Rephrased: “For every student x in this class, x has studied calculus” n n Let C(x) be “x has studied calculus” Let S(x) be “x is a student” x C(x) n True if the universe of discourse is all students in this class 28

Translating from English 2 What about if the unvierse of discourse is all students

Translating from English 2 What about if the unvierse of discourse is all students (or all people? ) n x (S(x) C(x)) This is wrong! Why? n x (S(x)→C(x)) Another option: n n Let Q(x, y) be “x has stuided y” x (S(x)→Q(x, calculus)) 29

Translating from English 3 This is example 18, page 36 Consider: n n “Some

Translating from English 3 This is example 18, page 36 Consider: n n “Some students have visited Mexico” “Every student in this class has visited Canada or Mexico” Let: n n n S(x) be “x is a student in this class” M(x) be “x has visited Mexico” C(x) be “x has visited Canada” 30

Translating from English 4 Consider: “Some students have visited Mexico” n Rephrasing: “There exists

Translating from English 4 Consider: “Some students have visited Mexico” n Rephrasing: “There exists a student who has visited Mexico” x M(x) n True if the universe of discourse is all students What about if the unvierse of discourse is all people? n x (S(x) → M(x)) This is wrong! Why? n x (S(x) M(x)) 31

Translating from English 5 Consider: “Every student in this class has visited Canada or

Translating from English 5 Consider: “Every student in this class has visited Canada or Mexico” x (M(x) C(x) n When the universe of discourse is all students x (S(x)→(M(x) C(x)) n When the universe of discourse is all people Why isn’t x (S(x) (M(x) C(x))) correct? 32

Translating from English 6 Note that it would be easier to define V(x, y)

Translating from English 6 Note that it would be easier to define V(x, y) as “x has visited y” n n x (S(x) V(x, Mexico)) x (S(x)→(V(x, Mexico) V(x, Canada)) 33

Translating from English 7 Translate the statements: n n “All hummingbirds are richly colored”

Translating from English 7 Translate the statements: n n “All hummingbirds are richly colored” “No large birds live on honey” “Birds that do not live on honey are dull in color” “Hummingbirds are small” Assign our propositional functions n n Let P(x) be “x is a hummingbird” Let Q(x) be “x is large” Let R(x) be “x lives on honey” Let S(x) be “x is richly colored” Let our universe of discourse be all birds 34

Translating from English 8 Our propositional functions n n Let P(x) be “x is

Translating from English 8 Our propositional functions n n Let P(x) be “x is a hummingbird” Let Q(x) be “x is large” Let R(x) be “x lives on honey” Let S(x) be “x is richly colored” Translate the statements: n “All hummingbirds are richly colored” x (P(x)→S(x)) n “No large birds live on honey” ¬ x (Q(x) R(x)) Alternatively: x (¬Q(x) ¬R(x)) n “Birds that do not live on honey are dull in color” x (¬R(x) → ¬S(x)) n “Hummingbirds are small” x (P(x) → ¬Q(x)) 35

Quick survey n a) b) c) d) I understand how to translate between English

Quick survey n a) b) c) d) I understand how to translate between English and quantified statements Very well With some review, I’ll be good Not really Not at all 36

Today’s demotivators 37

Today’s demotivators 37

Prolog A programming language using logic! Entering facts: instructor (bloomfield, cs 202) enrolled (alice,

Prolog A programming language using logic! Entering facts: instructor (bloomfield, cs 202) enrolled (alice, cs 202) enrolled (bob, cs 202) enrolled (claire, cs 202) Entering predicates: teaches (P, S) : - instructor (P, C), enrolled (S, C) Extracting data ? enrolled (alice, cs 202) Result: yes 38

Prolog 2 Extracting data ? enrolled (X, cs 202) Result: alice bob claire Extracting

Prolog 2 Extracting data ? enrolled (X, cs 202) Result: alice bob claire Extracting data ? teaches (X, alice) Result: bloomfield 39

Quick survey n a) b) c) d) I felt I understood the material in

Quick survey n a) b) c) d) I felt I understood the material in this slide set… Very well With some review, I’ll be good Not really Not at all 40

Quick survey n a) b) c) d) The pace of the lecture for this

Quick survey n a) b) c) d) The pace of the lecture for this slide set was… Fast About right A little slow Too slow 41

Quick survey n a) b) c) d) How interesting was the material in this

Quick survey n a) b) c) d) How interesting was the material in this slide set? Be honest! Wow! That was SOOOOOO cool! Somewhat interesting Rather borting Zzzzzz 42