• Tidak ada hasil yang ditemukan

Theorems in predicate logic)

Dalam dokumen Untitled - Digital Library Univ STEKOM (Halaman 133-137)

To test whether a particular variablexis free or bound in an expression, we can (consistently) replacexby a different name in that expression. If the meaning stays the same, thenxis bound; if the meaning changes, thenxis free. For example:

Example 3.37 (Testing for free and bound variables) Consider the following pairs of propositions:

xS:x>251 and ∃yS:y>251 (A)

x42x and y42y (B)

The expressions in (A) express precisely the same condition, namely:some element of S is greater than251.Thus, the variablesxandyin these two expressions arebound.

But the expressions in (B) mean different things, in the sense that we can construct a context in which these two statements have different truth values (for example, x = 3 andy = −2). The first expression states a condition on the value ofx, and the latter states a condition on the value ofy. Soxis a free variable in “x42x.”

Taking it further: The free-versus-bound-variable distinction is also something that may be familiar from programming, at least in some programming languages. There are some interesting issues in the design and implementation of programming languages that center on how free variables in a function definition, for example, get their values. See the discussion on p. 345.

An expression of predicate logic that contains no free variables is calledfully quan- tified.For expressions that are not fully quantified, we adopt a standard convention that any unbound variables in a stated claim areimplicitlyuniversally quantified. For example, consider these claims:

Claim A: Ifx≥1, thenx2x3.

Claim B: For allxR, ifx1, thenx2x3.

When we write a (true) claim like Claim A, we will implicitly interpret it to mean Claim B. (Note that Claim B also explicitly notesRas the domain of discourse, which was left implicit in Claim A.)

3.4.3 Theorem and Proof in Predicate Logic

Recall that atautologyis a proposition that is always true—in other words, it is true no matter what each Boolean variablepin the proposition “means” (that is, whether pis true or false). In this section, we will be interested in the corresponding notion of always-true statements of predicate logic, which are calledtheorems.A statement of predicate logic is “always true” when it’s true no matter what its predicates mean.

(Formally, the “meaning” of a predicatePis the set of elements of the universeUfor which the predicate is true—that is,{xU:P(x)}.)

Analogously, two fully quantified expressions arelogically equivalentif, for every possi- ble meaning of their predicates, the two expressions have the same truth values.

We’ll begin with a simple example of a theorem and a nontheorem:

Example 3.38 (A theorem of predicate logic)

LetSbe any set. The following claim is trueregardless of what the predicate P denotes:

xS:hP(x)∨ ¬P(x)i.

Indeed, this claim simply says that everyxSeither makesP(x) true orP(x) false.

And that assertion is true if the predicateP(x) is “x42” or “xhas red hair” or

xprefers programming in Python to playing Parcheesi”—indeed, it’s true for any predicateP.

Example 3.39 (A nontheorem)

Let’s show that the following proposition is not a theorem:

h∀xS:P(x)i

hxSP(x)i .

A theorem must be true regardless ofP’s meaning, so we can establish that this proposition isn’t a theorem by giving an example predicate that makes it false. Here’s one: letPbeisPrime(whereSisZ). Observe that∀xZ:isPrime(x) is false because isPrime(4) = False; and∀xZ:¬isPrime(x) is false because¬isPrime(5) = False. Thus the given proposition is false whenPisisPrime, and so it is not a theorem.

Note the crucial difference between Example 3.38, which states thatevery element of S either makes P true or makes P false,and Example 3.39, which states thateither every element of S makes P true, or every element of S makes P false.(Intuitively, it’s the difference between “Every letter is either a vowel or a consonant” and “Every letter is a vowel or every letter is a consonant.” The former is true; the latter is false.)

Example 3.39 establishes that the proposition [∀xS:P(x)]∨[∀xSP(x)] isn’t true foreverymeaning of the predicateP, but it may be true forsomemeanings. For example, ifP(x) is the predicatex2 ≥ 0 andSis the setR, then this disjunction is true (because∀xR:x2≥0 is true).

The challenge of proofs in predicate logic

The remainder of this section states some theorems of predicate logic, along with an initial discussion of how we might prove that they’re theorems. (Aproof of a statement is simply a convincing argument that the statement is a theorem.) Much of the rest of the book will be devoted to developing and writing proofs of theorems like these, and Chapter 4 will be devoted exclusively to some techniques and strategies for proofs.

(This section will preview some of the ideas we’ll see there.) Some theorems of pred- icate logic are summarized in Figure 3.23; we’ll prove a few of them here, and you’ll return to some of the others in the exercises.

xS:hP(x)∨ ¬P(x)i

¬hxS:P(x)ihxS:¬P(x)i De Morgan’s Laws (quantified form)

¬hxS:P(x)ihxS:¬P(x)i

hxS:P(x)ihxS:P(x)i if the set S is nonempty

x:P(x) Vacuous quantification

¬∃x:P(x)

xS:hP(x)Q(x)i hxS:P(x)ihxS:Q(x)i

xS:hP(x)Q(x)i hxS:P(x)ihxS:Q(x)i

xS:h

