Predicates and Quantifiers: Presenter Yukun Wang Computer Science and Technology
Predicates and Quantifiers: Presenter Yukun Wang Computer Science and Technology
P r e s e n t e r : Yu k u n Wa n g
C o m p u t e r s c i e n c e a n d Te c h n o l o g y
Predicates
Introduction
• Propositional logic, studied in Sections 1.1–1.3, cannot adequately express the
meaning of all statements in mathematics and in natural language.
•In this section we will introduce a more powerful type of logic called predicate
logic. We will see how predicate logic can be used to express the meaning of a wide
range of statements in mathematics and computer science.
1
Predicates
Predicates
Predicates
----indicating the property of individual variables or their relation to each other.
•Statements involving variables, such as
“x > 3,” “x = y + 3,” “x + y = z,”
and
“Computer x is under attack by an intruder.”
•These statements are neither true nor false when the values of the variables are
specified.
•In this section, we will discuss the ways that propositions can be produced from
such statements.
Predicates
Predicates
•“x > 3”
•The statement “x is greater than 3” has two parts. The first part, the variable x, is
the subject of the statement. The second part—the predicate, “is greater than 3”—
refers to a property that the subject of the statement can have.
•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.
•The statement P(x) is also said to be the value of the propositional function P at x.
Once a value has been assigned to the variable x, the statement P(x) becomes a
proposition and has a truth value.
Predicates
Example 1: Let P(x) denote the statement “x > 3.” What are the truth values of P(4)
and P(2)?
Solution:
•We obtain the statement P(4) by setting x = 4 in the statement “x > 3.”
•Hence, P(4), which is the statement “4 > 3,” is true. However, P(2), which is the
statement “2 > 3,” is false.
Predicates
Example 2:Let R(x, y, z) denote the statement “x + y = z.”What are the truth values
of the propositions R(1, 2, 3) and R(0, 0, 1)?
Solution:
•The proposition R(1, 2, 3) is obtained by setting x = 1, y = 2, and z = 3 in the
statement R(x, y, z).
•R(1, 2, 3) is the statement “1 + 2 = 3,” which is true. Also note that R(0, 0, 1),
which is the statement “0 + 0 = 1,” is false.
Predicates
Some Concepts
•In general, a statement involving the n variables x1, x2, … , xn can be denoted by
P(x1, x2, … , xn).
•A statement of the form P(x1, x2, … , xn) is the value of the propositional function
P at the n-tuple (x1, x2, … , xn), and P is also called an n-place predicate or an n-ary
predicate.
Solution:
When this statement is encountered in a program, the value of the variable x at that
point in the execution of the program is inserted into P(x), which is “x > 0.”
If P(x) is true for this value of x, the assignment statement x := x + 1 is executed, so
the value of x is increased by 1.
If P(x) is false for this value of x, the assignment statement is not executed, so the
value of x is not changed.
Preconditions and Postconditions
Some Concepts
•Predicates are also used to establish the correctness of computer programs, that is,
to show that computer programs always produce the desired output when given
valid input.
•The statements that describe valid input are known as preconditions and the
conditions that the output should satisfy when the program has run are known as
postconditions.
Preconditions and Postconditions
Example 4: Consider the following program, designed to interchange the values of
two variables x and y.
temp := x
x := y
y := temp
Find predicates that we can use as the precondition and the postcondition to
verify the correctness of this program.
Preconditions and Postconditions
Solution:
•For the precondition, we need to express that x and y have particular values before
we run the program. So, for this precondition we can use the predicate P(x, y),
where P(x, y) is the statement “x = a and y = b,” where a and b are the values of x
and y before we run the program.
•Because we want to verify that the program swaps the values of x and y for all
input values, for the postcondition we can use Q(x, y), where Q(x, y) is the statement
“x = b and y = a.”
Preconditions and Postconditions
Solution:
•To verify that the program always does what it is supposed to do, suppose that the
precondition P(x, y) holds. This means that x = a and y = b.
•The first step of the program, temp := x, assigns the value of x to the variable temp,
after this step we have x = a, temp = a, and y = b.
•The second step of the program, x := y, we know that x = b, temp = a, and y = b.
•After the third step, we know that x = b, temp = a, and y = a.
•Consequently, after this program is run, the postcondition Q(x, y) holds, that is, the
statement “x = b and y = a” is true.
2
Quantifiers
Quantifiers
Some Concepts
•Quantification asserts the domain for the subjects in predicates, that is the domain
for certain property hold.
•Quantification can create a proposition from a propositional function.
•Quantification expresses the extent to which a predicate is true over a range of
elements.
•The area of logic that deals with predicates and quantifiers is called the predicate
calculus.
Quantifiers
The Universal Quantifier
•Many mathematical statements assert that a property is true for all values of a
variable in a particular domain, called the domain of discourse (or the universe of
discourse), often just referred to as the domain.
•The universal quantification of P(x) for a particular domain is the proposition that
asserts that P(x) is true for all values of x in this domain.
Quantifiers
The Universal Quantifier
•The meaning of the universal quantification of P(x) changes when we change the
domain.
•The domain must always be specified when a universal quantifier is used; without
it, the universal quantification of a statement is not defined.
Quantifiers
Definition 1
• The universal quantification of P(x) is the statement
“P(x) for all values of x in the domain.”.
•The notation xP(x) denotes the universal quantification of P(x). Here is called
the universal quantifier. We read xP(x) as “for all x,P(x)” or “for every x,P(x).”
An element for which P(x) is false is called a counterexample to xP(x).
The meaning of the universal quantifier is summarized in the first row of Table 1.
TABLE 1 Quantifiers.
Statement When True? When False?
∀xP(x) P(x) is true for every x. There is an x for which P(x) is
false.
There is an x for which P(x) is
∃xP(x) false. P(x) is false for every x.
Quantifiers
We illustrate the use of the universal quantifier in Examples 5–7.
Example 5: Let P(x) be the statement “x + 1 > x.” What is the truth value of the
quantification xP(x), where the domain consists of all real numbers?
Solution:
Because P(x) is true for all real numbers x, the quantification xP(x) is true.
Quantifiers
Besides “for all” and “for every,” universal quantification can be
expressed in many other ways, including “all of,” “for each,” “given
any,” “for arbitrary,” “for each,” and “for any.”
Solution:
•Q(x) is not true for every real number x, because, for instance, Q(3) is false. That
is,x = 3 is a counterexample for the statement xQ(x).
TABLE 1 Quantifiers.
Statement When True? When False?
∀xP(x) P(x) is true for every x. There is an x for which P(x) is
false.
There is an x for which P(x) is
∃xP(x) true. P(x) is false for every x.
Quantifiers
Example 8: Let P(x) denote the statement “x > 3.” What is the truth value
of the quantification xP(x),where the domain consists of all real
numbers?
Solution:
• Because “x > 3” is sometimes true—for instance, when x = 4—the existential
quantification of P(x), which is xP(x), is true.
Solution:
• The statement xP(x) is the same as the conjunction
P(1) P(2) P(3) P(4),
because the domain consists of the integers 1, 2, 3, and 4. Because P(4), which is
the statement “42 < 10,” is false, it follows that xP(x) is false.
Quantifiers And Domains
Solution:
• Similarly, when the elements of the domain are x1, x2, … , xn, where n is a positive
integer, the existential quantification xP(x) is the same as the disjunction
P(x1) P(x2) P(xn),
because this disjunction is true if and only if at least one of P(x1), P(x2), … , P(xn) is
true.
Quantifiers And Domains
Example 10: What do the statements x < 0 (x2 > 0), y ≠ 0 (y3 ≠ 0), and z > 0
(z2 = 2) mean, where the domain in each case consists of the real numbers?
Solution:
• The statement x < 0 (x2 > 0) states that for every real number x with x < 0, x2 >
0.That is, it states “The square of a negative real number is positive.” This statement
is the same as x(x < 0 → x2 > 0).
•The statement y ≠ 0 (y3 ≠ 0) states that for every real number y with y ≠ 0, we
have y3 ≠ 0. That is, it states “The cube of every nonzero real number is nonzero.”
This statement is equivalent to y(y ≠ 0 → y3 ≠ 0).
Quantifiers And Domains
Example 10: What do the statements x < 0 (x2 > 0), y ≠ 0 (y3 ≠ 0), and z > 0
(z2 = 2) mean, where the domain in each case consists of the real numbers?
Solution:
•Finally, the statement z > 0 (z2 = 2) states that there exists a real number z with z
> 0 such that z2 = 2. That is, it states “There is a positive square root of 2.” This
statement is equivalent to z(z > 0 z2 = 2).
Precedence of Quantifiers
The quantifiers and have higher precedence than all logical operators
from propositional calculus.
Example 11:
•In the statement x(x + y = 1), the variable x is bound by the existential
quantification x, but the variable y is free because it is not bound by a quantifier
and no value is assigned to this variable. This illustrates that in the statement x(x +
y = 1), x is bound, but y is free.
•In the statement x(P(x) Q(x)) xR(x), all variables are bound. The scope of
the first quantifier, x, is the expression P(x) Q(x), because x is applied only to
P(x) Q(x) and not to the rest of the statement.
•Similarly, the scope of the second quantifier, x, is the expression R(x). That is, the
existential quantifier binds the variable x in P(x) Q(x) and the universal quantifier
x binds the variable x in R(x).
Quantifiers And Domains
Example 11:
•Observe that we could have written our statement using two different variables x
and y, as x(P(x) Q(x)) yR(y), because the scopes of the two quantifiers do
not overlap.
5
Tr a n s l a t i n g f r o m E n g l i s h
into Logical Expressions
Translating from English into Logical Expressions
Example : Express the statement “Every student in this class has studied
calculus” using predicates and quantifiers. The Domain consists of all
people
Solution:
• we change the domain to consist of all people, we will need to express our
statement as
“For every person x, if person x is a student in this class, then x has studied
calculus.”
If S(x) represents the statement that person x is in this class, we see that our
statement can be expressed as x(S(x) → C(x)).
Translating from English into Logical Expressions
Example : Consider these statements. The first two are called premises and the
third is called the conclusion. The entire set is called an argument.
Let P(x), Q(x), and R(x) be the statements “x is a lion,” “x is fierce,” and “x drinks
coffee,” respectively. Assuming that the domain consists of all creatures, express the
statements in the argument using quantifiers and P(x), Q(x), and R(x).
Translating from English into Logical Expressions
Solution:
• x(P(x) → Q(x)).
• x(P(x) ¬R(x)).
• x(Q(x) ¬R(x)).
Notice that the second statement cannot be written as x(P(x) → ¬R(x)). The
reason is that P(x) → ¬R(x) is true whenever x is not a lion, so that x(P(x) →
¬R(x)) is true as long as there is at least one creature that is not a lion, even if every
lion drinks coffee.
Similarly, the third statement cannot be written as x(Q(x) → ¬R(x)).
Using Quantifiers in System Specifications
Difinition 3
•Statements involving predicates and quantifiers are logically equivalent if and only
if they have the same truth value no matter which predicates are substituted into
these statements and which domain of discourse is used for the variables in these
propositional functions. We use the notation S ≡ T to indicate that two statements S
and T involving predicates and quantifiers are logically equivalent.
Logical Equivalences Involving Quantifiers
Example 11: Show that x(P(x) Q(x)) and xP(x) xQ(x) are logically
equivalent (where the same domain is used throughout). This logical equivalence
shows that we can distribute a universal quantifier over a conjunction.
Solution:
•To show that these statements are logically equivalent, we must show that they always take the same
truth value, no matter what the predicates P and Q are, and no matter which domain of discourse is
used.
•We can show that by doing two things.First, we show that if ∀x(P(x) ∧ Q(x)) is true, then ∀xP(x) ∧ ∀xQ(x) is
true.Second, we show that if ∀xP(x) ∧ ∀xQ(x) is true, then ∀x(P(x) ∧ Q(x)) is true.So, suppose that ∀x(P(x) ∧
Q(x)) is true. This means that if a is in the domain, then P(a) ∧Q(a) is true. Hence, P(a) is true and Q(a) is true.
Because P(a) is true and Q(a) is true for every element a in the domain, we can conclude that ∀xP(x) and ∀xQ(x)
are both true. This means that ∀xP(x) ∧ ∀xQ(x) is true.Next, suppose that ∀xP(x) ∧ ∀xQ(x) is true. It follows
that ∀xP(x) is true and ∀xQ(x) is true. Hence, if a is in the domain, then P(a) is true and Q(a) is true.It follows
that for all a, P(a) ∧ Q(a) is true. It follows that ∀x(P(x) ∧ Q(x)) is true. We can now conclude that∀x(P(x) ∧
Q(x)) ≡ ∀xP(x) ∧ ∀xQ(x).
Negating Quantified Expressions
•¬ xQ(x) ≡ x ¬Q(x)
Negating Quantified Expressions
¬ xP(x) ≡ x ¬P(x)
• To show that ¬ xP(x) and xP(x) are logically equivalent no matter what the
propositional function P(x) is and what the domain is, first note that ¬ xP(x) is true if
and only if xP(x) is false. Next, note that xP(x) is false if and only if there is an
element x in the domain for which P(x) is false. This holds if and only if there is an
element x in the domain for which ¬P(x) is true. Finally, note that there is an element
x in the domain for which ¬P(x) is true if and only if x ¬P(x) is true.
• Putting these steps together, we can conclude that ¬ xP(x) is true if and only if x
¬P(x) is true. It follows that ¬ xP(x) and x ¬P(x) are logically equivalent.
Negating Quantified Expressions
¬ xQ(x) ≡ x ¬Q(x)
• To show that ¬ xQ(x) and x ¬Q(x) are logically equivalent no matter what Q(x) is
and what the domain is, first note that ¬ xQ(x) is true if and only if xQ(x) is false.
This is true if and only if no x exists in the domain for which Q(x) is true. Next, note
that no x exists in the domain for which Q(x) is true if and only if Q(x) is false for
every x in the domain. Finally, note that Q(x) is false for every x in the domain if and
only if ¬Q(x) is true for all x in the domain, which holds if and only if x¬Q(x) is
true.
• Putting these steps together, we see that ¬ xQ(x) is true if and only if x¬Q(x) is
true. We conclude that ¬ xQ(x) and x ¬Q(x) are logically equivalent.
De Morgan’s laws for quantifiers
The rules for negations for quantifiers are called De Morgan’s laws for
quantifiers. These rules are summarized in Table 2.
Example 12: What are the negations of the statements x(x2 > x)
and x(x2 = 2)?
Solution:
•The negation of x(x2 > x) is the statement ¬ x(x2 > x), which is equivalent to
x¬(x2 > x). This can be rewritten as x(x2 ≤ x).
•The negation of x(x2 = 2) is the statement ¬ x(x2 = 2), which is equivalent to
x¬(x2 = 2). This can be rewritten as x(x2 ≠ 2).
•The truth values of these statements depend on the domain.
De Morgan’s laws for quantifiers
Example 13: Show that ¬ x(P(x) → Q(x)) and x(P(x) ¬Q(x)) are logically
equivalent.
Solution:
•By De Morgan’s law for universal quantifiers, we know that ¬ x(P(x) → Q(x))
and x(¬(P(x) → Q(x))) are logically equivalent.
•By the logical equivalence in Section 1.3, we know that ¬(P(x) → Q(x)) and P(x)
¬Q(x) are logically equivalent for every x.
•Because we can substitute one logically equivalent expression for another in a
logical equivalence, it follows that ¬ x(P(x) → Q(x)) and x(P(x) ¬Q(x)) are
logically equivalent.
Homework
1.Let Q(x) be the statement “x + 1 > 2x.” If the domain consists of all integers,
what are these truth values?
a) Q(0) b) Q(−1) c) Q(1)
d) xQ(x) e) xQ(x) f ) x¬Q(x)
2. Translate in two ways each of these statements into logical expressions. First,
let the domain consist of the students in your class and second, let it consist of all
people.
a) Someone in your class can speak Hindi.
b) Everyone in your class is friendly.
c) There is a person in your class who was not born in California.
d) A student in your class has been in a movie.
e) No student in your class has taken a course in logic programming.