Predicates and Quantifiers
Predicates and Quantifiers
E. Zimudzi
Department of Computer Science
University of Botswana
21 August, 2023
1 / 37
OUTLINE
1. PREDICATE LOGIC
2. QUANTIFIERS
3. NEGATING AND TRANSLATING WITH QUANTIFIERS
4. NESTED QUANTIFIERS AND NEGATIONS
5. TRANSLATING WITH NESTED QUANTIFIERS
6. LOGIC PROGRAMMING
2 / 37
Propositional logic cannot adequately express the meaning of all statements in mathematics
and in natural language.
Predicate - a proposition that depends on the value of some variables.
For example,
• “x is prime” will be true or false depending on the value of x.
• “x is greater than 3”
• “x = y + 3”
• “Computer x is under attack by an intruder”.
3 / 37
The Propositional Function
• “x is greater than 3”, has 2 parts, (1) the variable x of the statement, and (2) the
predicate “is greater than 3”, a property of the statement.
• We can denote the statement “x is greater than 3” by P (x), where P denotes the
predicate “is greater than 3” and x is the variable.
• P (x) is the value of the propositional function P at x. When a value is assigned x,
P (x) becomes a proposition with a truth value.
4 / 37
Examples:
1. Let P (x) be the statement x > 3. What are the truth values for P (4) and P (2)?
3. Let A(y) denote the statement: ”External disk y is infected by a virus”. Suppose that
there are only two external disks, Sahara and Kingston and that none of the disks is
infected by a virus. What are the truth values of A(Kingston) and A(Sahara)?
• A(Kingston) is the statement: External disk Kingston is infected by a virus, which is false.
• A(Sahara) is the statement: External disk Sahara is infected by a virus which is also false.
5 / 37
Predicate Calculus
- the area of logic that deals with predicates and quantifiers. Two ways to form propositions
from predicates:
• Assigning values to parameters: - seen already.
• by quantification: Universal and Existential quantification.
6 / 37
Quantifiers
Now we are going to turn a propositional function into a proposition using a quantifier.
Two most widely-used quantifiers:
• “FOR ALL” ∀ UNIVERSAL QUANTIFIER.
• “THERE EXISTS” ∃ EXISTENTIAL QUANTIFIER.
e.g. ∀xP (x) means for all x, P (x) is true.
e.g. ∃xP (x) means there exists some x, such that P (x) is true.
7 / 37
The Quantifiers
Universal ∀ Existential ∃
“For ALL” “THERE EXISTS”
When When P (x) is true for every x in the There is an x in the domain for which
True? domain. P (x) is true.
When There is an x in the domain for which When P (x) is false for every x in the
False? P (x) is false. domain.
∀xP (x) ≡ P (x1 )∧P (x2 )∧...∧P (xn ) ∃xP (x) ≡ P (x1 )∨P (x2 )∨...∨P (xn )
8 / 37
The Universal Quantifier ∀
The statement ∀xP (x) tells us that the proposition P (x) must be true for all values of x in
the Domain of Discourse/Universe.
Let P (x) represent “x > 0”. Find each truth value for ∀xP (x):
• U is Z.
• U is Z+ .
9 / 37
The Existential Quantifier ∃
The statement ∃xP (x) tells us that the proposition P (x) is true for some values of x in the
Domain of Discourse/Universe.
Let P (x) represent “x > 0”. Find each truth value for ∃xP (x):
• U is Z.
• U is Z− .
10 / 37
Examples:
1. Let P (x) be “x2 > 0” if the domain consists of all integers. Find the truth values of:
• ∀xP (x) 0 ∈ Z, and 02 > 0 is FALSE. Therefore, ∀xP (x) is False.
• ∃xP (x) 1 ∈ Z, and 12 > 0 is TRUE. Therefore, ∃xP (x) is True.
2. Let P (x) be “x2 < 0”if the domain consists of all integers. Find the truth values of:
• ∀xP (x) FALSE. (−2)2 < 0. Therefore, ∀xP (x) is False.
• ∃xP (x) FALSE. Therefore, ∀xP (x) is False.
11 / 37
Practice:
1. Let P (x) be “x + 1 = 2x” if the domain consists of all integers. Find the truth values of:
• ∀xP (x) FALSE. Counterexample 4 + 1 ̸= 2.4. Therefore, ∀xP (x) is False.
• ∃xP (x) True.
2. Let P (x) be “x2 < 16”if the domain consists of all integers. Find the truth values of:
• ∀xP (x) FALSE. Counterexample (5)2 ≮ 0. Therefore, ∀xP (x) is False.
• ∃xP (x) TRUE for −4 < x < 4. Therefore, ∀xP (x) is True.
12 / 37
The Uniqueness Quantifier
The statement, ∃!xP (x) tells us that the proposition P (x) is true for exactly one value of x in
the domain of discourse/universe.
Give the truth value for ∃!xP (x) for each proposition in the domain of all integers.
• P (x) represents “2x = 4” TRUE
• P (x) represents “2x > 4” FALSE
• P (x) represents “2x = 3” FALSE, 1.5 ∈
/Z
13 / 37
Precedence of Quantifiers
The quantifiers ∀ and ∃ have higher precedence than all logical operators from propositional
calculus.
e.g. for ∀xP (x) ∨ A(y) we find the truth value of ∀xP (x), then find the truth value of A(y)
and finally apply the ∨ to the two results.
14 / 37
Quantifiers with Restricted Domains
This allows for values of a parameter to be restricted. The condition is specified immediately
after the parameter. e.g.
1. ∀x < 0(x2 > 0): Note that the value of x is restricted to < 0, This statement says: “for
every real number x that is less than 0, x2 > 0. This is equivalent to:
∀x(x < 0 → x2 > 0). NB this is the same as the universal quantification of an
implication.
2. ∃y > 0(y 2 = 9): note that y is also restricted. The statement means: “there exists a real
number y that is greater than 0 such that y 2 = 9.” This is equivalent to:
∃y(y > 0 ∧ y 2 = 9). Note that this is equivalent to the existential quantification of a
conjunction
15 / 37
Binding Variables
When a quantifier is used on the variable x, we say that this occurrence of the variable is
bound, otherwise it is free.
In ∃x(x + y = 1), x is bound by the existential quantification ∃x, but y is free.
16 / 37
NEGATING AND TRANSLATING WITH QUANTIFIERS
Let P (x) be the statement: “x has taken a course in programming” for the domain of
students in your class.
Negating Quantifiers
Quantifier Statement Equivalent to
¬∀xP (x) There is a student in my class who has ∃x¬P (x)
not taken a course in programming.
¬∃xP (x) All students in my class have not taken ∀x¬P (x)
a course in programming.
17 / 37
De Morgan’s Laws for Quantifiers
18 / 37
Negate the Statements
1. There is an honest politician.
• H(x) represents “x is honest” for the domain of politicians.
∃xH(x)
¬∃xH(x) ≡ ∀x¬H(x)
• Every politician is dishonest, or All politicians are not honest.
2. All Africans eat chicken.
• C(x) represents “x eats chicken” for the domain of all Africans.
∀xC(x)
¬∀xC(x) ≡ ∃x¬C(x)
• Not every African eats chicken.
19 / 37
Translate statements: Domain
Some student in this class has visited Namibia.
1. Domain: Students in class.
• M (x) represents “x has visited Namibia”.
∃xM (x)
2. All people.
• M (x) represents “x has visited Namibia’
• C(x) represents “x is a student in this class”
∃x(M (x) ∧ C(x))
20 / 37
Nested Quantifiers and Negations
Definition:
Nested quantifier Two quantifiers are nested if one is within the scope of the other. e.g.
∀x∃y(x + y = 0) “Every real number has an additive inverse.”
∀x∃y(x + y = 0) is the same as ∀xQ(x), where Q(x) is ∃yP (x, y), where P (x, y) is x + y = 0.
Let P (x) denote “xy = yx”. Assume the domain is real numbers.
1. Is ∀x∀yP (x, y) true? TRUE “For all real number x, and for all real numbers y, xy = yx.
2. Is ∀y∀xP (x, y) true? TRUE
21 / 37
22 / 37
Practice
Let Q(x) denote “x + y = 5”. Assume the domain is real numbers.
1. Is ∀x∃yQ(x, y) true? “For all real number x, there exists a real number y, such that
x + y = 5. TRUE
2. Is ∃y∀xQ(x, y) true? “There exists a real number y such that for all real number x,
x + y = 5. FALSE
23 / 37
Practice
Let U be real numbers, and P (x, y) denote “x.y = 0”. Find the truth values for the following:
1. Is ∀x∀yP (x, y) true? FALSE
2. Is ∀x∃yP (x, y) true? TRUE
3. Is ∃x∀yP (x, y) true? TRUE
4. Is ∃x∃yP (x, y) true? TRUE
24 / 37
Practice
Let U be real numbers, and P (x, y) denote “x/y = 1”. Find the truth values for the following:
1. Is ∀x∀yP (x, y) true? FALSE
2. Is ∀x∃yP (x, y) true? FALSE “False because if x is 0, it doesn’t work.”
3. Is ∃x∀yP (x, y) true? FALSE
4. Is ∃x∃yP (x, y) true? TRUE
25 / 37
Translating with Nested Quantifiers
Translate “The sum of two positive integers is always positive” into a logical expression.
3. Let P (x) denote (x + y > 0), we can replace (x + y > 0) with P (x) in 1. and/or 2.
above.
26 / 37
Translating with Nested Quantifiers
Translate into statements involving nested quantifiers “Every real number except zero
has a multiplicative inverse” into a logical expression. A multiplicative inverse of a real
number x is a real number y such that xy = 1.
27 / 37
Translating from Nested Quantifiers into English
Solution
The statement says that for every student x in your school, x has a computer or there is a
student y such that y has a computer and x and y are friends. In other words, every student in
your school has a computer or has a friend who has a computer.
28 / 37
Translating English Sentences into Logical Expressions
Express the statement “If a person is female and is a parent, then this person is someone’s
mother” as a logical expression involving predicates, quantifiers with a domain consisting of all
people, and logical connectives.
Solution
The statement can be expressed as “For every person x, if person x is female and person x is
a parent, then there exists a person y such that person x is the mother of person y.” We
introduce the propositional functions F (x) to represent “x is female,” P (x) to represent “x is
a parent,” and M (x, y) to represent “x is the mother of y.” The original statement can be
represented as:
∀x((F (x) ∧ P (x)) → ∃yM (x, y))
which is the same as
∀x∃y((F (x) ∧ P (x)) → M (x, y))
29 / 37
The Negating Nested Quantifiers
Let P (x, y) denote “x = −y”. Find the negation of ∀x∃yP (x, y)
No negation to precede a quantifier
Therefore, the negation is “There exists a real number x, such that for all real numbers y,
x ̸= −y.”
30 / 37
Express the Negation of the Statement
Solution
By successively applying De Morgan’s laws for quantifiers, we can move the negation in
¬∀x∃y(xy = 1) inside the qualifiers.
Because ¬(xy = 1) can be expressed more simply as xy ̸= 1, we conclude that our negated
statement can be expressed as ∃x∀y(xy ̸= 1).”
31 / 37
Logic Programming
• Prolog - Programming with Logic: is a programming language designed to reason
using rules of predicate logic.
• It has two types of statements: Prolog Facts and Prolog Rules.
• Prolog facts define predicates.
• Prolog rules define new predicates using those already defined using Prolog facts.
32 / 37
Prolog program given facts about:
• instructors of each course. This is represented by the predicate: instructor(p,c) - to
represent that professor p is the instructor for course c.
• which classes students are enrolled. This is represented by the predicate: enrolled(s,c) - to
represent that student s is enrolled in course c.
33 / 37
Example:
• Study the Prolog Facts in a program given below
• instructor(chan, math273)
• instructor(patel, ee222)
• instructor(groosman, cs301)
• enrolled(kevin, math273)
• enrolled(juan, ee222)
• enrolled(juan, cs301)
• enrolled(kiko, math273)
• enrolled(kiko, cs301)
• Use lowercase for entries as Prolog considers names beginning with uppercase to be
variables.
34 / 37
• We can define a new predicate, teaches(p,s) to represent that professor p teaches student
s.
• This can be defined using the Prolog rule:
• teaches(P, S) :- instructor(P,C), enrolled(S, C)
• This means: teaches(p,s) is true if there is a class c such that professor p is instructor of
class c and student s is enrolled in class c.
• The comma represent ∧ and for ∨ its ; in Prolog.
35 / 37
• Prolog answers queries using rules and facts given.
• The query: ?enrolled(kevin, math273) evaluates to yes due to the fact given earlier.
• The query: ?enrolled(X, math273) produces kevin, kiko. Prolog determines all possible
values of X for which enrolled(X, math273) has been included as a Prolog fact.
• The query: ?teaches(X,juan) establishes professors who are instructors to courses being
taken by juan. It will produce: patel, grossman.
36 / 37
The End
37 / 37