1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution...

12
1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability in a “mechanical” way. p A, ¬ p B ( A p )∨ ( B – ¬ p ) p , ¬ p [] To prove a wff is valid: negate the wff and convert it to CNF; write down the fundamental disjunctions as premises; use resolution to find a false statement. Example. Prove (p q) (q r) (p r) is a tautology. Solution. Negate the wff and transform it into CNF: (¬ p q) q r) p ¬ r. Now write down the fundamental disjunctions as premises to start the proof. 1. ¬ p q P 2. ¬ q r P 3. p P 4. ¬ r P 5. q 1, 3, R Resolution for Propositional Logic The resolution rule for propositions is shown to the right, where A and B are disjunctions of literals. Notation: A p denotes A with all occurrences of p removed and B – ¬ p denotes B with all occurrences of ¬ p removed. Notation: We denote false by a box []. In applying resolution, we assume A B B A and A [] A. If A and B are false, then the rule is simplified as shown.

Transcript of 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution...

Page 1: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

1

Section 9.1 Automatic ReasoningRecall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability in a “mechanical” way.

p ∨ A, ¬ p ∨ B (A – p) ∨ (B – ¬ p)

p, ¬ p[]

To prove a wff is valid: negate the wff and convert it to CNF; write down the fundamental disjunctions as premises; use resolution to find a false statement.

Example. Prove (p q) (q r) (p r) is a tautology.Solution. Negate the wff and transform it into CNF: (¬ p q) (¬ q r) p ¬ r. Now write down the fundamental disjunctions as premises to start the proof.

1. ¬ p q P2. ¬ q r P3. p P4. ¬ r P 5. q 1, 3, R6. r 2, 5, R7. [] 4, 6, R

QED.

Resolution for Propositional LogicThe resolution rule for propositions is shown to the right, where A and B are disjunctions of literals. Notation: A – p denotes A with all occurrences of p removed and B – ¬ p denotes B with all occurrences of ¬ p removed.

Notation: We denote false by a box []. In applying resolution, we assume A B B A and A [] A. If A and B are false, then the rule is simplified as shown.

Page 2: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

2

Example/Quiz. Use resolution to prove that the following wff (an application of constructive dilemma) is a tautology.

(A B) (A C D) (B E F) (C D) (E F).

Solution. Negate the wff and transform the result into CNF.

(A B) (¬ A C ) (¬ A D) (¬ B E) (¬ B F) (¬ C ¬ D) (¬ E ¬ F).

1. A B P2. ¬ A C P3. ¬ A D P4. ¬ B E P

5. ¬ B F P 6. ¬ C ¬ D P 7. ¬ E ¬ F P8. ¬ A ¬ C 3, 6, R

9. ¬ B ¬ F 4, 7, R 10. ¬ B ¬ B 5, 9, R11. ¬ A ¬ A 2, 8, R12. B 1, 11, R13. [] 10, 12, R

QED.Question. Are there proofs that use less than 13 steps.Answer: Probably not since each of the 7 premises must be used. Why?

Page 3: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

3

Resolution for First-Order LogicExample (to Show the Idea). Suppose some proof contains the following two lines, where we assume that the wffs (called clauses) are universally closed.

1. p(a, x) q(x, y, a) P 2. ¬ p(x, b) r(x, y, b) P

To apply resolution to the wffs on lines 1 and 2 several actions need to be taken:

Change the names so the clauses have distinct variable names.In this case, we’ll keep line 1 as it is and change the names on line 2.

3. ¬ p(v, b) r(v, w, b) P

Unify (i.e., match) p(a, x) on line 1 and p(v, b) on line 3 to get a substitution (i.e., a set of bindings) = {v/a, x/b}. Apply to clauses on lines 1 and 3.

p(a, b) q(b, y, a)¬ p(a, b) r(a, w, b)

Apply resolution to the transformed wffs.

4. q(b, y, a) r(a, w, b) 1, 3, R, = {v/a, x/b}

So we need to discuss three things for first-order resolution.

The clausal form of wffs

Unification of atoms

The inference rule.

Page 4: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

4

Clausal FormsA clause is a disjunction of literals. (Recall a literal is an atom or its negation.)A clausal form is the universal closure of a conjunction of clauses.Notation. A clausal form is also represented as a set of its clauses.

Example. The clausal form

x y (p(x) (q(x, y) ¬ r(x)) (¬ p(x) s(y)))

Is represented by the set

