• 沒有找到結果。

Predicates and Quantifiers

Solving Satisfiability Problems

65. Explain the steps in the construction of the compound proposition given in the text that asserts that every

1.4 Predicates and Quantifiers

Introduction

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, to conclude the truth of

“There is a computer on the university network that is under attack by an intruder.”

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 notion of quantifiers, which enable us to reason with statements that assert that a certain property holds for all objects of a certain type and with statements that assert the existence of an object with a particular property.

Predicates

Statements involving variables, such as

x > 3,” “x = y + 3,” “x + y = z,”

and

“computerx is under attack by an intruder,”

and

“computerx 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), whereP 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 functionP at x. Once a value has been assigned to the variablex, the statement P (x) becomes a proposition and has a truth value. Consider Examples 1 and 2.

EXAMPLE 1 LetP (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.

EXAMPLE 2 LetA(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 ofA(CS1), A(CS2), and A(MATH1)?

Solution:We obtain the statementA(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 thatA(CS1) is false. Similarly, because CS2 and MATH1 are on the list of computers under attack, we know thatA(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 andQ is the predicate. When values are assigned to the variables x and y, the statement Q(x, y) has a truth value.

EXAMPLE 3 LetQ(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 obtainQ(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.

CHARLES SANDERS PEIRCE (1839–1914) Many consider Charles Peirce, born in Cambridge, Mas-sachusetts, to be the most original and versatile American intellect. He made important contributions to an amazing number of disciplines, including mathematics, astronomy, chemistry, geodesy, metrology, engineer-ing, psychology, philology, the history of science, and economics. Peirce was also an inventor, a lifelong student of medicine, a book reviewer, a dramatist and an actor, a short story writer, a phenomenologist, a logician, and a metaphysician. He is noted as the preeminent system-building philosopher competent and productive in logic, mathematics, and a wide range of sciences. He was encouraged by his father, Benjamin Peirce, a professor of mathematics and natural philosophy at Harvard, to pursue a career in science. Instead, he decided to study logic and scientific methodology. Peirce attended Harvard (1855–1859) and received a Harvard master of arts degree (1862) and an advanced degree in chemistry from the Lawrence Scientific School (1863).

In 1861, Peirce became an aide in the U.S. Coast Survey, with the goal of better understanding scientific methodology. His service for the Survey exempted him from military service during the Civil War. While working for the Survey, Peirce did astronomical and geodesic work. He made fundamental contributions to the design of pendulums and to map projections, applying new mathematical developments in the theory of elliptic functions. He was the first person to use the wavelength of light as a unit of measurement.

Peirce rose to the position of Assistant for the Survey, a position he held until forced to resign in 1891 when he disagreed with the direction taken by the Survey’s new administration.

While making his living from work in the physical sciences, Peirce developed a hierarchy of sciences, with mathematics at the top rung, in which the methods of one science could be adapted for use by those sciences under it in the hierarchy. During this time, he also founded the American philosophical theory of pragmatism.

The only academic position Peirce ever held was lecturer in logic at Johns Hopkins University in Baltimore (1879–1884). His mathematical work during this time included contributions to logic, set theory, abstract algebra, and the philosophy of mathematics.

His work is still relevant today, with recent applications of this work on logic to artificial intelligence. Peirce believed that the study of mathematics could develop the mind’s powers of imagination, abstraction, and generalization. His diverse activities after retiring from the Survey included writing for periodicals, contributing to scholarly dictionaries, translating scientific papers, guest lecturing, and textbook writing. Unfortunately, his income from these pursuits was insufficient to protect him and his second wife from abject poverty. He was supported in his later years by a fund created by his many admirers and administered by the philosopher William James, his lifelong friend. Although Peirce wrote and published voluminously in a vast range of subjects, he left more than 100,000 pages of unpublished manuscripts. Because of the difficulty of studying his unpublished writings, scholars have only recently started to understand some of his varied contributions. A group of people is devoted to making his work available over the Internet to bring a better appreciation of Peirce’s accomplishments to the world.

EXAMPLE 4 LetA(c, n) denote the statement “Computer c is connected to network n,” where c is a variable representing a computer andn 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 ofA(MATH1, CAMPUS1) and A(MATH1, CAMPUS2)?

Solution:Because MATH1 is not connected to the CAMPUS1 network, we see thatA(MATH1, CAMPUS1) is false. However, because MATH1 is connected to the CAMPUS2 network, we

see thatA(MATH1, CAMPUS2) is true.

Similarly, we can letR(x, y, z) denote the statement `‘x + y = z.” When values are assigned to the variablesx, y, and z, this statement has a truth value.

EXAMPLE 5 What are the truth values of the propositionsR(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 statementR(x, y, z). We see that R(1, 2, 3) is the statement “1 + 2 = 3,” which is true. Also note thatR(0, 0, 1), which is the statement “0 + 0 = 1,” is false.

In general, a statement involving then variables x1, x2, . . . , xncan be denoted by P (x1, x2, . . . , xn).

A statement of the formP (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 a n-ary predicate.

Propositional functions occur in computer programs, as Example 6 demonstrates.

EXAMPLE 6 Consider the statement ifx > 0 then x := x + 1.

When this statement is encountered in a program, the value of the variablex at that point in the execution of the program is inserted intoP (x), which is “x > 0.” If P (x) is true for this value ofx, 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 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.

EXAMPLE 7 Consider the following program, designed to interchange the values of two variablesx 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. 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 thatx and y have particular values before we run the program. So, for this precondition we can use the predicateP (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 ofx and y for all input values, for the postcondition we can useQ(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 precon-ditionP (x, y) holds. That is, we suppose that the statement “x = a and y = b” is true. This means thatx = 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 thatx = 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 thatx = b, temp = a, and y = a. Consequently, after this program is run, the postconditionQ(x, y) holds, that is, the statement “x = b and y = a” is true.

Quantifiers

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.

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. Such a statement is expressed using universal quantification. The universal quantification ofP (x) for a particular domain is the proposition that asserts thatP (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 ofP (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.

DEFINITION 1 The universal quantification ofP (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 xP (x)” or “for every xP (x).” An element for whichP (x) is false is called a counterexample of ∀xP (x).

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.

TABLE 1 Quantifiers.

Statement When True? When False?

∀xP (x) P (x) is true for every x. There is anx for which P (x) is false.

∃xP (x) There is anx for which P (x) is true. P (x) is false for every x.

EXAMPLE 8 LetP (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:BecauseP (x) is true for all real numbers x, the quantification

∀xP (x)

is true.

Remark: Generally, an implicit assumption is made that all domains of discourse for quantifiers are nonempty. Note that if the domain is empty, then ∀xP (x) is true for any propositional functionP (x) because there are no elements x in the domain for which P (x) is false.

Remember that the truth value of∀xP (x) depends on the domain!

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.”

Remark: It is best to avoid using “for anyx” because it is often ambiguous as to whether “any”

means “every” or “some.” In some cases, “any” is unambiguous, such as when it is used in negatives, for example, “there is not any reason to avoid studying.”

A statement∀xP (x) is false, where P (x) is a propositional function, if and only if P (x) is not always true whenx 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.

EXAMPLE 9 LetQ(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.

EXAMPLE 10 Suppose that P (x) is “x2> 0.” To show that the statement ∀xP (x) is false where the uni-verse of discourse consists of all integers, we give a counterexample. We see thatx = 0 is a counterexample becausex2= 0 when x = 0, so that x2is not greater than 0 whenx = 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 ifP (x1), P (x2), . . . , P (xn) are all true.

EXAMPLE 11 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. BecauseP (4), which is the statement

“42< 10,” is false, it follows that ∀xP (x) is false.

EXAMPLE 12 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.

EXAMPLE 13 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 num-bers, is false. For example,(12)212. Note thatx2≥ 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 numbersx with 0< x < 1). However, if the domain consists of the integers, ∀x(x2≥ x) is true, because there

are no integersx with 0 < x < 1.

THE EXISTENTIAL QUANTIFIER 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 ifP (x) is true for at least one value ofx in the domain.

DEFINITION 2 The existential quantification ofP (x) is the proposition

“There exists an elementx in the domain such that P (x).”

We use the notation∃xP (x) for the existential quantification of P (x). Here ∃ is called the existential quantifier.

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 anx such that P (x),”

“There is at least onex such that P (x),”

or

“For somexP (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.

EXAMPLE 14 LetP (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

quan-tification ofP (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 whichP (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.

EXAMPLE 15 LetQ(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:BecauseQ(x) is false for every real number x, the existential quantification of Q(x),

which is∃xQ(x), is false.

Remember that the truth value of∃xP (x) depends

on the domain! Remark: Generally, an implicit assumption is made that all domains of discourse for quantifiers are nonempty. If the domain is empty, then∃xQ(x) is false whenever Q(x) is a propositional function because when the domain is empty, there can be no elementx in the domain for which Q(x) is true.

When all elements in the domain can be listed—say,x1, x2, . . . , xn— the existential quan-tification∃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 ofP (x1), P (x2), . . . , P (xn) is true.

EXAMPLE 16 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 disjunc-tion

P (1) ∨ P (2) ∨ P (3) ∨ P (4).

BecauseP (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 aren 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 then 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 anx, 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.)

THE UNIQUENESS QUANTIFIER We have now introduced universal and existential quan-tifiers. 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

THE UNIQUENESS QUANTIFIER We have now introduced universal and existential quan-tifiers. 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