1 / 19

Logic Programming Part 2: Semantics

Logic Programming Part 2: Semantics. James Cheney CS 411. Resolution. Resolution principle: If A 1 ... A n  B and B,C 1 ,...,C m  D Then A 1 ... A n ,C 1 ,...,C m  D Proof search: To prove B, try to prove B  False Apply resolution until LHS is empty. Unification.

jirair
Download Presentation

Logic Programming Part 2: Semantics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Logic Programming Part 2: Semantics James Cheney CS 411

  2. Resolution • Resolution principle: • If A1 ... An B and B,C1,...,Cm  D • Then A1 ... An,C1,...,Cm  D • Proof search: • To prove B, try to prove B  False • Apply resolution until LHS is empty.

  3. Unification • In Prolog, logic variables X,Y,Z can be substituted by any other term • Unification: Algorithm for finding substitution making two terms equal

  4. Examples • f(X,[Y,Z]) == f(g(Z),W) • unifies with X = g(Z), W = [Y,Z] • f(X,g(X)) == f(2,g(Y)) • Doesn’t iunify: X = 2 and X = g(Y) impossible

  5. More Examples • f(X) == X • Doesn’t unify! • X = f(X) = f(f(X)) = ... • f(X,Y) == f(Y,g(X)) • Doesn’t unify! (Why?)

  6. Example f f X Y Y g X

  7. Example f f X Y Y g X

  8. Example X Y Y g X

  9. Example Answer: X = Y Y g X

  10. Example Answer: X = Y Y g Y

  11. Example Answer: X = Y Y = g(Y)

  12. Example Answer: X = Y Y = g(Y) Problem: In equation Y = f(Y), Y occurs circularly. There is no finite term satisfying this equation. Checking that this is not the case is called the occurs check. For efficiency reasons, PROLOG skips this check.

  13. Robinson’s Algorithm • Consider a general unification problem P = t1 == u1, t2 == u2, ... • Reduce the problem by replacing one equation with a set of equations • Succeed if all equations reducible, else fail.

  14. Robinson’s Algorithm • Two constants unify if they are equal. c == c, P  P Else fail.

  15. Robinson’s Algorithm • Two function applications unify if the symbols are equal, and the corresponding arguments unify. f(t1,...tn) == f(u1,...,un), P  t1 == u1,... tn == un, P • Must have equal number of arguments

  16. Robinson’s Algorithm • Two variables unify if they are the same. X == X, P  P

  17. Robinson’s Algorithm • Otherwise, a variable X unifies with a term t provided X does not occur in t. X = t, P  P[t/X] (if X not in FV(t)) • Proceed by substituting t for X in P.

  18. Operational Semantics • In general, we have • a program P = {clauses}, • a goal G = {atomic goals}, • and a substitution q : VarTerm • Base case: If there are no goals then succeed (P,{},q)  Yes q

  19. Operational Semantics • Inductive case: Suppose state is (P,G,q) with G nonempty. • Pick a p(t1,...,tn) in G. • Assume clause p(u1,...,un) :- G’ in P. • Assume q’ unifies p(t1,...,tn) and p(u1,...,un) • Then: (P,G,q)  (P,q’G’, q’q).

More Related