{p(x), q(x, y) ¬ r(x), ¬ p(x) s(y)}.

Not every wff is equivalent to a clausal form. For example, the wff x p(x) is not equivalent to a clausal form. But we have the following result of Skolem, which is sufficient for resolution.

Skolem’s AlgorithmEvery wff can be associated with a clausal form in which the two are either both satisfiable or both unsatisfiable.

• Construct the prenex CNF for the wff.• Replace all occurrences of each free variable by a new constant.• Eliminate the existential quantifiers by Skolem’s Rule:

A. If x W(x) is not inside the scope of a universal quantifier, then replace x W(x) by W(c) for a new constant c.

B. If x W(x) is inside the scope of x1 ...xn, then replace x W(x) by W(ƒ(x1, …, xn)) for a new function symbol ƒ.

Page 5: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

5

Quiz. Find a clausal form for each wff.

1. x A(x).2. x y B(x, y).3. x y z C(x, y, z).4. x y z D(x, y, z).

Answers.

1. A(c).2. x B(x, ƒ(x)).3. x y C(x, y, g(x, y)).4. x D(x, ƒ(x), g(x)).

Example/Quiz. Find a clausal form for the wff

y x p(x, y) z (q(x) r(z)).

Solution: Put the wff in prenex CNF.

y x p(x, y) z (q(w) r(z)) (renamed) ¬ y x p(x, y) z (q(w) r(z)) (removed ) y x ¬ p(x, y) z (q(w) r(z)) (moved ¬ inside) y (x ¬ p(x, y) z (q(w) r(z))) (moved y outside) y x z (¬ p(x, y) (q(w) r(z))) (moved x and z outside) y x z ((¬ p(x, y) q(w)) (¬ p(x, y) r(z))) (constructed CNF)

(replace free variable w by constant c)

y x z ((¬ p(x, y) q(c)) (¬ p(x, y) r(z)))

Apply Skolem’s Rule to eliminate x and z.

