Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Hedman. A First Course in Logic, 2004 (Oxford)

.pdf
Скачиваний:
140
Добавлен:
10.08.2013
Размер:
7.17 Mб
Скачать

120

Proof theory

time, but it is more systematic than the method described here. Herbrand theory will be useful in proving that the resolution we define works.

3.4 Resolution for first-order logic

We now define resolution for first-order logic. Let ϕ be any sentence in SNF. Then ϕ has the form x1 x2 · · · xmϕ0 where ϕ0 is a conjunction of disjunctions of literals. In particular, ϕ0 is quantifier-free, and so it can be viewed as a formula of propositional logic that is in CNF. Let C(ϕ0) denote the set of all clauses in the CNF formula ϕ0. We define C(ϕ) to be C(ϕ0). That is, C(ϕ) = {C1, . . . , Cm} where Ci is the set of all literals occurring in the ith disjunction.

For example, if ϕ is the sentence

= x y z((P (x, y) ¬Q(x, z)) ((R(x, y, z) ¬P (f (x, y), z)),

then C(ϕ) is the set

{{P (x, y), ¬Q(x, z)}, {R(x, y, z), ¬P (f (x, y), z)}}.

Note that a sentence ϕ in SNF uniquely determines C(ϕ). Conversely, by Proposition 1.67, C(ϕ0) determines ϕ0 up to equivalence. It follows that C(ϕ) determines ϕ up to equivalence. That is, if C(ϕ) = C(ψ) for sentences ϕ and ψ in SNF, then ϕ ≡ ψ. For this reason, we need not distinguish between formulas in SNF and sets of clauses.

We want to say what it means for a clause R to be a resolvent of two clauses C1 and C2. As in propositional logic, a resolvent of C1 and C2 is a consequence of the conjunction of C1 and C2. Before giving a formal definition for resolvents, we consider a couple of examples.

Example 3.29 Let C1 = {¬Q(x, y), P (f (x), y)} and C2 = {¬P (f (x), y), R(x, y, z)}. The clause R = {¬Q(x, y), R(x, y, z)} is a resolvent of C1 and C2. This works the same way as in propositional logic. Since the literal P (f (x), y) occurs in one clause and the negation of this same literal occurs in the other, the resolvent can be formed by taking the union of C1 and C2 less P (f (x), y) and ¬P (f (x), y).

Example 3.30 Let C1 = {¬Q(x, y), P (f (x), y)} and C2 = {¬P (z, y), R(x, y, z)}. Then we cannot directly find a resolvent of C1 and C2 as in the previous example. Let C2 be the clause obtained by substituting f (x) for z in the clause C2. That is, C2 = {¬P (f (x), y), R(x, y, f (x))}. We make two observations. First, we can easily find a resolvent of C1 and C2, namely R = {¬Q(x, y), R(x, y, f (x))}. Second, note that C2 is a consequence of C2. This is because the SNF sentence represented by C2 asserts that the formula ¬P (z, y) R(x, y, z) holds for every

Proof theory

121

x, y, and z. In particular, this formula holds in the specific case where z = f (x). That is, C2 implies C2. Hence, R, which is a consequence of {C1, C2}, is also a consequence of {C1, C2}. We define resolvents so that R is a resolvent of C1 and C2 (and of C1 and C2 as well). We diagram this situation as follows:

 

C2

C1

C

 

2

 

 

 

 

 

 

R

So prior to finding a resolvent, we must first make substitutions for variables to make certain literals look the same. In the previous example, we did a substitution that made P (f (x), y) and P (z, y) identical. This process is called unification and we postpone the formal definition of “resolvent” until after we have discussed unification in detail.

3.4.1 Unification. Let L = {L1, . . . , Ln} be a set of literals. We say L is unifiable if there exist variables x1, . . . , xm and terms t1, . . . , tm such that substituting ti for xi (for each i) makes each literal in L look the same. We denote such a substitution by sub = (x1/t1, x2/t2, . . . , xm/tm). For any sentence ϕ in SNF, we denote the result of applying this substitution to ϕ by ϕsub.

For example, if sub = (x/w, y/f (a), z/f (w)) and ϕ = {¬Q(x, y), R(a, w, z)}, then ϕsub = {¬Q(w, f (a)), R(a, w, f (w))}.

If L is a set of literals, then Lsub denotes the set of all Lisub such that Li L. So L is unifiable if and only if there exists a substitution sub such that Lsub contains only one literal. If this is the case, we call sub a unifier for L and say that sub unifies L.

Example 3.31 Let L = {P (f (x), y), P (f (a), w)}. Let sub1 = (x/a, y/w) and sub2 = (x/a, y/a, w/a). Then both sub1 and sub2 unify L. We have Lsub1 = {P (f (a), w)} and Lsub2 = {P (f (a), a)}. Note that, by making another substitution, we can get Lsub2 from Lsub1. Namely, if sub3 = (w/a), then sub1sub3 (sub1 followed by sub3) has the same e ect as sub2. However, we cannot generate Lsub1 from Lsub2 since Lsub2 has no variables. So, in some sense, the unifier sub1 is better for our purposes. It is more versatile. “Our purposes” will be resolution, and if we choose sub2 as our unifier instead of sub1, we might needlessly limit our options.

Definition 3.32 Let L be a set of literals. The substitution sub is a most general unifier for L if it unifies L and for any other unifier sub for L, we have subsub = sub .

122

Proof theory

In Example 3.31, sub1 is the most general unifier. As we pointed out, this is the best unifier for our purposes.

Proposition 3.33 A finite set of literals is unifiable if and only if it has a most general unifer.

There are two possiblities for a finite set L of literals, either it is unifiable or it is not. Proposition 3.33 asserts that if L is unifiable, then it automatically has a most general unifier. We prove this by exhibiting an algorithm that, given L as input, outputs “not unifiable” if no unifier exists and otherwise ouputs a most gerneal unifier for L. The algorithm runs as follows.

The unification algorithm

Given: a finite set of literals L.

Let L0 = L and sub0 = .

Suppose we know Lk and subk. If Lk contains just one literal, output “sub0sub1 · · · subk is a most general unifier for L.”

Otherwise, there exist Li and Lj in Lk such that the nth symbol of Li di ers from the nth symbol of Lj (for some n). Suppose n is least in this regard. If the nth symbol of Li is a variable v and the nth symbol of Lj is the first symbol of a term t that does not contain v or vice versa (with Li and Lj reversed) then:

Let subk+1 = (v/t) and Lk+1 = Lksubk+1.

If any of the hypotheses of the previous sentence do not hold, output “L is not unifiable.”

We must verify that this algorithm works. First we give a demonstration.

Example 3.34 Let L = {R(f (g(x)), a, x), R(f (g(a)), a, b), R(f (y), a, z)}. First set L0 = L and sub0 = .

As we read each of the three literals in L0 from left to right, we see that each begins with “R(f (. . . ”, but then there is a discrepency. Whereas the second literal continues with “g(a)”, the third literal has “y”. We check that one of these two terms is a variable and the other is a term that does not contain that variable. This is the case and so we let

sub1 = (y/g(a)), and

L1 = L0sub1 = {R(f (g(x)), a, x), R(f (g(a)), a, b), R(f (g(a)), a, z)}.

We note that L1 contains more than one literal and proceed. Now all literals begin with R(f (g(. . . , but then the first literal has “x” and the second has “a”.

Proof theory

123

One of these is a variable and the other is a term that does not contain that variable, and so we let

sub2 = (x/a), and

L2 = L1sub2 = {R(f (g(a)), a, a), R(f (g(a)), a, b), R(f (g(a)), a, z)}.

The set L2 still contains more than one literal, and so we continue. Each literal in L2 looks the same up to R(f (g(a)), a, . . . , but then the first literal has “a” and the second has “b.” Neither of these is a variable, and so the algorithm concludes with output “L is not unifiable.”

If the algorithm outputs “not unifiable,” it is for one of two reasons. One is illustrated by the previous example. Here we had a discrepency between two literals that did not involve a variable. Where one literal had the constant a, the other had b. Clearly, this cannot be reconciled by a substitution and the set is, in fact, not unifiable. The other possibility is that the dicrepency involves a variable and a term, but the variable occurs in the term. For example, the set {P (x, y), P (x, f (y))} is not unifiable. No matter what we substitute for the variables x and y, the second literal will have one more occurrence of f than the first literal. The algorithm, noting a discrepency occurs with y and f (y), will terminate with “not unifiable” because the variable y occurs in the term f (y). Both reasons for concluding “not unifiable” are good reasons. If the algorithm yields this output, then the set must not be unifiable.

Note that, when applied to the set L from Example 3.31, this algorithm outputs sub1 as the most general unifier. So, in these examples, the algorithm works. We want to show that it always works.

If the set L is a finite set, then only finitely many variables occur in L. It follows that the algorithm when applied to L must terminate in a finite number of steps. If it terminates with “L is not unifiable,” then, as we have already mentioned, L must not be unifiable. Otherwise, the algorithm outputs “sub0sub1 · · · subk is a most genral unifier.” We must show that, when this statement is the output, it is true.

The algorithm outputs “sub0sub1 · · · subk is the most genral unifier” only if Lk = Lsub0sub1 · · · subk contains just one literal. If this is the output, then sub0sub1 · · · subk is a unifier. We must show that it is a most general unifier.

Let sub be any other unifier for L. We know that sub0sub = sub because sub0 is empty. Now suppose that we know sub0 · · · submsub = sub for some m, 0 ≤ m < k. Then Lmsub = Lsub0 · · · submsub = Lsub = {L}. That is, since sub unifies L, it also unifies Lm.

Suppose subm+1 is (x/t). By the definition of the algorithm, t must be a term in which the variable x does not occur. Moreover, for some literals Li and Lj in Lm, x occurs in the nth place of Li and t begins in the nth place of Lj

124

Proof theory

(for some n). Since sub unifies Lm, sub must do the same thing to both x and t. That is, xsub = tsub . It follows that subm+1sub = (x/t)sub = sub . By induction, we have sub0 · · · subm+1sub = sub for all m < k. In particular, sub0 · · · subksub = sub and sub0 · · · subk is the most general unifier for L.

3.4.2 Resolution. We now define resolution for first-order logic. Recall that for any literal L, L is the literal defined by L = ¬L or ¬L = L.

Definition 3.35 Let C1 and C2 be two clauses. Let s1 and s2 be any substitutions such that C1s1 and C2s2 have no variables in common. Let L1, . . . , Lm C1s1 and L1, . . . , Ln C2s2 be such that L = {L1, . . . , Lm, L1, . . . , Ln} is unifiable. Let sub be a most general unifier for L.

Then R = [(C1s1 − {L1, . . . , Lm}) (C2s2 − {L1, . . . , Ln})]sub is a resolvent of C1 and C2.

Let ϕ be a sentence in SNF. Then ϕ = {C1, . . . , Cn} for some clauses C1, . . . , Cn.

Let Res(ϕ) = {R| R is a resolvent of some Ci and Cj in ϕ}. Let Res0(ϕ) = ϕ, and Resn+1 = Res(Resn(ϕ)).

Let Res (ϕ) = n Resn(ϕ).

The same notation was used in propositional logic. However, unlike the propositional case, Res (ϕ) may be an infinite set. To justify this notation and the definition of “resolvent” we need to show that Res (ϕ) if and only if ϕ is unsatisfiable. First we look at an example.

Example 3.36 Let C1 = {Q(x, y), P (f (x), y)}, and C2 = {R(x, c), ¬P (f (c), x), ¬P (f (y), h(z))}.

Suppose we want to find a resolvent of C1 and C2. First, we need to rename some variables since x and y occur in both C1 and C2. Let s1 = (x/u, y/v). Then C1s1 = {Q(u, v), P (f (u), v)} which has no variables in common with C2.

Second, note that C1s1 contains a literal of the form P ( , ) and C2 contains literals of the form ¬P ( , ). Namely, P (f (u), v) is in C1s1 and ¬P (f (c), x) and ¬P (f (y), h(z)) are in C2. Let

L = {P (f (u), v), P (f (c), x), P (f (y), h(z))}.

By applying the unification algorithm, we see that L is unifiable and sub = (u/c, y/c, v/h(z), x/h(z)) is a most general unifier. We conclude that C1 and C2 have resolvent

R= [(C1s1 − {P (f (u), v)}) (C2 − {¬P (f (c), x), ¬P (f (y), h(z))})]sub

= {Q(u, v), R(x, c)}sub = {Q(c, h(z)), R(h(z), c)}.

Proof theory

125

We verify that the resolvent R from the previous example is in fact a consequence of C1 and C2. Recall that C1 and C2 represent sentences in SNF.

C1 represents x y(Q(x, y)) P (f (x), y)), and

C2 represents x y z(R(x, c)) ¬P (f (c), x) ¬P (f (y), h(z)).

Suppose C1 and C2 hold (in some structure). Then, since these sentences are universal, they hold no matter what we plug in for the variables. In particular,

C1s1sub ≡ z(Q(c, h(z)) P (f (c), h(z))), and

C2sub ≡ z(R(h(z), c)) ¬P (f (c), h(z))

both hold. That is, C1s1sub is a consequence of C1 and C2sub is a consequence of C2. Put another way,

C1s1sub ≡ z(¬Q(c, h(z)) → P (f (c), h(z))), and

C2sub ≡ z(P (f (c), h(z)) → R(h(z), c)).

From these two sentences, we can deduce

z(¬Q(c, h(z)) → R(h(z), c))

which is equivalent to

z(Q(c, h(z)) R(h(z), c))

which is the sentence represented by R. Hence, R is a consequence of the conjunction of C1 and C2.

In a similar manner, we can show that any resolvent of any two clauses is necessarily a consequence of the conjunction of the two clauses. It follows that if Res (ϕ), then ϕ must be unsatisfiable. Conversely, suppose ϕ is unsatisfiable. We need to show that Res (ϕ).

At the end of the previous section we showed that ϕ is unsatisfiable if and only if the set E(ϕ) is unsatisfiable. Recall that E(ϕ) is the set of all sentences obtained by replacing each variable of ϕ with a term from the Herbrand universe. These sentences can be viewed as sentences of propositional logic. Suppose that C1 and C2 are in E(ϕ) and R is a resolvent of C1 and C2 in the sense of propostional logic. Then there are some clauses C1 and C2 of ϕ such that C1 = C1sub1 and C2 = C2sub2. In the following lemma we show that there exists a resolvent R of C1 and C2 (in the sense od first-order logic) and a substitution sub such that Rsub = R . So, essentially, this lemma says that any R that can be derived from E(ϕ) using propositional resolution can also be derived from ϕ using first-order resolution.

126

Proof theory

Lemma 3.37 (Lifting lemma) Let ϕ be a sentence in SNF. If R Res(E(ϕ)), then there exists R Res(ϕ) such that such that Rsub = R for some substitution sub .

This is called the “Lifting lemma” because we are “lifting” the resolvent R from propositional logic to first-order logic.

Let ϕ be a sentence in SNF and let C1 and C2 be two clauses of ϕ. Let s1 be a substitution such that C1s1 and C2 have no variables in common. Let C1 and C2 in E(ϕ) be such that C1s1sub1 = C1 and C2sub2 = C2 for some substitutions sub1 and sub2. Let R be a resolvent (in propositional logic sense) of C1 and C2. This setup can be diagramed as follows:

C1

 

 

 

 

 

 

C1s1

C2

sub1

 

 

sub2

C

1

C

2

 

 

 

 

 

R

The lemma says that if this setup holds, then there exists a resolvent R of C1s1 and C2 (in the sense of first-order logic) such that Rsub = R for some substitution sub . This conclusion can be diagramed as follows:

C1

C1s1

C2

R

R

In the first diagram, the resolvent is taken as in propositional logic. In the second diagram, the resolvent R is as in Definition 3.35. The vertical lines in each diagram refers to a substitution. The lemma can be summarized as saying “if the first diagram holds, then so does the second diagram.”

Proof of Lemma Supose the first diagram holds. Then there must exist some literal L C1 such that L C2 and R = (C1 − {L}) (C2 − {L}). This is the definition of resolvent for propositional logic.

Proof theory

127

Let sub = sub1sub2. Since C1s1 and C2 have no variables in common,

C1s1sub = C1s1sub1 = C1 and C2sub = C2sub2 = C2.

Let L1 = {L1, . . . , Ln} be the set of all Li in C1s1 such that Lisub = L. Likewise, let L2 = {L1, . . . , Lm} be the set of all Li in C2 such that Lisub = L. We have the following diagram:

 

 

 

L1

C1s1

C2

 

L2

 

sub

 

 

 

 

 

 

 

 

 

 

 

 

sub

 

 

 

L

C

C

 

 

L

 

 

 

 

 

 

1

2

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

R

 

 

 

 

 

 

Let L =

{

 

, . . . ,

 

 

, L

, . . . , L

(that is L = L¯

 

 

 

). This set is unifiable

L

L

n

1

L

 

1

 

 

1

 

m}

 

 

2

 

 

 

since Lsub = {L}. Let sub be a most general unifier for L. Then we can apply Definition 3.35 to find the following resolvent of C1 and C2:

R = [(C1s1 L1) (C2 L2)]sub.

Referring to the second diagram of the lemma, we see that it remains to be shown that R can be obtained from R by a substitution. We complete the proof of the lemma by showing that Rsub = R . By applying sub we get

Rsub = [(C1s1 L1) (C2 L2)]subsub .

Since sub is a unifier for L and sub is a most general unifier for L, we know subsub = sub . So we have

Rsub = [(C1s1 L1) (C2 L2)]sub

= (C1s1sub − L1sub ) (C2sub − L2sub ) = (C1 − {L}) (C2 − {L}) = R .

Corollary 3.38 Let ϕ be a sentence in SNF. If C Res (E(ϕ)), then there exists C Res (ϕ) and a substitution sub such that Csub = C .

Proof If C Res (E(ϕ)), then C Resn(E(ϕ)) for some n. We prove the corollary by induction on n. If n = 0, then C E(ϕ). Then, by the definition of E(ϕ), C is obtained by substituting variable free terms in for the variables of some C ϕ.

For the induction step, we utilize the Lifting lemma. Suppose that for some m, each clause of Resm(E(ϕ)) is obtained from some clause of Res (ϕ) via substitution. Let ϕ˜ Res (ϕ) be such that every clause of Resm(E(ϕ)) comes from some clause in ϕ˜. Then Resm(E(ϕ)) E(ϕ˜). If C Resm+1(E(ϕ)), then C Res(E(ϕ˜)). By the Lifting lemma, there is some C Res(ϕ˜) such that Csub = C for some substitution sub . Since ϕ˜ Res (ϕ), C Res (ϕ).

128

Proof theory

In particular, if Res (E(ϕ)), then there exists some C Res (ϕ) such that Csub = for some substitution sub . But this is only possible if C = . So if Res (E(ϕ)), then Res (ϕ). We conclude that if ϕ is unsatisfiable, then Res (ϕ). We have shown that the notion of resolution defined in this section works. We state this as a theorem.

Theorem 3.39 Let ϕ be a sentence in SNF. Then ϕ is unsatisfiable if and only if Res (ϕ).

3.5 SLD-resolution

One purpose of resolution is to provide a method of proof that can be done by a computer. Toward this aim, we refine resolution in this section. Our goal is to find a version of resolution that can be completely automated. The advantage of resolution over other formal proof systems is that it rests on a single rule. Resolution proofs may not be the most succinct. They will not lend insight as to why, say, a sentence ϕ is unsatisfiable. The benefit of resolution is precisely that it does not require any insight. To show that ϕ is unsatisfiable, we can blindly compute Res (ϕ) until we find . However, this method is not practical. If is in Res (ϕ), then calculating the clauses in Res (ϕ) one-by-one in no particular order is not an e cient way of finding it. The first two theorems of this section show that it is not necesssary to compute all of Res (ϕ). We show that we only need to compute resolvents R of clauses C1 and C2 that have certain forms. We refer to C1 and C2 as the parents of R.

Definition 3.40 N -resolution requires that one parent contain only negative literals.

We look at an example from propositional logic. Let

ϕ = {{A, B}, {¬A, C}, {¬B, D}, {¬C}, {¬D}}.

We show that ϕ is unsatisfiable using N -resolution.

{¬A, C}

{¬C}

 

 

 

 

 

 

 

 

 

{A, B}

{¬A}

{¬B, D}

{¬D}

 

 

 

 

 

 

 

{B}

{¬B}

 

 

 

 

 

 

 

 

 

 

Note that each resolvent has a parent that contains only negative literals.

Proof theory

129

Definition 3.41 Linear resolution requires that one parent be the resolvent from the previous step.

The word “linear” refers to the diagram. The previous diagram is not linear because it has two “branches.” The following diagram illustrates a linear resolution for this same example.

{¬A, C} {¬C}

{A, B} {¬A}

{¬B, D} {B}

{¬D} {D}

So we can derive the emptyset from ϕ either by N -resolution or linear resolution. The next two theorems show that this is true for any unsatisfiable ϕ. That is, to show that ϕ is unsatisfiable, we can restrict our computations to N -resolution or linear resolution.

Theorem 3.42 Let ϕ be a sentence in SNF. Then ϕ is unsatisfiable if and only if can be derived from ϕ by N -resolution.

Proof If can be derived by N -resolution, then Res (ϕ) and so ϕ is unsatisfiable. Conversely, suppose ϕ is unsatisfiable.

By the Lifting lemma, it su ces to prove this theorem for propositional logic. This requires some explanation. If can be derived from E(ϕ) by N -resolution, then we can “lift” this to a derivation of from ϕ. By “lift” we mean that the former can be obtained from the latter via substitutions. Note that a clause C contains only negative literals if and only if Csub does (for any substitution sub). So an N -resolution derivation in propositional logic lifts to an N -resolution derivation in first-order logic.

Having said this, we assume ϕ is an unsatisfiable set of sentences of propositional logic in CNF. By compactness, we may assume ϕ is finite. We showed thatRes (ϕ) in Proposition 1.74. Following that same proof, we show that can be derived by N -resolution.

Let ϕ = {C1, . . . , Ck}. We assume that none of the Cis is a tautology (otherwise we just throw away these clauses and show that can be derived