1.2. Predicate Logic - Discrete Structures For Computing
1.2. Predicate Logic - Discrete Structures For Computing
Contents
• 1.2.1. Predicates and Variables
• 1.2.2. Quantifiers
• 1.2.3. Nested Quantifiers
• 1.2.4. Possible Pitfalls
• 1.2.5. Exercises
It is often the case that propositional logic is insufficient to represent more complex logical
expressions. Enter predicate logic.
p := “All men are mortal” and q := “Socrates is a man”. Is Socrates a mortal? The answer
is yes, but this cannot be expressed in propositional logic.
We need a way to formalize objects, their properties, and relations between them.
Definition (predicate)
A symbol which represents a property or relation. Often, the statement or relation itself is
called a predicate.
Predicates are typically capital letters P , Q, R, S, …. Predicates are very much like propositional
variables in that they stand in for something. Predicates are more general in that they need not have
a truth value. Moreover, whereas propositions needed to be a declarative statement (i.e. an
independent clause in a sentence), predicates can be an incomplete phrase.
• D := “is a dog”
Notice from these examples that predicates typically lack subjects. Combining predicates with
variables allows us to form propositional functions.
Propositional functions become propositions when their variables are replaced by a value in the
domain of discourse, often called simply domain. This domain specifies what are the possible values
for the variable. A domain is often denoted by U .
Without a domain, a propositional function makes little sense. If P (x) stands for “x passed
CS2214”, this only makes sense if the domain for x is “people who have taken CS2214”.
Propositional function
Let P be “is greater than 0”. Then, P (x) is a propositional function denoting “x is greater
than 0”. If we let the domain be the integers, x may take the value of any integer.
• P (−3) is false.
• P (0) is false.
• P (2) is true.
When we replace (i.e. substitute) a particular value from the domain of discourse for a variable in a
propositional function, we say that the variable is bound. We call it a bound variable. In contrast, a
variable that is not bound is called a free variable.
Checkpoint Solution
1. R(2, −1, 5)
2. R(3, 4, 7)
3. R(x, 3, z)
4. Q(2, −1, 3)
5. Q(3, 4, 7)
6. Q(x, 3, z)
Compound Expressions
All of the logical connectives of propositional logic also apply to predicate logic. Let’s see some
examples.
Connecting predicates
Let P (x) := x can fly. Let Q(x) := x are blue. Let the domain of x be all species of
animals.
We can also use logical connectives to connect propositional functions. The result is another
propositional function with possibly more variables.
1.2.2. Quantifiers
Quantifiers are used as modifiers to variables, giving rise to the logical formalization of the English
words “all”, “some”, “any”, “every”, etc. For example, “all men are mortal” or “some birds cannot fly”
cannot be expressed in propositional logic but can be represented in predicate logic using
quantifiers. The two main quantifiers are the universal quantifier and the existential quantifier.
“For all”, “For any”, “Given any”. A universal quantifier asserts that a predicate is true for
any and every value in the domain. It is denoted ∀.
“There exists”, “For some”, “There is a”, “There is at least one”. An existential quantifier
asserts that a predicate is true for at least one value in the domain. It is denoted ∃.
Just as substituting a variable for a value from the domain binds the variable, a quantifier also binds
a variable. Let P be a predicate and U be the domain. ∀xP (x) says that P (x) is true for every
choice of x from the domain. ∃xP (x) says that P (x) is true for some x in the domain.
Existential quantifier
Notice that the truth value of a propositional function whose variable is bound by a quantifier
depends on the particular domain of discourse.
Important
Checkpoint Solution
1. If U is the positive integers, what is the truth value of ∀ x P (x)? What is the truth value of
∃ x P (x)?
2. If U is the negative integers, what is the truth value of ∀ x P (x)? What is the truth value of
∃ x P (x)?
3. If U is the numbers 3, 4, and 5, what is the truth value of ∀ x P (x)? What is the truth
value of ∃ x P (x)?
Tip
For some domains of discourse, it is possible to “expand” a quantified expression into an equivalent
compound expression with no variables. In particular, when domains are finite.
Finite domains, conjunctions, disjunctions
Precedence of Quantifiers
Quantifiers have a higher precedence than all other logical connectives.
If we want a quantifier to apply to multiple predicates, we must use parentheses. ∀ x P (x) ∧ Q(x)
is not the same as ∀ x (P (x) ∧ Q(x)).
Quantified compounds
Let P (x) := “x has a son”. Let Q(x) := “x is a parent”. Let U be all people.
∀ x P (x) → Q(x) translates to “if every person has a son, then x is a parent”. That is,
we have not bound the variable in the predicate Q(x).
∀ x (P (x) → Q(x)) translates to “For all people, if a person has a son then that person
is a parent”.
Negating Quantifiers
When we are negating expressions with quantifiers, special care must be taken. Consider first some
English language examples.
Negating English
◦ “At least one student in this class does not know Python”
Already, we can see that there are two ways to express negation with quantifiers. We can negate
the quantifier itself, or we can negate the inner predicate. Formally, this is similar to De Morgan’s law
for propositional logic. Negating a universal or existential quantifier “flips” it to become the other one.
“There exists a student in this class who does not know Python”.
Let S := “thinks football is the best sport” with U being all people.
Quantified Equivalent
Expression Expression When True? When False?
You should really internalize these subtle differences in each case. You will really need this
throughout the course and in the future! Re-read the table and try the do the following checkpoint.
Checkpoint Solution
Translate the following sentences to predicate logic, using quantifiers as appropriate. Can
you discern a truth value from the resulting expression?
∀ x ∃ y (x × y = 1)
One way of thinking of nested quantifiers is through nested propositional functions. From the
previous example, let P (x, y) := (x × y = 1) and Q(x) := ∃ y P (x, y). P (x, y) is saying that
x and y are multiplicative inverses, meanwhile Q(x) is saying x has a multiplicative inverse.
Then, “every real number has a multiplicative inverse” can be written as:
Order of Quantifiers
The order of quantifiers is very important. Consider again multiplicative inverses.
No! The first says “every real number has a multiplicative inverse”. The second says “there exists a
real number which, when multiplied by any real number, equals 1”.
Ordering quantifiers
Let P (x, y) := x + y = 0 and the domain of x and y be the real numbers. The truth
value of the following expressions are:
∀x ∀y P (x, y) False
∀y ∀x P (x, y) False
∃x ∀y P (x, y) False
∀y ∃x P (x, y) True
∃x ∃y P (x, y) True
This previous exemplifies that the order of two universal quantifiers (or existential quantifiers)
applied to a single propositional function does not change the truth value. However, the order
between a universal quantifier and an existential quantifier does matter.
Tip
One way to think about nested quantifiers is that variables are bound or “fixed” left to right.
In ∃x ∀y P (x, y), x is bound first, regardless of what happens to y. Then y is bound.
Yet another way of thinking about nested quantifiers is as nested loops. Consider the below loop
and the following quantified expressions.
for i in range(n) :
for j in range(m) :
P(i, j)
Expression When is it true?
Of course, when the domains of discourse are infinite, we cannot actually loop through all of the
possible elements. However, it is a useful way to think about quantifiers.
Quantifiers to English
Let C(x) := x has a computer, F (x, y) := x and y are friends, where U is all students
at Western.
In English, this says “every student at Western has a computer or has a friend with a
computer”.
Before we start thinking about translating more interesting mathematical statements, let’s check in
and make sure we understand nested quantifiers and their ordering.
Checkpoint Solution
Let C(x) := x has a computer, F (x, y) := x and y are friends, where U is all students
at Western.
Once we conclude this chapter on logic and proofs, the rest of the course will be much more
mathematical. We will use the language of logic to formally state many mathematical properties,
theorems, and facts. Let’s see a taste of that before returning to “fun” English statements.
Unfortunately, a large part of being able to understand, and translate, mathematical statements
comes with practice. But, there is a general methodology we can use to convert mathematical
statements to logic.
1. First re-write the statement to be more verbose. Replace phrases like “q whenever p” with “if p
then q” to bring the statement closer to a “direct translation”.
2. Explicitly introduce variables. Replace phrases like “a number greater than two” with “a
number x such that x > 2”.
3. Finally, translate that sentence to a logical expression using quantifiers, predicates, and logical
connectives.
Write “the sum of two positive integers is always positive” as a logical expression.
1. Re-write the sentence to be more verbose: “for any two integers, if they are both positive,
then their sum is positive.”
2. Use variables explicitly: “for any two integers x and y, if x and y are both positive, then
their sum is positive”.
Consider a mail server with limited bandwidth. The designer specifies three requirements:
1. ∀ m (L(m, 1) → C(m))
Now, you may be wondering, is it possible to “distribute” a quantifier into a compound expression as
we did with negation? The answer is sometimes.
However, in more cases, quantifiers do not distribute. Here are some counterexamples.
A key reason why existential quantifiers do not distribute is because the two quantifiers bind the
variable in different ways. ∃x P (x) ∧ ∃x Q(x) means “there exists some x such that P (x) AND
there exists some x such that Q(x)”. The x in the first clause is not the same x in the second
clause; x was quantified twice in different contexts.
This is very different from saying ∃x(P (x) ∧ Q(x)), which says “there exists some x such that
P (x) and Q(x) are true”. In the latter, the same object x is being applied simultaneously to P and
Q.
1.2.5. Exercises
Predicates and Variables
Exercise 1.17
Rewrite the following statements, as appropriate, using the quantifiers “for all” and “there
exists”.
2. “For every real number y, there exists a real number x such that x > y.”
3. “For every positive integer x, there exists prime numbers p1, … , pk such that
x = p1p2 ⋯ pk.”
Exercise 1.18
Rewrite the following statements, as appropriate, using the quantifiers “for all” and “there
exists”. You don’t have to translate to predicate logic, just re-write in English being more
verbose and including the phrases “for all” and “there exists” as appropriate.
1. There exists a polynomial with integer coefficients which has integer roots.
Quantifiers
Exercise 1.19
If the domain of x is all animals, what is the truth value of the following?
1. ∀x (F (x) → W (x))
2. ∃x (S(x) → ¬W (x))
4. ∀x S(x) → ∀x W (x)
1. True. If the animal is a fish, then it lives in the water. If the animal is not a fish, falsity
implies anything.
2. True. There exists many animals with scales that live on land. Butterflies, chameleons,
pangolins.
4. True. Quantifiers have precedence over implication. Therefore, the left-hand side and
right-hand side are independently false and we have F → F ≡ T .
Exercise 1.20
If the domain of x is all plants and animals, translate each of these quantified statements
to a natural language statement. What is the truth value of each of them?
1. ∀x (B(x) → E(x))
2. ∀x (E(x) → B(x))
3. ∃x (W (x) ∧ P (x))
4. ∃x (W (x) ∧ E(x))
6. ∀x (W (x) → ¬M(x))
5. False. There are organisms which are neither plants, mammals or birds. Reptiles,
amphibians, etc.
Exercise 1.21
Write the following English statements in predicate logic. Do this in two steps. First, re-
write the statement so that any implicit quantifiers or logical connectives are explicit.
Second, convert that statement to predicate logic, quantified as necessary.
1. “There exists a positive integer that is smaller than every other positive integer.” Let
P (x, y) := x < y. Letting the domain of x and y be positive integers, we have:
∃x ∀y P (x, y)
2. “There exists a polynomial that has a non-real (i.e. complex) root.” Let P (f) := “f has a
non-real root.” Letting the domain of f be all polynomials, we have:
∃fP (f)
3. “There exists sets A and B such that A and B have no common elements.” Let
P (A, B) := “A and B have no common elements.” Letting the domain of A and B be all
possible sets, we have:
∃A ∃B P (A, B)
Exercise 1.22
Let U be the set of imaginary creatures consisting of drackles, klabs, and grebbits.
• D(x) := x is a drackle.
• K(x) := x is a klab.
• G(x) := x is a grebbit.
1. Everything is a drackle.
2. Nothing is a klab.
5. No klab is a grebbit.
1. ∀ x D(x)
2. ¬∃ x K(x) ≡ ∀ x ¬K(x)
3. ∀ x (D(x) → K(x))
4. ∃ x (D(x) ∧ G(x))
Exercise 1.23
In some Far Far Away Kingdom, the Queens’s court is composed of a number of members
and ranks. Let U be the set of all such ranks.
• K(x) := x is a Knight.
• B(x) := x is a Bard.
• R(x) := x is royalty.
• T (x) := x is a Thane.
1. ∃ x (K(x) ∧ B(x))
3. ∀ x (T (x) → K(x))
Let the domain of u be all users of the system and the domain of e be “encrypted” or
“unencrypted”. Let:
1. ∀ u ( A(u) → C(u) )
2. ∀ u ∃ e ( C(u) ↔ R(u, e) )
These are not consistent. If A(u), C(u) are false and E(u) is true, then the third
requirement implies that u can receive messages, contradicting (2).
Nested Quantifiers
Exercise 1.25
1. ∀x ∀y P (x, y)
2. ∀x ∃y P (x, y)
3. ∃x ∀y P (x, y)
4. ∃x ∃y P (x, y)
5. ∀x P (x, x)
1. False
2. True
3. False
4. True
5. True
Exercise 1.26
Let T (x, y) be the predicate “x is taking y” where the domain of x is all students and the
domain of y is all courses.
1. ∀C ∃S T (S, C)
2. ∃S ∀C T (S, C)
3. ∀S ∃C ¬T (S, C)
4. ∃C ∀S T (S, C)
5. ∀S ∃C T (S, C)
6. ∃C ∀S ¬T (S, C)
7. ∃S ∀C ¬T (S, C)
8. ∀C ∃S ¬T (S, C)
9. ∃C ∀S ¬T (S, C)
10. ∀S ∀C ¬T (S, C)
Exercise 1.27
Express the following English sentences in predicate logic. First define a predicate and
then write the English sentence as a quantified predicate statement.
2. “Siblinghood is symmetric.”
3. ∀x ∃y L(x, y)
4. ∃y ∀x L(x, y)
5. ∃x ∃y L(x, y)
Exercise 1.28
Let E(m, p) := “man m has eaten pizza p” and T (p, i) := “pizza p has ingredient i as a
topping”. Let the domains of m be all men, i be all toppings available at Pizza Hut, and p
be all pizzas made at Pizza Hut.
1. “A man has, for all toppings, eaten a pizza with that topping.”
Exercise 1.29
Negate each of the logical expressions in Exercise 1.28. Ensure to distribute the negation
inside of any quantifiers.
Exercise 1.30
Use quantifiers and predicates to express the statement “there is a woman who has taken
a flight on every airline in the world”.
• The domain of w is all women, the domain of f is all flights, and the domain of a is all
airlines.
Use quantifiers and predicates to express the statement “there is a person that has visited
every country or that country no longer exists”.
Then, negate the quantified expression. What is a natural language interpretation of the
negated statement?
• The domain of p is all people, the domain of c is all countries, past or present.
∃p ∀c (V (p, c) ∨ ¬E(c))
Its interpretation: “There is a extant country which not every person in the world has
visited. “
Exercise 1.32
Use quantifiers to express the statement “there does not exist a woman who has taken a
flight on every airline in the world.” That is, negate the solution to Exercise 1.30. Distribute
the negation so that there is no negation applied to a quantifier.
“For every woman, there is an airline such that for all flights, this woman has not taken that
flight or that flight is not on this airline.”
By Alexander Brandt
© Copyright 2022.