48.7 KB · commit a9602da
Propositional logic, studied in Sections 1.1–1.3, cannot adequately express the meaning of all statements in mathematics and in natural language. For example, suppose that we know that “Every computer connected to the university network is functioning properly.” No rules of propositional logic allow us to conclude the truth of the statement “MATH3 is functioning properly,” where MATH3 is one of the computers connected to the university network. Likewise, we cannot use the rules of propositional logic to conclude from the statement “CS2 is under attack by an intruder,” where CS2 is a computer on the university network, that the statement “There is a computer on the university network that is under attack by an intruder” is true.
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 in ways that permit us to reason and explore relationships between objects. To understand predicate logic, we first need to introduce the concept of a predicate. Afterward, we will introduce the notions of subject and quantification.
Statements involving variables, such as “x>3,”“x=y+3,”“x+y=z,” and “computer x is under attack by an intruder,” and “computer x is functioning properly,” are often found in mathematical assertions, in computer programs, and in system specifications. These statements are neither true nor false when the values of the variables are not specified. In this section, we will discuss the ways that propositions can be produced from such statements.
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. Consider Examples 1 and 2.
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. ◀
Let A(x) denote the statement “Computer x is under attack by an intruder.” Suppose that of the computers on campus, only CS2 and MATH1 are currently under attack by intruders. What are truth values of A(CS1), A(CS2), and A(MATH1)?
Solution: We obtain the statement A(CS1) by setting x=CS1 in the statement “Computer x is under attack by an intruder.” Because CS1 is not on the list of computers currently under attack, we conclude that A(CS1) is false. Similarly, because CS2 and MATH1 are on the list of computers under attack, we know that A(CS2) and A(MATH1) are true. ◀
We can also have statements that involve more than one variable. For instance, consider the statement “x=y+3.” We can denote this statement by Q(x,y), where x and y are variables and Q is the predicate. When values are assigned to the variables x and y, the statement Q(x,y) has a truth value.
Let Q(x,y) denote the statement “x=y+3.” What are the truth values of the propositions Q(1,2) and Q(3,0)?
Solution: To obtain Q(1,2), set x=1 and y=2 in the statement Q(x,y). Hence, Q(1,2) is the statement “1=2+3,” which is false. The statement Q(3,0) is the proposition “3=0+3,” which is true. ◀
Let A(c,n) denote the statement “Computer c is connected to network n,” where c is a variable representing a computer and n is a variable representing a network. Suppose that the computer MATH1 is connected to network CAMPUS2, but not to network CAMPUS1. What are the values of A(MATH1,CAMPUS1) and A(MATH1,CAMPUS2)?
Solution: Because MATH1 is not connected to the CAMPUS1 network, we see that A(MATH1,CAMPUS1) is false. However, because MATH1 is connected to the CAMPUS2 network, we see that A(MATH1,CAMPUS2) is true. ◀
Similarly, we can let R(x,y,z) denote the statement “x+y=z.” When values are assigned to the variables x, y, and z, this statement has a truth value.
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). We see that 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. ◀
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.
Propositional functions occur in computer programs, as Example 6 demonstrates.
Consider the statement ifx>0thenx:=x+1. 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. ◀
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. (Note that unless the correctness of a computer program is established, no amount of testing can show that it produces the desired output for all input values, unless every input value is tested.) 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. As Example 7 illustrates, we use predicates to describe both preconditions and postconditions. We will study this process in greater detail in Section 5.5.
Consider the following program, designed to interchange the values of two variables x and y.
temp:=xx:=yy:=tempFind predicates that we can use as the precondition and the postcondition to verify the correctness of this program. Then explain how to use them to verify that for all valid input the program does what is intended.
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.”
To verify that the program always does what it is supposed to do, suppose that the precondition P(x,y) holds. That is, we suppose that the statement “x=a and y=b” is true. 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, so after this step we know that x=a, temp=a, and y=b. After the second step of the program, x:=y, we know that x=b, temp=a, and y=b. Finally, 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. ◀
When the variables in a propositional function are assigned values, the resulting statement becomes a proposition with a certain truth value. However, there is another important way, called quantification, to create a proposition from a propositional function. Quantification expresses the extent to which a predicate is true over a range of elements. In English, the words all, some, many, none, and few are used in quantifications. We will focus on two types of quantification here: universal quantification, which tells us that a predicate is true for every element under consideration, and existential quantification, which tells us that there is one or more element under consideration for which the predicate is true. The area of logic that deals with predicates and quantifiers is called the predicate calculus.
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. Such a statement is expressed using universal quantification. 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. Note that the domain specifies the possible values of the variable x. 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.
The meaning of the universal quantifier is summarized in the first row of Table 1. We illustrate the use of the universal quantifier in Examples 8–13.
| Statement | When True? | When False? |
|---|---|---|
| ∀xP(x) | P(x) is true for every x. | There is an x for which P(x) is false. |
| ∃xP(x) | There is an x for which P(x) is true. | P(x) is false for every x. |
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. ◀
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.”
A statement ∀xP(x) is false, where P(x) is a propositional function, if and only if P(x) is not always true when x is in the domain. One way to show that P(x) is not always true when x is in the domain is to find a counterexample to the statement ∀xP(x). Note that a single counterexample is all we need to establish that ∀xP(x) is false. Example 9 illustrates how counterexamples are used.
Let Q(x) be the statement “x<2.” What is the truth value of the quantification ∀xQ(x), where the domain consists of all real numbers?
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). Thus ∀xQ(x) is false. ◀
Suppose that P(x) is “x2>0.” To show that the statement ∀xP(x) is false where the universe of discourse consists of all integers, we give a counterexample. We see that x=0 is a counterexample because x2=0 when x=0, so that x2 is not greater than 0 when x=0. ◀
Looking for counterexamples to universally quantified statements is an important activity in the study of mathematics, as we will see in subsequent sections of this book.
When all the elements in the domain can be listed—say, x1,x2,…,xn—it follows that the universal quantification ∀xP(x) is the same as the conjunction P(x1)∧P(x2)∧⋯∧P(xn), because this conjunction is true if and only if P(x1),P(x2),…,P(xn) are all true.
What is the truth value of ∀xP(x), where P(x) is the statement “x2<10” and the domain consists of the positive integers not exceeding 4?
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. ◀
What does the statement ∀xN(x) mean if N(x) is “Computer x is connected to the network” and the domain consists of all computers on campus?
Solution: The statement ∀xN(x) means that for every computer x on campus, that computer x is connected to the network. This statement can be expressed in English as “Every computer on campus is connected to the network.” ◀
As we have pointed out, specifying the domain is mandatory when quantifiers are used. The truth value of a quantified statement often depends on which elements are in this domain, as Example 13 shows.
What is the truth value of ∀x(x2≥x) if the domain consists of all real numbers? What is the truth value of this statement if the domain consists of all integers?
Solution: The universal quantification ∀x(x2≥x), where the domain consists of all real numbers, is false. For example, (21)2≥21. Note that x2≥x if and only if x2−x=x(x−1)≥0. Consequently, x2≥x if and only if x≤0 or x≥1. It follows that ∀x(x2≥x) is false if the domain consists of all real numbers (because the inequality is false for all real numbers x with 0<x<1). However, if the domain consists of the integers, ∀x(x2≥x) is true, because there are no integers x with 0<x<1. ◀
Many mathematical statements assert that there is an element with a certain property. Such statements are expressed using existential quantification. With existential quantification, we form a proposition that is true if and only if P(x) is true for at least one value of x in the domain.
A domain must always be specified when a statement ∃xP(x) is used. Furthermore, the meaning of ∃xP(x) changes when the domain changes. Without specifying the domain, the statement ∃xP(x) has no meaning.
Besides the phrase “there exists,” we can also express existential quantification in many other ways, such as by using the words “for some,” “for at least one,” or “there is.” The existential quantification ∃xP(x) is read as “There is an x such that P(x),” “There is at least one x such that P(x),” or “For some xP(x).”
The meaning of the existential quantifier is summarized in the second row of Table 1. We illustrate the use of the existential quantifier in Examples 14–16.
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. ◀
Observe that the statement ∃xP(x) is false if and only if there is no element x in the domain for which P(x) is true. That is, ∃xP(x) is false if and only if P(x) is false for every element of the domain. We illustrate this observation in Example 15.
Let Q(x) denote the statement “x=x+1.” What is the truth value of the quantification ∃xQ(x), where the domain consists of all real numbers?
Solution: Because Q(x) is false for every real number x, the existential quantification of Q(x), which is ∃xQ(x), is false. ◀
When all elements in the domain can be listed—say, x1,x2,…,xn—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.
What is the truth value of ∃xP(x), where P(x) is the statement “x2>10” and the universe of discourse consists of the positive integers not exceeding 4?
Solution: Because the domain is {1,2,3,4}, the proposition ∃xP(x) is the same as the disjunction P(1)∨P(2)∨P(3)∨P(4). Because P(4), which is the statement “42>10,” is true, it follows that ∃xP(x) is true. ◀
It is sometimes helpful to think in terms of looping and searching when determining the truth value of a quantification. Suppose that there are n objects in the domain for the variable x. To determine whether ∀xP(x) is true, we can loop through all n values of x to see whether P(x) is always true. If we encounter a value x for which P(x) is false, then we have shown that ∀xP(x) is false. Otherwise, ∀xP(x) is true. To see whether ∃xP(x) is true, we loop through the n values of x searching for a value for which P(x) is true. If we find one, then ∃xP(x) is true. If we never find such an x, then we have determined that ∃xP(x) is false. (Note that this searching procedure does not apply if there are infinitely many values in the domain. However, it is still a useful way of thinking about the truth values of quantifications.)
We have now introduced universal and existential quantifiers. These are the most important quantifiers in mathematics and computer science. However, there is no limitation on the number of different quantifiers we can define, such as “there are exactly two,” “there are no more than three,” “there are at least 100,” and so on. Of these other quantifiers, the one that is most often seen is the uniqueness quantifier, denoted by ∃! or ∃1. The notation ∃!xP(x) [or ∃1xP(x)] states “There exists a unique x such that P(x) is true.” (Other phrases for uniqueness quantification include “there is exactly one” and “there is one and only one.”) For instance, ∃!x(x−1=0), where the domain is the set of real numbers, states that there is a unique real number x such that x−1=0. This is a true statement, as x=1 is the unique real number such that x−1=0. Observe that we can use quantifiers and propositional logic to express uniqueness (see Exercise 52 in Section 1.5), so the uniqueness quantifier can be avoided. Generally, it is best to stick with existential and universal quantifiers so that rules of inference for these quantifiers can be used.
An abbreviated notation is often used to restrict the domain of a quantifier. In this notation, a condition a variable must satisfy is included after the quantifier. This is illustrated in Example 17. We will also describe other forms of this notation involving set membership in Section 2.1.
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.” Note that this statement is equivalent to ∀y(y=0→y3=0).
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). ◀
Note that the restriction of a universal quantification is the same as the universal quantification of a conditional statement. For instance, ∀x<0(x2>0) is another way of expressing ∀x(x<0→x2>0). On the other hand, the restriction of an existential quantification is the same as the existential quantification of a conjunction. For instance, ∃z>0(z2=2) is another way of expressing ∃z(z>0∧z2=2).
The quantifiers ∀ and ∃ have higher precedence than all logical operators from propositional calculus. For example, ∀xP(x)∨Q(x) is the disjunction of ∀xP(x) and Q(x). In other words, it means (∀xP(x))∨Q(x) rather than ∀x(P(x)∨Q(x)).
When a quantifier is used on the variable x, we say that this occurrence of the variable is bound. An occurrence of a variable that is not bound by a quantifier or set equal to a particular value is said to be free. All the variables that occur in a propositional function must be bound or set equal to a particular value to turn it into a proposition. This can be done using a combination of universal quantifiers, existential quantifiers, and value assignments.
The part of a logical expression to which a quantifier is applied is called the scope of this quantifier. Consequently, a variable is free if it is outside the scope of all quantifiers in the formula that specify this variable.
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). 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. The reader should be aware that in common usage, the same letter is often used to represent variables bound by different quantifiers with scopes that do not overlap. ◀
In Section 1.3 we introduced the notion of logical equivalences of compound propositions. We can extend this notion to expressions involving predicates and quantifiers.
Example 19 illustrates how to show that two statements involving predicates and quantifiers are logically equivalent.
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. Furthermore, we can also distribute an existential quantifier over a disjunction. However, we cannot distribute a universal quantifier over a disjunction, nor can we distribute an existential quantifier over a conjunction. (See Exercises 50 and 51.)
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. Suppose we have particular predicates P and Q, with a common domain. We can show that ∀x(P(x)∧Q(x)) and ∀xP(x)∧∀xQ(x) are logically equivalent 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 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 [because P(x) and Q(x) are both true for all elements in the domain, there is no conflict using the same value of a here]. 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). ◀
We will often want to consider the negation of a quantified expression. For instance, consider the negation of the statement “Every student in your class has taken a course in calculus.” This statement is a universal quantification, namely, ∀xP(x), where P(x) is the statement “x has taken a course in calculus” and the domain consists of the students in your class. The negation of this statement is “It is not the case that every student in your class has taken a course in calculus.” This is equivalent to “There is a student in your class who has not taken a course in calculus.” And this is simply the existential quantification of the negation of the original propositional function, namely, ∃x¬P(x). This example illustrates the following logical equivalence: ¬∀xP(x)≡∃x¬P(x).
To show that ¬∀xP(x) and ∃x¬P(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.
Suppose we wish to negate an existential quantification. For instance, consider the proposition “There is a student in this class who has taken a course in calculus.” This is the existential quantification ∃xQ(x), where Q(x) is the statement “x has taken a course in calculus.” The negation of this statement is the proposition “It is not the case that there is a student in this class who has taken a course in calculus.” This is equivalent to “Every student in this class has not taken calculus,” which is just the universal quantification of the negation of the original propositional function, or, phrased in the language of quantifiers, ∀x¬Q(x). This example illustrates the equivalence ¬∃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.
The rules for negations for quantifiers are called De Morgan's laws for quantifiers. These rules are summarized in Table 2.
| Negation | Equivalent Statement | When Is Negation True? | When False? |
|---|---|---|---|
| ¬∃xP(x) | ∀x¬P(x) | For every x, P(x) is false. | There is an x for which P(x) is true. |
| ¬∀xP(x) | ∃x¬P(x) | There is an x for which P(x) is false. | P(x) is true for every x. |
We illustrate the negation of quantified statements in Examples 20 and 21.
What are the negations of the statements “There is an honest politician” and “All Americans eat cheeseburgers”?
Solution: Let H(x) denote “x is honest.” Then the statement “There is an honest politician” is represented by ∃xH(x), where the domain consists of all politicians. The negation of this statement is ¬∃xH(x), which is equivalent to ∀x¬H(x). This negation can be expressed as “Every politician is dishonest.” (Note: In English, the statement “All politicians are not honest” is ambiguous. In common usage, this statement often means “Not all politicians are honest.” Consequently, we do not use this statement to express this negation.)
Let C(x) denote “x eats cheeseburgers.” Then the statement “All Americans eat cheeseburgers” is represented by ∀xC(x), where the domain consists of all Americans. The negation of this statement is ¬∀xC(x), which is equivalent to ∃x¬C(x). This negation can be expressed in several different ways, including “Some American does not eat cheeseburgers” and “There is an American who does not eat cheeseburgers.” ◀
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. ◀
We use De Morgan's laws for quantifiers in Example 22.
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 fifth logical equivalence in Table 7 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. ◀
Translating sentences in English (or other natural languages) into logical expressions is a crucial task in mathematics, logic programming, artificial intelligence, software engineering, and many other disciplines. We began studying this topic in Section 1.1, where we used propositions to express sentences in logical expressions. In that discussion, we purposely avoided sentences whose translations required predicates and quantifiers. Translating from English to logical expressions becomes even more complex when quantifiers are needed. Furthermore, there can be many ways to translate a particular sentence. (As a consequence, there is no “cookbook” approach that can be followed step by step.) We will use some examples to illustrate how to translate sentences from English into logical expressions. The goal in this translation is to produce simple and useful logical expressions. In this section, we restrict ourselves to sentences that can be translated into logical expressions using a single quantifier; in the next section, we will look at more complicated sentences that require multiple quantifiers.
Express the statement “Every student in this class has studied calculus” using predicates and quantifiers.
Solution: First, we rewrite the statement so that we can clearly identify the appropriate quantifiers to use. Doing so, we obtain: “For every student in this class, that student has studied calculus.” Next, we introduce a variable x so that our statement becomes “For every student x in this class, x has studied calculus.” Continuing, we introduce C(x), which is the statement “x has studied calculus.” Consequently, if the domain for x consists of the students in the class, we can translate our statement as ∀xC(x).
However, there are other correct approaches; different domains of discourse and other predicates can be used. The approach we select depends on the subsequent reasoning we want to carry out. For example, we may be interested in a wider group of people than only those in this class. If 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)). [Caution! Our statement cannot be expressed as ∀x(S(x)∧C(x)) because this statement says that all people are students in this class and have studied calculus!]
Finally, when we are interested in the background of people in subjects besides calculus, we may prefer to use the two-variable quantifier Q(x,y) for the statement “student x has studied subject y.” Then we would replace C(x) by Q(x,calculus) in both approaches to obtain ∀xQ(x,calculus) or ∀x(S(x)→Q(x,calculus)). ◀
In Example 23 we displayed different approaches for expressing the same statement using predicates and quantifiers. However, we should always adopt the simplest approach that is adequate for use in subsequent reasoning.
Express the statements “Some student in this class has visited Mexico” and “Every student in this class has visited either Canada or Mexico” using predicates and quantifiers.
Solution: The statement “Some student in this class has visited Mexico” means that “There is a student in this class with the property that the student has visited Mexico.” We can introduce a variable x, so that our statement becomes “There is a student x in this class having the property that x has visited Mexico.” We introduce M(x), which is the statement “x has visited Mexico.” If the domain for x consists of the students in this class, we can translate this first statement as ∃xM(x).
However, if we are interested in people other than those in this class, we look at the statement a little differently. Our statement can be expressed as “There is a person x having the properties that x is a student in this class and x has visited Mexico.” In this case, the domain for the variable x consists of all people. We introduce S(x) to represent “x is a student in this class.” Our solution becomes ∃x(S(x)∧M(x)) because the statement is that there is a person x who is a student in this class and who has visited Mexico. [Caution! Our statement cannot be expressed as ∃x(S(x)→M(x)), which is true when there is someone not in the class because, in that case, for such a person x, S(x)→M(x) becomes either F→T or F→F, both of which are true.]
Similarly, the second statement can be expressed as “For every x in this class, x has the property that x has visited Mexico or x has visited Canada.” (Note that we are assuming the inclusive, rather than the exclusive, or here.) We let C(x) be “x has visited Canada.” Following our earlier reasoning, we see that if the domain for x consists of the students in this class, this second statement can be expressed as ∀x(C(x)∨M(x)). However, if the domain for x consists of all people, our statement can be expressed as “For every person x, if x is a student in this class, then x has visited Mexico or x has visited Canada.” In this case, the statement can be expressed as ∀x(S(x)→(C(x)∨M(x))).
Instead of using M(x) and C(x) to represent that x has visited Mexico and x has visited Canada, respectively, we could use a two-place predicate V(x,y) to represent “x has visited country y.” In this case, V(x,Mexico) and V(x,Canada) would have the same meaning as M(x) and C(x) and could replace them in our answers. If we are working with many statements that involve people visiting different countries, we might prefer to use this two-variable approach. Otherwise, for simplicity, we would stick with the one-variable predicates M(x) and C(x). ◀
In Section 1.2 we used propositions to represent system specifications. However, many system specifications involve predicates and quantifications. This is illustrated in Example 25.
Use predicates and quantifiers to express the system specifications “Every mail message larger than one megabyte will be compressed” and “If a user is active, at least one network link will be available.”
Solution: Let S(m,y) be “Mail message m is larger than y megabytes,” where the variable m has the domain of all mail messages and the variable y is a positive real number, and let C(m) denote “Mail message m will be compressed.” Then the specification “Every mail message larger than one megabyte will be compressed” can be represented as ∀m(S(m,1)→C(m)).
Let A(u) represent “User u is active,” where the variable u has the domain of all users, and let S(n,x) denote “Network link n is in state x,” where n has the domain of all network links and x has the domain of all possible states for a network link. Then the specification “If a user is active, at least one network link will be available” can be represented by ∃uA(u)→∃nS(n,available). ◀
Lewis Carroll (really C. L. Dodgson writing under a pseudonym), the author of Alice in Wonderland, is also the author of several works on symbolic logic. His books contain many examples of reasoning using quantifiers. Examples 26 and 27 come from his book Symbolic Logic; other examples from that book are given in the exercises at the end of this section. These examples illustrate how quantifiers are used to express various types of statements.
Consider these statements. The first two are called premises and the third is called the conclusion. The entire set is called an argument. “All lions are fierce.” “Some lions do not drink coffee.” “Some fierce creatures do not drink coffee.” (In Section 1.6 we will discuss the issue of determining whether the conclusion is a valid consequence of the premises. In this example, it is.) 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).
Solution: We can express these statements as: ∀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)). ◀
Consider these statements, of which the first three are premises and the fourth is a valid conclusion. “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.” Let P(x), Q(x), R(x), and S(x) be the statements “x is a hummingbird,” “x is large,” “x lives on honey,” and “x is richly colored,” respectively. Assuming that the domain consists of all birds, express the statements in the argument using quantifiers and P(x), Q(x), R(x), and S(x).
Solution: We can express the statements in the argument as ∀x(P(x)→S(x)). ¬∃x(Q(x)∧R(x)). ∀x(¬R(x)→¬S(x)). ∀x(P(x)→¬Q(x)). (Note we have assumed that “small” is the same as “not large” and that “dull in color” is the same as “not richly colored.” To show that the fourth statement is a valid conclusion of the first three, we need to use rules of inference that will be discussed in Section 1.6.) ◀
An important type of programming language is designed to reason using the rules of predicate logic. Prolog (from Programming in Logic), developed in the 1970s by computer scientists working in the area of artificial intelligence, is an example of such a language. Prolog programs include a set of declarations consisting of two types of statements, Prolog facts and Prolog rules. Prolog facts define predicates by specifying the elements that satisfy these predicates. Prolog rules are used to define new predicates using those already defined by Prolog facts. Example 28 illustrates these notions.
Consider a Prolog program given facts telling it the instructor of each class and in which classes students are enrolled. The program uses these facts to answer queries concerning the professors who teach particular students. Such a program could use the predicates instructor(p, c) and enrolled(s, c) to represent that professor p is the instructor of course c and that student s is enrolled in course c, respectively. For example, the Prolog facts in such a program might include:
instructor(chan,math273)
instructor(patel,ee222)
instructor(grossman,cs301)
enrolled(kevin,math273)
enrolled(juana,ee222)
enrolled(juana,cs301)
enrolled(kiko,math273)
enrolled(kiko,cs301)
(Lowercase letters have been used for entries because Prolog considers names beginning with an uppercase letter to be variables.)
A new predicate teaches(p, s), representing that professor p teaches student s, can be defined using the Prolog rule
teaches(P,S) :- instructor(P,C), enrolled(S,C)
which means that teaches(p, s) is true if there exists a class c such that professor p is the instructor of class c and student s is enrolled in class c. (Note that a comma is used to represent a conjunction of predicates in Prolog. Similarly, a semicolon is used to represent a disjunction of predicates.)
Prolog answers queries using the facts and rules it is given. For example, using the facts and rules listed, the query
?enrolled(kevin,math273)
produces the response
yes
because the fact enrolled(kevin, math273) was provided as input. The query
?enrolled(X,math273)
produces the response
kevin
kiko
To produce this response, Prolog determines all possible values of X for which enrolled(X, math273) has been included as a Prolog fact. Similarly, to find all the professors who are instructors in classes being taken by Juana, we use the query
?teaches(X,juana)
This query returns
patel
grossman
◀