1 / 14

Logic Programming

Logic Programming. Robert Kowalski’s equation: Algorithm = Logic + Control Definite logic program: A  B 1 , B 2 , …, B m (program clause) head body  A 1 , A 2 , …, A n (goal clause). Logic Programming. SLD-resolution: Resolvent:

tamah
Download Presentation

Logic Programming

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 • Robert Kowalski’s equation: Algorithm = Logic + Control • Definite logic program: A  B1, B2, …, Bm (program clause) head body  A1, A2, …, An (goal clause)

  2. Logic Programming • SLD-resolution: • Resolvent:  A1, …, Ak-1, Ak, Ak+1, …, An A  B1, B2, …, Bm  (A1, …, Ak-1, B1, B2, …, Bm, Ak+1, …, An) Ak = A SL-resolution for Definite clauses - SL = Linear resolution with Selection function

  3. Logic Programming • SLD-resolution: • SLD-derivation: G0 = G,G1, G2, …, Gn C1, C2, …, Cn 1, 2, …, n (mgu’s) i+1Ci+1 = i+1Gi • SLD-refutation: Gn = empty • Computed answer: n… 21

  4. Logic Programming • SLD-resolution: • Soundness: if n… 21 is a computed answer, then P |=n… 21G • Completeness: if P |=G, then there exists a computed answer s such that  = s for some  Example: p(X,Z)  q(X,Y), p(Y,Z) p(X,X) q(a,b)

  5. Logic Programming SLD-tree:  p(X,b)  q(X,Y), p(Y,b) {X/b} success  p(b,b)  q(b,U), p(U,b) failure {X/b} success Each branch is an SLD-derivation

  6. Logic Programming • PROLOG (Alain Colmerauer 1972): • Only Horn sentences are acceptable • The occur-check is omitted from the unification  unsound Example: test  p(X,X) p(X,f(X)) • Backward chaining with depth-first search  incomplete Example: p(X,Y)  q(X,Y) p(X,X) q(X,Y)  q(Y,X)

  7. Logic Programming Infinite SLD-tree:  p(X,b)  q(X,b) {X/b} success  q(b,X)  q(X,b)

  8. Logic Programming • PROLOG (Alain Colmerauer 1972): • Unsafe cut  incomplete Example: A  B, C  A B  D, !, E D   B, C  D, !, E, C  !, E, C • Negation as failure:  P if fails to prove P

  9. Theorem Provers • Accepts full first-order logic • Keeps control distinct from logic A  B  C A  C  B

  10. Production Systems • Working memory: contains a set of positive literals with no variables • Rule memory: contains a set of reference rules of the form p1p2 … act1 act2 … pi are literals acti are actions to delete or add elements to the working memory

  11. Production Systems • Forwarding chaining in each cycle: • Match phase:computes the subset of rules whose left-hand side is satisfied by the current contents of the working memory • Conflict resolution phase: decides which of the rules to be executed • Act phase: executes the actions in the chosen rules

  12. Production Systems • Example: • Working memory: {A(1), A(2), B(2), B(3), B(4), C(5)} • Rule memory: A(x)  B(x)  C(y)  add D(x) A(x)  B(y)  D(x)  add E(x) A(x)  B(x)  E(x)  delete A(x)

  13. Production Systems RETE network D A=D add E A B A=B C add D C(5) D(2) A(1), A(2) B(2), B(3), B(4) A(2) B(2) E delete A

  14. Exercises • In Russell & Norvig’s AIMA (Chapter 10): 10.2, 10.4

More Related