Announcements Project 1 underway... discuss ideas with TAs check out wiki Second midterm Friday You may bring on one letter-sized sheet of paper with anything written or drawn or... anywhere on it. It will cover up to as much as we get to today (including unification and top-down proofs with variables, equality and possibly negation as failure) c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 1 / 31
Review Prolog extends propositional logic program by having predicates, constants, variables and function symbols. Triples are universal representations of relations, and are the basis for RDF URIs provide constants that have standard meanings Ontologies define the meaning of symbols used in information systems. Unification is used to extend the top-down proof procedure to include structured atoms (predicates, functions, constants, variables). c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 2 / 31
Clicker Question What does this triple mean: cir, rdfs:domain, http://schema.org/newspaper A cir is a property that applies only to newspapers B cir is a newspaper C cir is a property where some of the values are newspapers D cir is a property which apples to newspapers, and perhaps other things c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 3 / 31
Clicker Question For the atoms foo(x, X, Z) and foo(y, T, W ) The substitution {X /Y, T /Y, W /Y, Z/Y } A is a most general unifier B is a unifier, but not a most-general unifier C is not a unifier c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 4 / 31
Clicker Question For the atoms foo(x, X, Z) and foo(y, T, W ) The substitution {X /V, T /V, Y /V, W /M, Z/M} A is a most general unifier B is a unifier, but not a most-general unifier C is not a unifier c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 5 / 31
Clicker Question For the atoms foo(x, X, Z) and foo(y, b, W ) A most general unifier is A {Y /X, X /b, Z/W } B {X /b, Y /b, Z/X } C {X /b, Y /b, Z/T, W /T } D There are most general unifiers, but none of A-C are most general unifiers. E There are no most general unifiers c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 6 / 31
Top-down Proof procedure A generalized answer clause is of the form yes(t 1,..., t k ) :- a 1, a 2,..., a m, where t 1,..., t k are terms and a 1,..., a m are atoms. The SLD resolution of this generalized answer clause on a 1 with the clause a :- b 1,..., b p, where a i and a have most general unifier θ, is (yes(t 1,..., t k ) :- b 1,..., b p, a 2,..., a m )θ. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 7 / 31
Top-down Proof Procedure To solve query?b with variables V 1,..., V k : Set ac to generalized answer clause yes(v 1,..., V k ) :- B while body of ac is not empty do Suppose ac is yes(t 1,..., t k ) :- a 1, a 2,..., a m select leftmost atom a i in the body of ac choose clause a :- b 1,..., b p in KB Rename all variables in a :- b 1,..., b p Let θ be the most general unifier of a i and a. Fail if they don t unify Set ac to (yes(t 1,..., t k ) :- b 1,..., b p, a 2,..., a m )θ end while. Answer is V 1 = t 1,..., V k = t k c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 8 / 31
Example append([], L, L). append([h T ], A, [H R]) :- append(t, A, R).? append([a, b, c], [1, 2, 3], L). yes(l) :- append([a, b, c], [1, 2, 3], L). yes([a R1]) :- append([b, c], [1, 2, 3], R1). yes([a, b R2]) :- append([c], [1, 2, 3], R2). yes([a, b, c R3]) :- append([], [1, 2, 3], R3). yes([a, b, c, 1, 2, 3]) :-. Answer is L = [a, b, c, 1, 2, 3] c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 9 / 31
Clicker Question For the answer clause yes(obj) :- noun([sam, likes, cs312], T 2, Obj), vp(t 2, T 3, Obj) and the clause in the knowledge base noun([x R], R, X ) :- person(x ) What is the most general unifier used in the top-down derivation A {R/[likes, cs312], X /sam, T 2/R, Obj/X } B {R/[cs312], X /[sam, likes], T 2/[cs312], Obj/sam} C {R/[likes, cs312], X /sam, T 2/[likes, cs312], Obj/sam} D It doesn t unify as there is no vp in the clause. E None of the above c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 10 / 31
Clicker Question For the answer clause yes(obj) :- noun([sam, likes, cs312], T 2, Obj), vp(t 2, T 3, Obj). and the clause in the knowledge base noun([x R], R, X ) :- person(x ). What is the resulting answer clause (up to renaming of variables): A yes(x ) :- person(x ), vp(t 2, T 3, X ). B yes(sam) :- person(sam), vp([likes, cs312], T 3, sam). C yes(obj) :- noun([sam, likes, cs312], T 2, Obj), person(obj), vp(t 2, T 3, Obj). D yes(obj) :- person(obj), vp(t 2, T 3, Obj). E the proof fails here c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 11 / 31
Clicker Question What is not a reason for renaming variables in the clause when resolving: A The system can forget about the names of variables when compiling clauses B To prevent name clashes for variables in the query and the clauses in the knowledge base C One clause in a program may be used multiple times in a proof with different substitutions D An answer may require multiple different instances of variables E These are all reasons c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 12 / 31
Today Proofs with variables (cont) Equality, unique names assumption Negation as failure c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 13 / 31
Unification with function symbols Consider a knowledge base consisting of one fact: lt(x, s(x )). Should the following query succeed??- lt(y, Y ). What does the top-down proof procedure give? Solution: variable X should not unify with a term that contains X inside. Occurs check E.g., X should not unify with s(x ). Simple modification of the unification algorithm, which Prolog does not do! c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 14 / 31
Complete Knowledge Assumption Often you want to assume that your knowledge is complete. Example: assume that a database of what students are enrolled in a course is complete. We don t want to have to state all negative enrolment facts! The definite clause language is monotonic: adding clauses can t invalidate a previous conclusion. Under the complete knowledge assumption, the system is non-monotonic: adding clauses can invalidate a previous conclusion. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 15 / 31
Equality Equality is a special predicate symbol with a standard domain-independent intended interpretation. Suppose interpretation I = D, φ, π. t 1 and t 2 are ground terms then t 1 = t 2 is true in interpretation I if t 1 and t 2 denote the same individual. That is, t 1 = t 2 if φ(t 1 ) is the same as φ(t 2 ). t 1 t 2 when t 1 and t 2 denote different individuals. Example: D = {,, }. φ(phone) =, φ(pencil) =, φ(telephone) = What equalities and inequalities hold? phone = telephone, phone = phone, pencil = pencil, telephone = telephone pencil phone, pencil telephone Equality does not mean similarity! c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 16 / 31
Equality Constants/Terms a b c d Individuals f(a) e c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 17 / 31
Properties of Equality Equality is: Reflexive: X = X Symmetric: if X = Y then Y = X Transitive: if X = Y and Y = Z then X = Z For each n-ary function symbol f f (X 1,..., X n ) = f (Y 1,..., Y n ) if X 1 = Y 1 and and X n = Y n. For each n-ary predicate symbol p p(x 1,..., X n ) if p(y 1,..., Y n ) and X 1 = Y 1 and and X n = Y n. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 18 / 31
Unique Names Assumption Suppose the only clauses for enrolled are enrolled(sam, cs222) enrolled(chris, cs222) enrolled(sam, cs873) To conclude enrolled(chris, cs873), what do we need to assume? All other enrolled facts are false Inequalities: sam chris cs873 cs222 The unique names assumption (UNA) is the assumption that distinct ground terms denote different individuals. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 19 / 31
Inequality as a subgoal What should the following query return?? X 4. What should the following query return?? X 4, X = 7. What should the following query return?? X 4, X = 4. Prolog has 3 different inequalities that differ on examples like these: \== \= dif() They differ in cases where there are free variables, and terms unify but are not identical. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 20 / 31
Completion of a knowledge base: propositional case Suppose the rules for atom a are a b 1.. a b n. equivalently a b 1... b n. Under the Complete Knowledge Assumption, if a is true, one of the b i must be true: a b 1... b n. Thus, the clauses for a mean a b 1... b n c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 21 / 31
Clark Normal Form The Clark normal form of the clause p(t 1,..., t k ) B. is the clause where p(v 1,..., V k ) W 1... W m V 1 = t 1,..., V k = t k, B. V 1,..., V k are k variables that did not appear in the original clause W 1,..., W m are the original variables in the clause. When the clause is an atomic clause, B is true. Often can be simplified by replacing W V = W p(w ) with P(V ). c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 22 / 31
Clark normal form For the clauses student(mary). student(sam). student(x ) undergrad(x ). the Clark normal form is student(v ) V = mary. student(v ) V = sam. student(v ) X V = X undergrad(x ). c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 23 / 31
Clark s Completion Suppose all of the clauses for p are put into Clark normal form, with the same set of introduced variables, giving p(v 1,..., V k ) B 1.. p(v 1,..., V k ) B n. which is equivalent to p(v 1,..., V k ) B 1... B n. Clark s completion of predicate p is the equivalence V 1... V k p(v 1,..., V k ) B 1... B n If there are no clauses for p, the completion results in V 1... V k p(v 1,..., V k ) false Clark s completion of a knowledge base consists of the completion of every predicate symbol along the unique names assumption. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 24 / 31
Completion example p q, \+ r. p s. q \+ s. r \+ t. t. s w. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 25 / 31
Completion Example Consider the recursive definition: passed each([ ], St, MinPass). passed each([c R], St, MinPass) passed(st, C, MinPass), passed each(r, St, MinPass). In Clark normal form, this can be written as passed each(l, S, M) :- L = [ ]. passed each(l, S, M) C R L = [C R], passed(s, C, M), passed each(r, S, M). Here we renamed the variables as appropriate. Thus, Clark s completion of passed each is L S M passed each(l, S, M) L = [ ] C R L = [C R], passed(s, C, M), passed each(r, S, M). c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 26 / 31
Clark s Completion of a KB Clark s completion of a knowledge base consists of the completion of every predicate. The completion of an n-ary predicate p with no clauses is p(v 1,..., V n ) false. You can interpret negations in the body of clauses. \+ a means a is false under the complete knowledge assumption. \+ a is replaced by a in the completion. This is negation as failure. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 27 / 31
Defining empty course Given database of: course(c) that is true if C is a course enrolled(s, C) that is true if student S is enrolled in course C. Define empty course(c) that is true if there are no students enrolled in course C. Using negation as failure, empty course(c) can be defined by empty course(c) course(c), has enrollment(c) enrolled(s, C). \+ has enrollment(c). The completion of this is: C empty course(c) course(c), has enrollment(c). C has enrollment(c) S enrolled(s, C). c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 28 / 31
Top-Down negation as failure proof procedure If the proof for a fails, you can conclude \+ a. Failure can be defined recursively: Suppose you have rules for atom a: a b 1. a b n If each body b i fails, a fails. A body fails if one of the conjuncts in the body fails. Note that you need finite failure. Example p :- p. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 29 / 31
Floundering p(x ) \+ q(x ), r(x ). q(a). q(b). r(d).?- p(x ). What is the answer to the query? How can a top-down proof procedure find the answer? Delay the subgoal until it is bound enough. Sometimes it never gets bound enough floundering. c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 30 / 31
Problematic Cases p(x ) :- \+ q(x ) q(x ) :- \+ r(x ) r(a)?- p(x ). What is the answer? What does delaying do? How can this be implemented? c D. Poole and A. Mackworth 2017 CPSC 312 2017 Lecture 17 31 / 31