05 Predicates Quantifiers
05 Predicates Quantifiers
1
Terminology review
• Proposition: a statement that is either true
or false
– Must always be one or the other!
– Example: “The sky is red”
– Not a proposition: x + 3 > 4
2
Propositional functions
• Consider P(x) = x < 5
– P(x) has no truth values (x is not given a
value)
– P(1) is true
• The proposition 1<5 is true
– 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”
– For what values of x is P(x) true?
• Let P(x) = x + 3
– For what values of x is P(x) true?
4
Anatomy of a propositional function
P(x) = x + 5 > x
variable predicate
5
Propositional functions 3
• Functions with multiple variables:
– P(x,y) = x + y == 0
• P(1,2) is false, P(1,-1) is true
– P(x,y,z) = x + y == z
• P(3,4,5) is false, P(1,2,3) is true
– P(x1,x2,x3 … xn) = …
6
So, why do we care about
quantifiers?
• Many things (in this course and beyond)
are specified using quantifiers
– In some cases, it’s a more accurate way to
describe things than Boolean propositions
7
Quantifiers
• A quantifier is “an operator that limits the
variables of a proposition”
• Two types:
– Universal
– Existential
8
Universal quantifiers 1
• Represented by an upside-down A:
– It means “for all”
– Let P(x) = x+1 > x
• x P(x), where 1 ≤ x ≤ 10
• … can be translated as …
• If P(x) is true for all parts of the for loop, then x P(x)
– Consequently, if P(x) is false for any one value of the for loop,
then x P(x) is false
13
Existential quantification 1
• Represented by an bacwards E:
– It means “there exists”
– Let P(x) = x+1 > x
15
Existential quantification 3
• Let P(x) = x+1 > x
– There is a numerical value for which x+1>x
• In fact, it’s true for all of the values of x!
– Thus, x P(x) is true
16
Existential quantification 4
• Given some propositional function P(x)
20
Binding variables 2
• (x P(x)) Q(x)
– The x in Q(x) is not bound; thus not a proposition
• (x P(x)) (x Q(x))
– Both x values are bound; thus it is a proposition
• (x P(x) Q(x)) (y R(y))
– All variables are bound; thus it is a proposition
• (x P(x) Q(y)) (y R(y))
– The y in Q(y) is not bound; this not a proposition
21
Negating quantifications
• Consider the statement:
– All students in this class have red hair
• What is required to show the statement is false?
– There exists a student in this class that does NOT
have red hair
• To negate a universal quantification:
– You negate the propositional function
– AND you change to an existential quantification
– ¬x P(x) = x ¬P(x)
22
Negating quantifications 2
• Consider the statement:
– There is a student in this class with red hair
• What is required to show the statement is
false?
– All students in this class do not have red hair
• Thus, to negate an existential quantification:
– Tou negate the propositional function
– AND you change to a universal quantification
– ¬x P(x) = x ¬P(x)
23
Translating from English
• Consider “For every student in this class,
that student has studied calculus”
• Rephrased: “For every student x in this
class, x has studied calculus”
– Let C(x) be “x has studied calculus”
– Let S(x) be “x is a student”
• x C(x)
– True if the universe of discourse is all
students in this class
24
Translating from English 2
• What about if the unvierse of discourse is
all students (or all people?)
– x (S(x)C(x))
• This is wrong! Why?
– x (S(x)→C(x))
• Another option:
– Let Q(x,y) be “x has stuided y”
– x (S(x)→Q(x, calculus))
25
Translating from English 3
• Consider:
– “Some students have visited Mexico”
– “Every student in this class has visited
Canada or Mexico”
• Let:
– S(x) be “x is a student in this class”
– M(x) be “x has visited Mexico”
– C(x) be “x has visited Canada”
26
Translating from English 4
• Consider: “Some students have visited Mexico”
– Rephrasing: “There exists a student who has visited
Mexico”
• x M(x)
– True if the universe of discourse is all students
• What about if the universe of discourse is all
people?
– x (S(x) → M(x))
• This is wrong! Why?
– x (S(x) M(x))
27
Translating from English 5
• Consider: “Every student in this class has
visited Canada or Mexico”
• x (M(x)C(x)
– When the universe of discourse is all students
• x (S(x)→(M(x)C(x))
– When the universe of discourse is all people
• Why isn’t x (S(x)(M(x)C(x))) correct?
28
Translating from English 6
• Note that it would be easier to define
V(x, y) as “x has visited y”
– x (S(x) V(x,Mexico))
– x (S(x)→(V(x,Mexico) V(x,Canada))
29
Translating from English 7
• Translate the statements:
– “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
– 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
30
Translating from English 8
• Our propositional functions
– 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:
– “All hummingbirds are richly colored”
• x (P(x)→S(x))
– “No large birds live on honey”
• ¬x (Q(x) R(x))
• Alternatively: x (¬Q(x) ¬R(x))
– “Birds that do not live on honey are dull in color”
• x (¬R(x) → ¬S(x))
– “Hummingbirds are small”
• x (P(x) → ¬Q(x)) 31
Prolog
• A programming language using logic!
• Entering facts:
instructor (bloomfield, cs202)
enrolled (alice, cs202)
enrolled (bob, cs202)
enrolled (claire, cs202)
• Entering predicates:
teaches (P,S) :- instructor (P,C), enrolled (S,C)
• Extracting data
?enrolled (alice, cs202)
• Result:
yes
32
Prolog 2
• Extracting data
?enrolled (X, cs202)
• Result:
alice
bob
claire
• Extracting data
?teaches (X, alice)
• Result:
bloomfield
33
Multiple quantifiers
• You can have multiple quantifiers on a statement
• xy P(x, y)
– “For all x, there exists a y such that P(x,y)”
– Example: xy (x+y == 0)
• xy P(x,y)
– There exists an x such that for all y P(x,y) is true”
– Example: xy (x*y == 0)
34
Order of quantifiers
• xy and xy are not equivalent!
• xy P(x,y)
– P(x,y) = (x+y == 0) is false
• xy P(x,y)
– P(x,y) = (x+y == 0) is true
35
Negating multiple quantifiers
• Recall negation rules for single quantifiers:
– ¬x P(x) = x ¬P(x)
– ¬x P(x) = x ¬P(x)
– Essentially, you change the quantifier(s), and negate
what it’s quantifying
• Examples:
– ¬(xy P(x,y))
= x ¬y P(x,y)
= xy ¬P(x,y)
– ¬(xyz P(x,y,z))
= x¬yz P(x,y,z)
= xy¬z P(x,y,z)
= xyz ¬P(x,y,z) 36
Negating multiple quantifiers 2
• Consider ¬(xy P(x,y)) = xy ¬P(x,y)
– The left side is saying “for all x, there exists a y such
that P is true”
– To disprove it (negate it), you need to show that “there
exists an x such that for all y, P is false”
42
Rules of inference for the
universal quantifier
• Assume that we know that x P(x) is true
– Then we can conclude that P(c) is true
• Here c stands for some specific constant
– This is called “universal instantiation”
45
Example of proof
1. x (R(x)→T(x)) 3rd hypothesis
2. R(Linda) → T(Linda) Universal instantiation using step 1
3. R(Linda) 2nd hypothesis
4. T(Linda) Modes ponens using steps 2 & 3
5. C(Linda) 1st hypothesis
6. C(Linda) T(Linda) Conjunction using steps 4 & 5
7. x (C(x)T(x)) Existential generalization using
step 6