140 likes | 390 Views
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:
E N D
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)
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
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… 21
Logic Programming • SLD-resolution: • Soundness: if n… 21 is a computed answer, then P |=n… 21G • 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)
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
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)
Logic Programming Infinite SLD-tree: p(X,b) q(X,b) {X/b} success q(b,X) q(X,b)
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
Theorem Provers • Accepts full first-order logic • Keeps control distinct from logic A B C A C B
Production Systems • Working memory: contains a set of positive literals with no variables • Rule memory: contains a set of reference rules of the form p1p2 … act1 act2 … pi are literals acti are actions to delete or add elements to the working memory
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
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)
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
Exercises • In Russell & Norvig’s AIMA (Chapter 10): 10.2, 10.4