Download
logic programming n.
Skip this Video
Loading SlideShow in 5 Seconds..
Logic Programming PowerPoint Presentation
Download Presentation
Logic Programming

Logic Programming

225 Vues Download Presentation
Télécharger la présentation

Logic Programming

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Logic Programming Jacques Robin

  2. A unifying metaphor for computer science Syntax: Pure Prolog abstract syntax Full Prolog abstract syntax Concrete syntax Declarative semantics: Open x closed world hypothesis Unique name hypothesis Clark’s completion Least Herbrand model Operational semantics Lifted SLD resolution and backward chaining Limitations Of ISO Prolog Of SLD resolution and pure backward chaining Tabled logic programming SLG resolution for pure Prolog High order logic programming HiLog abstract syntax HiLog first-order semantics Constraint logic programming Limitations of CSP CLP engine architeture CLP abstract syntax Operational semantics Other extensions Roteiro

  3. Declarative Programming Formal Software Specification Logic Programming Automated Reasoning Intelligent Databases Formal Logic Theory Logic Programming: a Versatile Metaphor

  4. Logic Programming: Key Ideas

  5. Logic programming vision • Single language with logic-based declarative semantics that is: • A Turing-complete, general purpose programming language • A versatile, expressive knowledge representation language to support deduction and other reasoning services useful for intelligent agents (abduction, induction, constraint solving, belief revision) • Data definition, query and update language for databases with built-in inference capabilities • One tool solves all philosophy: • Any computation = resolution + unification + search • Programming = declaring logical axioms (Horn clauses) • Running the program = query about theorems provable from declared axioms • Algorithmic design entirely avoided (single, built-in control structure) • Same language for formal specification (modeling) and implementation • Same language for model checking and code testing

  6. Prolog • First and still most widely used logic programming language • Falls short to fulfill the vision in many respect: • Many imperative constructs with no logical declarative semantics • No commercial deductive database available • Most other logic programming languages both: • Extend Prolog • Fulfills better one aspect of the logic programming vision • Basis for aborted attempt to Japanese to fully revolutionize all computing from ground up in the 80s

  7. Definite Query +connective =  Definite Clause +connective =  Definite Logic Program +connective =  Pure Prolog: abstract syntax arg * * 0..1 * Pure Prolog Term Pure Prolog Atom arg * predicate body head Functional Term Function-Free Term functor Symbol clauses Variable Numerical Symbol c11 (...,Xk1,...) :- p11(...,Xi1,...), ... , pm1(...,Xj1,...). ... c1n (...,Xkn,...) :- p1n(...,Xin,...), ... , pmn(...,Xjn,...). parent(al,jim)  parent(jim,joe  anc(A,D)  parent(A,D)  anc(A,D)  parent(A,P)  anc(P,D)

  8. Prolog Literal +connective = naf Full Prolog Query +connective =  Full Prologl Clause +connective =  Full Prolog Atom Full Prolog Program +connective =  Full Prolog 0..1 arg * arg Prolog Literal Full Prolog Term * body head Functional Term predicate Function-Free Term functor * Symbol Built-in Symbol User-Defined Symbol Variable Built-in Imperative Symbol Built-in Logical Symbol • Semantics of full Prolog: • Cannot be purely logic-based • Must integrate algorithmic ones Numerical Symbol Meta-Programming Predicate Symbol I/O Predicate Symbol Search Customization Predicate Symbol Program Update Predicate Symbol

  9. Pure Prolog program declarative formal semantics • Declarative, denotational, intentional: • Clark’s transformation to CFOL formula • First-order formula semantically equivalent to program • Declarative, denotational, extentional, model-theoretic: • Least Herbrand Model • Intersection of all Herbrand Models • Conjunction of all ground formulas that are deductive consequences of program

  10. Classical First-Order Predicate Logic: NoUnique Name Assumption (UNA): two distinct symbols can potentially be paraphrases to denote the same domain entity Open-World Assumption (OWA): If KB |≠ Q but KB |≠ Q , the truth value of Q is considered unknown Ex: KB: true  core(ai)  true  core(se)  core(C)  offered(C,T)  true  offered(mda,fall) Q: true  offered(mda,spring) OWA necessary for monotonic, deductively sound reasoning: If KB |= T then A, KB  A |= T Logic Programming: UNA: two distinct symbols necessarily denote two distinct domain entities Closed-World Assumption (CWA): If KB |≠ Q but KB |≠ Q , the truth value of Q is considered false Ex: ?- offered(mda,spring) fail CWA is a logically unsound form of negatively abductive reasoning CWA makes reasoning inherently non-monotonic as one can have:KB |= T but KB  A |≠ Tif the proof KB |= T included steps assuming A false by CWA Motivation: intuitive, representational economy, consistent w/ databases CFOL x Prolog Semantic Assumptions

  11. Transform Pure Prolog Program P into semantically equivalent CFOL formula comp(P) Same answer query set derived from P (abductively) than from FP (deductively) Example P:core(se). core(ai). offered(mda,fall). offered(C,T) :- core(C). ?- offered(mda,spring) no ?- Naive semantics naive(P):C,T true  core(ai)  true  core(se)  true  offered(mda,fall)  core(C)  offered(C,T)naive(P) |≠ offered(mda,spring) Clark’s completion semantics comp(P): C,T,C1,T1 (core(C1)  (C1=ai C1=se)) (offered(C1,T1)  (C1=mda  T1=fall)  (C,T (C1=C T1=T core(C)))) (ai=se)  (ai=mda)  (ai=fall)  (se=fall)  (se=mda)  (mda=fall) Fp |= offered(mda,spring) Clark’s completion semantics

  12. Clark’s transformation • Axiomatizes closed-world and unique name assumptions in CFOL • Start from naive Horn formula semantics of pure Prolog program • Partition program in clause sets, each one defining one predicate (i.e., group together clauses with same predicate c(t1, ..., tn) as conclusion) • Replace each such set by a logical equivalence • One side of this equivalence contains c(X1, ..., Xn) where X1, ..., Xn are fresh universally quantified variables • The other side contains a disjunction of conjunctions, one for each original clause • Each conjunction is either of the form: • Xi = ci ...  Xj = ci, if the original clause is a ground fact • Yi ... Yj Xi = Yi  ...  Xj = Yj  p1( ...)  ...  pn( ... ) if the original clause is a rule with body p1( ...)  ...  pn( ... ) containing variables Yi ... Yj • Join all resulting equivalences in a conjunction • Add conjunction of the form (ci = cj) for all possible pairs (ci,cj) of constant symbols in pure Prolog program

  13. SLD Resolution • SLD resolution (Linear resolution with Selection function for Definite logic programs): • Joint use of input and goal-driven set of support heuristics • Always pick last proven theorem clause with next untried axiom clause • Always questions last pick even if unrelated to failure that triggered backtracking • A form of goal-driven backward chaining of Horn clauses seen as deductive rules • Prolog uses special case of SLD resolution where: • Axiom clauses tried in top to bottom program writing order • Atoms to unify in the two picked clauses: • Conclusion of selected axiom clause • Next untried premise of last proven theorem clause in left to right program writing order (goal) • Unification without occur-check • Generates proof tree in top-down, depth-first manner • Failure triggers systematic, chronological backtracking: • Try next alternative for last selection even if clearly unrelated to failure • Reprocess from scratch new occurrences of sub-goals previously proven true or false • Simple, intuitive, space-efficient, time-inefficient, potentially non-terminating (incomplete)

  14. Refutation proof principle: To prove KB |= F Prove logically equivalent: (KB  F) |= True In turn logically equivalent to: (KB   F) |= False (american(P)  weapon(W)  nation(N)  hostile(N)  sells(P,N,W)  criminal(P)) //1  (T  owns(nono,m1)) //2a  (T  missile(m1)) //2b  (owns(nono,W)  missile(W) sells(west,nono,W)) //3  (T  american(west)) //4  (T  nation(nono)) //5  (T  enemy(nono,america)) //6  (missile(W)  weapon(W)) //7  (enemy(N,america) hostile(N)) //8  (T  nation(america)) //9  (criminal(west)  F) //0 Refutation Resolution Proof Example 1. Solve 0 w/ 1 unifying P/west:american(west)  weapon(W)  nation(N) hostile(N)  sells(west,N,W)  F //10 2. Solve 10 w/ 4:weapon(W)  nation(N)  hostile(N) sells(west,N,W)  F //11 3. Solve 11 w/ 7: missile(W)  nation(N)  hostile(N) sells(west,N,W)  F //12 4. Solve 12 w/ 2b unifying W/m1:nation(N)  hostile(N)  sells(west,N,m1)  F //13 5. Solve 13 w/ 5 unifying N/nono:hostile(nono)  sells(west,nono,m1)  F //14 6. Solve 14 w/ 8 unifying N/nono:enemy(nono,america)  sells(west,nono,m1)  F //15 7. Solve 15 w/ 6: sells(west,nono,m1)  F //16 8. Solve 16 w/ 3 unifying W/m1: owns(nono,m1)  missile(m1)  F //17 9. Solve 17 with 2a: missile(m1)  F //18 10. Solve 18 with 2b: F

  15. SLD resolution example criminal(west)? criminal(P) american(P) weapon(W) nation(N) hostile(N) sells(P,N,W) sells(west,nono,W) missile(W) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  16. SLD resolution example criminal(west)? criminal(west) american(P) weapon(W) nation(N) hostile(N) sells(P,N,W) sells(west,nono,W) missile(W) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  17. SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west,N,W) sells(west,nono,W) missile(W) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  18. SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west,N,W) sells(west,nono,W) missile(W) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  19. SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west,N,W) sells(west,nono,W) missile(W) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  20. SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west,N,W) sells(west,nono,W) missile(W) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  21. SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west,N,W) sells(west,nono,W) missile(W) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  22. SLD resolution example criminal(west)? criminal(west) american(west) weapon(W) nation(N) hostile(N) sells(west,N,W) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  23. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(N) hostile(N) sells(west,N,W) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  24. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  25. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  26. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  27. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(N) sells(west,N,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  28. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  29. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  30. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,W) missile(m1) enemy(nono,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  31. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,W) missile(m1) enemy(nono,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  32. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,W) missile(m1) enemy(nono,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  33. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,W) missile(m1) enemy(nono,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  34. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,m1) missile(m1) enemy(nono,america) owns(nono,W) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  35. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,m1) missile(m1) enemy(nono,america) owns(nono,m1) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  36. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,m1) missile(m1) enemy(nono,america) owns(nono,m1) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  37. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,m1) missile(m1) enemy(nono,america) owns(nono,m1) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  38. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,m1) missile(m1) enemy(nono,america) owns(nono,m1) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  39. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,m1) missile(m1) enemy(nono,america) owns(nono,m1) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  40. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,m1) missile(m1) enemy(nono,america) owns(nono,m1) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  41. SLD resolution example criminal(west)? criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,m1) missile(m1) enemy(nono,america) owns(nono,m1) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  42. SLD resolution example criminal(west)? yes criminal(west) american(west) weapon(m1) nation(nono) hostile(nono) sells(west,nono,m1) sells(west,nono,m1) missile(m1) enemy(nono,america) owns(nono,m1) american(west) missile(m1) nation(nono) enermy(nono,america) owns(nono,m1) nation(america)

  43. SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(america) enermy(nono,america) owns(nono,m1) nation(nono)

  44. SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m1) nation(N) hostile(N) sells(west,N,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(america) enermy(nono,america) owns(nono,m1) nation(nono)

  45. SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m1) nation(america) hostile(N) sells(west,N,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(america) enermy(nono,america) owns(nono,m1) nation(nono)

  46. SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(america) enermy(nono,america) owns(nono,m1) nation(nono)

  47. SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(america) enermy(nono,america) owns(nono,m1) nation(nono)

  48. SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) american(west) missile(m1) nation(america) enermy(nono,america) owns(nono,m1) nation(nono)

  49. SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1) sells(west,nono,W) missile(m1) enemy(N,america) owns(nono,W) fail american(west) missile(m1) nation(america) enermy(nono,america) owns(nono,m1) nation(nono)

  50. SLD resolution example with backtracking criminal(west)? criminal(west) american(west) weapon(m1) nation(america) hostile(america) sells(west,america,m1) sells(west,nono,W) backtrack missile(m1) enemy(N,america) owns(nono,W) fail american(west) missile(m1) nation(america) enermy(nono,america) owns(nono,m1) nation(nono)