logic programming
play

Logic Programming Gilian Henke Universitt zu Lbeck January 5, 2016 - PowerPoint PPT Presentation

Logic Programming Gilian Henke Universitt zu Lbeck January 5, 2016 History Example January 5, 2016 Logic Programming Gilian Henke (Universitt zu Lbeck) Problems 5 SLD-Resolution Search-Trees Control 4 Horn Clause Basics


  1. Logic Programming Gilian Henke Universität zu Lübeck January 5, 2016

  2. History Example January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) Problems 5 SLD-Resolution Search-Trees Control 4 Horn Clause Basics Logic 3 Basics 2 History 1 Content Problems Control Logic 2

  3. History Example January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) Problems 5 SLD-Resolution Search-Trees Control 4 Horn Clause Basics Logic 3 Basics 2 History 1 Content Problems Control Logic 3

  4. History Basics Logic Control Problems History Idea from 1930s Based on automation of theorem proving and AI 1970s Kowalski developed SLD resolutions Colmerauer developed Prolog Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 4

  5. History Example January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) Problems 5 SLD-Resolution Search-Trees Control 4 Horn Clause Basics Logic 3 Basics 2 History 1 Content Problems Control Logic 5

  6. History Basics Logic Control Problems Basics Based on First-Order-Predicate-Logic Declarative language Divided into Logic and Control Most common language: Prolog Others: Datalog, Parlog Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 6

  7. History Example January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) Problems 5 SLD-Resolution Search-Trees Control 4 Horn Clause Basics Logic 3 Basics 2 History 1 Content Problems Control Logic 7

  8. History Basics Logic Control Problems Horn Clause Definition (Horn Clause) A clause, i.e. a disjunction of literals, where at most one positive literal exists. Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 8 Example: A ∨ ¬ B ∨ ¬ C

  9. History Basics January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) Query Goal clause Fact A Unit clause Rule Definite clause Logic programming name Logic programming Normal logic Normal name Different Horn Clauses Problems Control Logic 9 A ∨ ¬ B 1 ∨ ¬ B 2 ∨ ... ∨ ¬ B n A ← B 1 ∧ B 2 ∧ ... ∧ B n A ← ¬ G 1 ∨ ¬ G 2 ∨ ... ∨ ¬ G n ← G 1 ∧ G 2 ∧ ... ∧ G n

  10. History Basics Logic Control Problems Hello World! hw( h e l l o w o r l d ) . world ! ’ ) . Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 10 ? − hw(X) . ? − w r i t e ( ’ Hello

  11. History parent ( c l a i r e , sophie ) . January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) parent (tom , gary ) . parent (tom , frank ) . Basics parent ( alice , c a r l ) . parent (ben , c a r l ) . parent ( c l a i r e , ben ) . parent ( steve , sophie ) . parent ( steve , ben ) . parent ( sophie , gary ) . parent ( sophie , frank ) . Example in Prolog Problems Control Logic 11 grandparent (X,Z): − parent (X,Y) , parent (Y,Z) . ancestor (X,Y): − parent (X,Y) . ancestor (X,Y): − parent (Z,Y) , ancestor (X,Z) . ? − grandparent (X, gary ) . ? − parent ( sophie , gary ) . ? − ancestor ( steve , c a r l ) .

  12. History Example January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) Problems 5 SLD-Resolution Search-Trees Control 4 Horn Clause Basics Logic 3 Basics 2 History 1 Content Problems Control Logic 12

  13. History Basics Logic Control Problems Search-Tree How to get the solution to a query? Build a Search-Tree with Depth-First Traversal, where the query is the root nodes are subgoals leaves are success or failure nodes If a path to a success node exist the query is successful Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 13

  14. History fail January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) X=steve Y=ben true parent(ben,carl) parent(steve,ben), parent(Y,carl) parent(steve,Y), X=sophie Y=gary parent(gary,carl) Basics parent(sophie,gary), Y=frank fail parent(frank,carl) parent(sophie,frank), parent(Y,carl) parent(sophie,Y), parent(X,Y),parent(Y,carl) grandparent(X,carl) Example Problems Control Logic 14

  15. History Basics Logic Control Problems Substitution Definition (Substitution) Let X be variable and t be a term. For a given set of tuples ( X , t ) the replaced by its corresponding t i . Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 15 substitution θ denotes that if θ is applied to a term s every X i is Example: θ = ( X , alice ) θ ( parent ( X , Y )) = parent ( alice , Y )

  16. History Basics January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) unify. 16 Definition (Unification) Unification Problems Control Logic Let s and t be terms. If there exists a Substitution θ so that s θ = t θ , then θ is called the unifier of s and t . This is also called that t and s Example: θ = ( X , alice ) θ ( parent ( X , Y )) = parent ( alice , Y ) θ ( parent ( alice , Y )) = parent ( alice , Y )

  17. History Basics Logic Control Problems Resolution Definition (Resolution) Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 17 If the Rules A ← B and B ← C holds true then also A ← C holds true.

  18. History delete G i ; January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) end end break; failure = true; if A does not exists then end Basics continue; if G i =true then SLD-Resolution Logic Control Problems 18 Resolvent = Q; failure=false; Data : Q= G 1 , G 2 ... G n Result : substitution σ and failure σ ={}; while Resolvent ! = {} do select G i ∈ Resolvent ; select Rule A ← B 1 ... B m where A and G i unify with θ ; replace G i with B 1 ... B m ; apply θ to Resolvent; σ = θσ ; return σ , failure;

  19. History Example January 5, 2016 Logic Programming Gilian Henke (Universität zu Lübeck) Problems 5 SLD-Resolution Search-Trees Control 4 Horn Clause Basics Logic 3 Basics 2 History 1 Content Problems Control Logic 19

  20. History Basics Logic Control Problems Problems Negation as failure Determinism Termination Prolog: Non-Uniformity Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 20

  21. History Basics Logic Control Problems Conclusion Declarative programming language based on First Order Predicate Logic Useful in specialised contexts Non-trivial problems exist Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 21

  22. History Basics Logic Control Problems Thank you for your attention! Gilian Henke (Universität zu Lübeck) Logic Programming January 5, 2016 22

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend