Predicate Calculus 2 Outline Unification definitions algorithm Formal

  • Slides: 22
Download presentation
Predicate Calculus 2 Outline: Unification: definitions, algorithm Formal interpretations and satisfiability Horn clauses and

Predicate Calculus 2 Outline: Unification: definitions, algorithm Formal interpretations and satisfiability Horn clauses and PROLOG CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 1

Unification Predicate calculus rules are sometimes so general that we need to create specializations

Unification Predicate calculus rules are sometimes so general that we need to create specializations of them in order to perform resolution. Suppose we have the rule If x is a working automobile, then x has an engine. P(x) Q(x) and we have the fact Tim’s Chevy is a working automobile P(a) These cannot immediately be resolved because P(x) and P(a) don’t quite match. They must be “unified. ” CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 2

Modus Ponens and Resolution P Q P ----Q Modus ponens is a special case

Modus Ponens and Resolution P Q P ----Q Modus ponens is a special case of resolution: P v Q P ----Q CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 3

Modus Ponens in the Predicate Calculus P(a) Q(a) P(a) ----Q(a) But we have P(x)

Modus Ponens in the Predicate Calculus P(a) Q(a) P(a) ----Q(a) But we have P(x) Q(x) So we create a substitution instance of it: P(a) Q(a) using the substitution { a/x } CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 4

Substitutions A substitution is a set of term/variable pairs. e. g. , { a/x,

Substitutions A substitution is a set of term/variable pairs. e. g. , { a/x, f(a)/y, w/z } Each element of the set is an elementary substitution. A particular variable occurs at most once on the right-hand side of any elementary subst. in a substitution. { a/x, b/x } is not an acceptable substitution. The empty set is an acceptable substitution. If E is a term or a formula of the predicate calculus, and S is a substitution, then S(E) is the result of applying S to E, i. e. , replacing each variable of S that occurs in E by the corresponding term in S. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 5

Unifiers Given a pair of literals L 1 and L 2, if S is

Unifiers Given a pair of literals L 1 and L 2, if S is a substitution such that S(L 1) = S(L 2) or S(L 1) = S(L 2), then S is a unifier for L 1 and L 2. Example: L 1 = P(x, f(a)) L 2 = P(b, y) S = { b/x, f(a)/y } S(L 1) = P(b, f(a)) = S(L 2) Therefore S is a unifier for L 1 and L 2. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 6

The Occurs Check A unifier may not contain an elementary substitution of the form

The Occurs Check A unifier may not contain an elementary substitution of the form f(x)/x and may not cause an indefinite recursion. In general the term in a term/variable pair may not include that variable. P(x) and P(f(x)) cannot be unified, since f(x)/x is illegal. P(y, f(y)) and P(f(x), y) cannot be unified, since S = { f(x)/y, f(y)/x } leads to an indefinite recursion. Testing whether a variable appears in its corresponding term is called the “occurs check”. Some automated reasoning systems do not perform the occurs check in order to save time. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 7

Generality of Unifiers Some pairs of literals may have more than one possible unifier.

Generality of Unifiers Some pairs of literals may have more than one possible unifier. P(x), P(y) is unified by each of { x/y }, { y/x }, { z/x, z/y }, { a/x, a/y}, { f(a)/x, f(a)/y } etc. Suppose S 1 and S 2 are unifiers for L 1 and 12. Then S 1(P 1) = S 1(P 2) or S 1(P 1) = ~S 1(P 2) S 2(P 1) = S 2(P 2) or S 2(P 1) = ~S 2(P 2) S 2 is less general than S 1 if no S 3 exists such that S 3(S 2(P 1)) = S 1(P 1). { a/x, a/y } is less general than { y/x }. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 8

Most General Unifiers A unifier S 1 for L 1 and L 2 is

Most General Unifiers A unifier S 1 for L 1 and L 2 is a most general unifier (MGU) for L 1 and L 2 provided that for any other unifier S 2 of L 1 and L 2 there exists a substitution S 3 such that S 3(S 1(L 1)) = S 2(L 1). S 1 = { y/x } is a most general unifier for P(x), P(y). S 2 = { f(a)/x, f(a)/y } is not a MGU for P(x), P(y). S 3 = { f(a)/y } S 3(S 1(P(x))) = P(f(a)) = S 2(P(x)). CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 9

Finding a Most-General Unifier 1. Given literals L 1 and L 2, place a

Finding a Most-General Unifier 1. Given literals L 1 and L 2, place a cursor at the left end of each. Skip any negation sign. If the predicate symbols do not match, return NOT-UNIFIABLE. 2. Let S = { }. 3. Move the cursors right to the next term in each literal. If there are no terms left, return S as a MGU. Let t 1 and t 2 be the terms. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 10

Finding an MGU (Cont. ) 4 a. If t 1 = t 2, go

Finding an MGU (Cont. ) 4 a. If t 1 = t 2, go to Step 3. 4 b. Otherwise, if either t 1 or t 2 is a variable (call it v and call the other term t), then attempt to add t/v to S (see below). 4 c. Otherwise if t 1 and t 2 both begin with function symbols, and these symbols are the same, move the cursors to the first argument of these symbols and go to step 4 a. 4 d. Otherwise, return NOT-UNIFIABLE. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 11

Finding an MGU (Cont. ) When trying to add t/v to S, apply {

Finding an MGU (Cont. ) When trying to add t/v to S, apply { t/v } to each term in S. If this results in any elementary substitution whose term includes its variable, return NOTUNIFIABLE. Otherwise, replace each elementary substitution in S by the result of applying { t/v } and add t/v itself to S. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 12

Example L 1: P(a, f(x, a)) L 2: P(a, f(g(y), y)) S: { }

Example L 1: P(a, f(x, a)) L 2: P(a, f(g(y), y)) S: { } S: { g(y)/x } S: { g(a)/x, a/y } CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 13

Logical Inferences Per Second LIPS are sometimes used to describe the performance of a

Logical Inferences Per Second LIPS are sometimes used to describe the performance of a logical reasoning system. Can mean the number of successful unification operations per second. 1 successful unification 1 successful resolution step. Note: some unifiers are trivial to compute, yet there is no upper bound on the size of a unifier. Also, discovering that two literals are not unifiable can be arbitrarily costly. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 14

Formal Interpretations An interpretation for a given formula W consists of the following: A

Formal Interpretations An interpretation for a given formula W consists of the following: A domain D of elements that can be referred to by terms. E. g. , D = (0, 1, 2, . . . } An assignment that maps each constant symbol of W to an element of D. For each n-ary function symbol of W a mapping from n-tuples of elements of D to single elements of D. For each n-ary predicate symbol of W a mapping from ntuples of elements of D to {T, F}. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 15

Example of Interpretation Let W = ( x) (P(a) Q(x, a) ) An interpretation

Example of Interpretation Let W = ( x) (P(a) Q(x, a) ) An interpretation for W: D = { apple, peach } { a = apple } mapping for constants {} mappings for functions { P(apple) = T, P(peach) = T; mappings for predicates Q(apple, apple) = T, Q(apple, peach) = T, Q(peach, apple) = T, Q(peach, peach) = T } CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 16

Satisfiability and Models A formula W is satisfiable iff there exists some interpretation of

Satisfiability and Models A formula W is satisfiable iff there exists some interpretation of W that make W true. A formula W is unsatisfiable iff there does NOT exist any interpretation of W that make W true. Then W is inconsistent. W is a contradiction. If every interpretation of W satisfies W (makes W true), then W is a tautology. If I is an interpretation for W that satisfies W , then I is a model for W. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 17

Another Interpretation Let W = ( x) (P(a) Q(x, a) ) An interpretation for

Another Interpretation Let W = ( x) (P(a) Q(x, a) ) An interpretation for W: D = { 0, 1, 2, . . . } {a=0} {} { P(n) iff n = 0; Q(m, n) iff n > m. } mapping for constants mappings for functions mappings for predicates Note that Q(x, x). This interpretation fails to satisfy W. It’s not a model for W. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 18

The Basis of Proof by Resolution is used to prove that a given set

The Basis of Proof by Resolution is used to prove that a given set of clauses is inconsistent. (i. e. , it cannot have a model). Each time a resolvent is formed, it is added to the set of clauses. This does not change the consistency of the set. However, if the null clause is ever added to the set, then it becomes very obvious that the set is inconsistent. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 19

Horn Clauses: The basis for Logic Programming A Horn clause is a clause in

Horn Clauses: The basis for Logic Programming A Horn clause is a clause in which at most one literal is unnegated Examples of Horn clauses: P P V Q Q Q V R P V Q V R [] Examples of non-Horn clauses: PVQ P V ~Q V R CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 20

Horn Clauses: Goal-oriented form P V Q V R Standard mathematical form (Q R)

Horn Clauses: Goal-oriented form P V Q V R Standard mathematical form (Q R) P Equivalent conditional form P (Q V R) Goal-oriented form p : - q, r. Edinburgh PROLOG syntax head : - body. goal : - subgoal 1, subgoal 2, . . . , subgoal. N. CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 21

Prolog: Horn Clauses + Resolution + Backward Chaining grandparent(X, Y) : - parent(X, Z),

Prolog: Horn Clauses + Resolution + Backward Chaining grandparent(X, Y) : - parent(X, Z), parent(Z, Y). parent(X, Y) : - father(X, Y). parent(X, Y) : - mother(X, Y). father(abe, bev). mother(bev, carl). mother(bev, mary). ? - grandmother(A, B). A = abe, B = carl; A = abe, B = mary; no CSE 415 -- (c) S. Tanimoto, 2008 Predicate Calculus II 22