P(x)Q(x)i

hxS:P(x)i

hxS:Q(x)i

xS:hP(x)Q(x)i hxS:P(x)ihxS:Q(x)i hxS:P(x)Q(x)ihxS:P(x)ihxS:Q(x)i hx∈ {yS:P(y)}:Q(x)i hxS:P(x)Q(x)i hx∈ {yS:P(y)}:Q(x)i hxS:P(x)Q(x)i

ϕhxS:P(x)ihxS:ϕP(x)i if x does not appear as a free variable inϕ ϕhxS:P(x)ihxS:ϕP(x)i if x does not appear as a free variable inϕ

Figure 3.23: A few theorems involving quantification.

While predicate logic allows us to express claims that we couldn’t state without quantifiers, that extra expressiveness comes with a cost! For a quantifier-free proposi- tion (like all propositions in Sections 3.2–3.3), there is a straightforward—if tedious—

algorithm to decide whether a given proposition is a tautology: first, build a truth table for the proposition; and, second, check to make sure that the proposition is true in every row. It turns out that the analogous question for predicate logic is much more difficult—in fact,impossibleto solve in general: there’s no algorithm that’s guaranteed to figure out whether a given fully quantified expression is a theorem! Demonstrating that a statement in predicate logic is a theorem will require you tothinkin a way that demonstrating that a statement in propositional logic is a tautology did not.

Taking it further: See the discussion on p. 346 for more about the fact that there’s no algorithm guaran- teed to determine whether a given proposition is a theorem. The absence of such an algorithm sounds like bad news; it means that proving predicate-logic statements is harder, because you can’t just plug- and-chug into a simple algorithm to figure out whether a given statement is actually always true. But this fact is also precisely the reason that creativity plays a crucial role in proofs and in theoretical com- puter science more generally—and why, arguably, proving things can be fun! (For me, this difference is exactly why I find Sudoku less interesting than crossword puzzles: when there’s no algorithm to solve a problem, we have to embrace the creative challenge in attacking it.)

3.4.4 A Few Examples of Theorems and Proofs

In the rest of this section, we will see a few further theorems of predicate logic, with proofs. As we’ve said, there’s no formulaic approach to prove these theorems; we’ll need to employ a variety of strategies in this endeavor.

Negating quantifiers: a first example

Suppose that your egomaniacal, overconfident partner from Intro CS wanders into the lab and saysFor any array A that you give me, partner, my implementation of insertion sort correctly sorts A.You know, though, that your partner is wrong. (You spot a bug in his egomaniacal code.) What would that mean? Well, you might reply, gently but firmly:There’s an array A for which your implementation of insertion sort does not correctly sort A.The equivalence that you’re using is a theorem of predicate logic:

Example 3.40 (Negating universal quantifiers)

Let’s prove the equivalence you’re using to debunk your partner’s claim:

¬xS:P(x)xS:¬P(x).

Perhaps the easiest way to view this claim is as a quantified version of the tautology

¬(pq)⇔ ¬p∨ ¬q, which was one of De Morgan’s Laws from propositional logic. If we think of∀xS:P(x) asP(x1)∧P(x2)∧P(x3)∧ · · ·, then

¬xS:P(x) ∼∼∼ ¬P(x1)P(x2)∧P(x3)∧ · · ·

¬P(x1)∨ ¬P(x2)∨ ¬P(x3)∨ · · ·

∼∼

∼ ∃xSP(x),

where the second line follows by the propositional version of De Morgan’s Laws.

There is something slightly more subtle to our claim because the setSmight be infinite, but the idea is identical. If there’s anaSsuch thatP(a) = False, then

xS :¬P(x) is true (becauseais an example) and∀xS:P(x) is false (becausea is a counterexample). And if everyaShasP(a) = True, then∃xS:¬P(x) is false and∀xS:P(x) is true.

The analogous claim for the negation of∃xS:P(x) is also a theorem:

Example 3.41 (Negating existential quantifiers) Let’s prove that this claim is a theorem, too:

¬xS:P(x)

xSP(x).

To see that this claim is true for an arbitrary predicateP, we start with the claim from Example 3.40, but using the predicateQ(x) := ¬P(x). (Note thatQis also a predicate—so Example 3.40 holds forQtoo!) Thus we know that

¬xS:Q(x)xS:¬Q(x), and, becausepq≡ ¬p⇔ ¬q, we therefore also know that

xS:Q(x)⇔ ¬xS:¬Q(x).

ButQ(x) is just¬P(x) and¬Q(x) is justP(x), by definition ofQ, and so we have ∀xS:¬P(x)⇔ ¬xS:P(x).

Thus we’ve now shown that the desired claim is true for any predicateP, so it is a theorem.

All implies some: a proof of an implication

The entirety of Chapter 4 is devoted to proofs and proof techniques; there’s lots more there about how to approach proving or disproving new claims. But here we’ll preview a particularly useful proof strategy for proving an implication, and use it to establish another theorem of predicate logic. Here’s the method of proof:

Dalam dokumen Untitled - Digital Library Univ STEKOM (Halaman 133-137)