y ((¬ p(ƒ(y), y) q(c)) (¬ p(ƒ(y), y) r(g(y))).

So there are two clauses in the clausal form, which can be denoted by the set

{¬ p(ƒ(y), y) q(c), ¬ p(ƒ(y), y) r(g(y)}.

Page 6: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

6

Substitutions and Unification

A binding of a variable x to a term t is denoted x/t and it means replace x by t.

Applying a Binding to an Expression

If x/t is a binding and E is an expression, then E(x/t) denotes the expression obtained from E by replacing all free occurrences of x with t.

Examples. p(x, y, z)(x/y) = p(y, y, z)

p(x, y, z)(y/ƒ(z)) = p(x, ƒ(z), z)

A substitution is a finite set of bindings with distinct numerators. (Use lowercase greek letters for substitutions.)

Example. = {x/y, y/ƒ(z)} and = {y/ƒ(a), z/b} are substitutions.

Applying a Substitution to an Expression or a Set of Expressions

If is a substitution and E is an expression, then E denotes the expression obtained from E by simultaneously applying the bindings in to E.

Example. If = {x/y, y/ƒ(z)}, then

p(x, y, z) = p(x, y, z){x/y, y/ƒ(z)} = p(y, ƒ(z), z).

If S is a set of expressions, then S is the set of expresisons obtained from S by applying to each expression of S.

Example. If = {x/y, y/ƒ(z)} and S = {p(x, y), q(y, g(z))}, then

S = {p(x, y), q(y, g(z))}= {p(y, ƒ(z)), q(ƒ(z), g(z))}.

Page 7: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

7

Composing Substitutions If and are two substitutions, then the composition is applied to an expression E by

E() = (E).

We can calculate by applying it to an atom that contains all the numerator variables of the two substitutions. Then collect the bindings that result from the application.

Example. Let = {x/y, y/ƒ(z)} and = {y/ƒ(a), z/b}. Since the numerator variables are x, y, and z, we calculate

p(x, y, z)() = (p(x, y, z)) = p(y, ƒ(z), z)) = p(ƒ(a), ƒ(b), b).

So = {x/ƒ(a), y/ƒ(b), z/b}.

We can also calculate by the following procedure, where = {xi/ti} and = {yi/si}. • Construct {xi/(ti}.• Delete any xi/xi from Step 1.• Delete yi/si from if yi is a numerator of . is the union of the substitutions from Steps 2 and 3.

Example. Let = {x/y, y/ƒ(z)} and = {y/ƒ(a), z/b}. Calculate . Step 1. Construct {x/y, y/ƒ(z)} = {x/ƒ(a), y/ƒ(b)}.Step 2. No deletions. So no changes from Step 1.Step 3. Delete y/ƒ(a) from (because y is a numerator of ) to obtain {z/b}.Step 4. The union of sets from Steps 2 and 3 give = {x/ƒ(a), y/ƒ(b), z/b}.

Properties of Composition

= and = = where = {}.

Page 8: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

8

A unifier of a set S of expressions is a substitution such that S is a singleton set.

Example. {x/a} is a unifier of {p(x), p(a)} because {p(x), p(a)}{x/a} = {p(a)}.

Example/Quiz. What are some unifiers of S = {p(x, a), p(y, z)}?

Answer: Since a is a constant, any unifier must include the binding z/a. A unifier might also include x/y or y/x. So two unifiers of S are {x/y, z/a} and {y/x, z/a} because

S{x/y, z/a} = {p(y, a)} and S{y/x, z/a} = {p(x, a)}.

Notice also that {x/t, y/t, z/a} is a unifier of S for any term t because

S{x/t, y/t, z/a} = {p(t, a)}.

A most general unifier (mgu) of a set S of expressions is a unifier of of S such that any other unifier of S can be written as = for some substitution .

Example. Let S = {p(x, a), p(y, z)} from the preceding example. The unifiers of S are

{x/y, z/a} and {y/x, z/a} and {x/t, y/t, z/a} for any term t.

The unifier {x/y, z/a} is an mgu for S because

{y/x, z/a} = {x/y, z/a}{y/x} and {x/t, y/t, z/a} = {x/y, z/a}{y/t}.

Quiz. Continue the example and show that, {y/x, z/a} is an mgu of S.

Proof: {x/y, z/a} = {y/x, z/a}{x/y} and {x/t, y/t, z/a} = {y/x, z/a}{x/t}. QED.

Quiz. Continue the example and show for a constant c that {x/c, y/c, z/a} is not an mgu of S.

Proof: Assume, BWOC, that {x/c, y/c, z/a} is an mgu. Then {x/y, z/a} = {x/c, y/c, z/a} for some substitution . But {x/c, y/c, z/a} contains the subset {x/c, y/c, z/a}, so it can’t equal {x/y, z/a}. This contradiction tells us that {x/c, y/c, z/a} is not an mgu. QED.

Page 9: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

9

Unification Algorithms

Robinson:

For a finite set S of atoms find whether S has an mgu.

1. k := 0; 0 := ; go to Step 2.

2. If Sk is a singleton then stop with mgu k

Otherwise construct Dk (set of terms in leftmost position of disagreement); go to Step 3.

3. If Dk has a variable v and a term t such that v does not occur in t thenk+1 := k{v/t}; k := k + 1; go to Step 2.

Otherwise stop (S is not unifiable).

Example. Trace the algorithm for S = {p(x, h(x, g(y)), y), p(x, h(a, z), b)}.

1. k := 0; 0 := .2. S0 = S = {p(x, h(x, g(y)), y), p(x, h(a, z), b)} is not a singleton; D0 = {x, a}.

3. 1 := 0{x/a} = {x/a}; k := 1.

2. S1 = {p(a, h(a, g(y)), y), p(a, h(a, z), b)} is not a singleton; D1 = {g(y), z}.

3. 2 := 1{z/g(y)} = {x/a, z/g(y)}; k := 2.

2. S2 = {p(a, h(a, g(y)), y), p(a, h(a, g(y)), b)} is not a singleton; D2 = {y, b}.

3. 3 := 2{y/b} = {x/a, z/g(b), y/b}; k := 3.

2. S3 = {p(a, h(a, g(b)), b)} is a singleton; stop with mgu 3 = {x/a, z/g(b), y/b}.

Quiz. Apply the algorithm to S = {p(x), p(ƒ(x))}.

Answer. S is not unifiable because in the set D0 = {x, ƒ(x))} x occurs in ƒ(x).

Page 10: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

10

Martelli-Montanari:To see whether two atoms A and B have an mgu, form the set {A = B} and apply the following rules repeatedly in any order. (ƒ and g are either function or predicate symbols.)

1. Replace ƒ(s1, …, sn) = ƒ(t1, …, tn) with equations s1 = t1, …, sn = tn.

2. If ƒ(s1, …, sn) = g(t1, …, tm) with ƒ ≠ g or m ≠ n, then stop with failure.3. Delete x = x.4. Replace t = x, where t is not a variable, with x = t.5. If x = t and x does not occur in t, apply {x/t} to the other equations that contain x.6. If x = t and t is not a variable and x occurs in t, then stop with failure.

If there is no failure and the rules cannot be applied, then transform {xi = ti} to mgu {xi/ti}.

Example. Trace the algorithm for A = p(x, h(x, g(y)), y) and B = p(x, h(a, z), b).

{p(x, h(x, g(y)), y) = p(x, h(a, z), b)} ({A = B}){x = x, h(x, g(y)) = h(a, z), y = b} (Rule 1){h(x, g(y)) = h(a, z), y = b} (Rule 3){x = a, g(y) = z, y = b} (Rule 1){x = a, z = g(y), y = b} (Rule 4){x = a, z = g(b), y = b} (Rule 5)

Done. The mgu is {x/a, z/g(b), y/b}.

Quiz. Apply the algorithm to the two atoms p(x, x) and p(y, ƒ(y)).Solution: {p(x, x) = p(y, ƒ(y))} and Rule 1 gives {x = y, x = ƒ(y)}.

Apply Rule 5 to get {x = y, y = ƒ(y)}. Apply Rule 6 to get failure.

Page 11: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

11

Resolution Rule (R)Given the following two clauses.

L1 … Lk C and ¬ M1 … ¬ Mn D,

where Li and Mi are atoms and C and D are disjunctions of other literals. Assume also that

1. The clauses have distinct sets of variable names (rename if necessary).

2. is the mgu of {L1, …, Lk, M1, …, Mn}.

3. N = L1, where {L1, …, Lk, M1, …, Mn} = {N}.Then we have:

L1 ∨ L ∨ Lk ∨ C, ¬ M1 ∨ L ∨ ¬ Mn ∨ D(Cθ – N) ∨ (Dθ – ¬ N)

.

Example. Given the two clauses in the following proof segment

k. p(a, y) p(a, z) q(x, y, z) P

k + 1. ¬ p(w, ƒ(b)) r(w, v, g(w)) ¬ p(a, ƒ(b)) P

These two clauses have the form L1 L2 C and ¬ M1 D.The two clauses have distinct sets of variables. The set of atoms {p(a, y), p(a, z), p(w, ƒ(b))} has mgu = {w/a, y/ƒ(b), z/ƒ(b)}. Notice that {p(a, y), p(a, z), p(w, ƒ(b))} = {p(a, ƒ(b))}.So the resolution rule can be applied to the two clauses to obtain the resolvant:

k + 2. q(x, ƒ(b), ƒ(b)) r(a, v, g(a)) k, k + 1, R, {w/a, y/ƒ(b), z/ƒ(b)}.

Page 12: 1 Section 9.1 Automatic Reasoning Recall that a wff W is valid iff ¬ W is unsatisfiable. Resolution is an inference rule used to prove unsatisfiability.

12

To prove a wff is valid: negate the wff and convert it to clausal form; write down the clauses as premises; use resolution to find a false statement.

Example/Quiz. Use resolution to prove the following wff is valid.

x (y p(x, y) z q(x, z) y (p(x, y) q(x, y))).

Solution: Negate the wff: ¬ x (y p(x, y) z q(x, z) y (p(x, y) q(x, y))). Convert it to clausal form:

¬ x (y p(x, y) z q(x, z) w (p(x, w) q(x, w))) (renamed variables)

x ((y p(x, y) z q(x, z)) w (¬ p(x, w) ¬ q(x, w))) (removed and moved ¬ right)

x w ((y p(x, y) z q(x, z)) ¬ p(x, w) ¬ q(x, w)) (moved w left)

x w y z ((p(x, y) q(x, z)) ¬ p(x, w) ¬ q(x, w)) (moved y and z left)

x y z ((p(x, y) q(x, z)) ¬ p(x, ƒ(x)) ¬ q(x, ƒ(x))) (removed w by Skolem)

So the set of clauses is {p(x, y) q(x, z), ¬ p(x, ƒ(x)), ¬ q(x, ƒ(x)))}.Now do a resolution proof by making each the three clauses a premise (rename to get distinct variable names).

1. p(x, y) q(x, z) P2. ¬ p(u, ƒ(u)) P3. ¬ q(w, ƒ(w)) P4. q(u, z) 1, 2, R, {x/u, y/ƒ(u)}5. [] 3, 4, R, {w/u, z/ ƒ(u)}

QED.