© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 1 Introduction to Prolog.

download © Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 1 Introduction to Prolog.

If you can't read please download the document

Transcript of © Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 1 Introduction to Prolog.

  • Slide 1

Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 1 Introduction to Prolog Slide 2 Patrick Blackburn, Johan Bos & Kristina Striegnitz Learn Prolog Now! http://www.learnprolognow.org/ Important: be aware that there are different versions of the LPN book: the online html version, the hard copy book, and online pdf. They differ in particular wrt exercises and their numbering. When referring to exercises from the LPN book, I refer to the online html version as can be found on www.learnprolognow.org. Slide 3 Patrick Blackburn, Johan Bos & Kristina Striegnitz SWI Prolog Freely available Prolog interpreter Works with Linux, Windows, or Mac OS There are many more Prolog interpreters Not all are ISO compliant Slide 4 Aim of this lecture LPN Ch. 1-3 After this lecture, you should be able to explain the meaning of the following key notions and their relation to Prolog: logic programming facts, rules and queries (horn clauses) unification (most general) unifier (mgu) backtracking, depth-first search, forward & backward chaining Important: I will not discuss everything from the book in the lectures, but it is to be studied for the exam (to the extent indicated on blackboard)! I strongly advise you to read the relevant parts of the book before the practical sessions. Slide 5 Patrick Blackburn, Johan Bos & Kristina Striegnitz Introduction Slide 6 Prolog Colmerauer & Roussel, 1972 Kowalski, Predicate Logic as Programming Language, In Proceedings IFIP Congress, pp. 569-574. 1974. Slide 7 Grace Hopper 1906-1992 Mother of COBOL (1959) programs should be written in a language that is close to English rather than in machine code Slide 8 Prolog (2) Slide 9 Patrick Blackburn, Johan Bos & Kristina Striegnitz removeThrees in Java static void removeThrees (ArrayList list) { Iterator iterator = list.iterator(); while (iterator.hasNext()) { if (iterator.next() == 3) { iterator.remove(); } } Procedural language: step by step instructions describing what should be computed Slide 10 Patrick Blackburn, Johan Bos & Kristina Striegnitz removeThrees in Prolog removeThrees([],[]). removeThrees([3|T],L) :- removeThrees(T,L). removeThrees([H|T],[H|T2]) :- not(H = 3), removeThrees(T,T2). What are the differences with Java? Slide 11 Patrick Blackburn, Johan Bos & Kristina Striegnitz Prolog "Programming with Logic" Declarative: separation of knowledge base and inference engine Very different from other (procedural) programming languages Good for knowledge-rich tasks, logical reasoning Initially, small programming tasks to practice specific skills. More elaborate programs as part of GOAL in the 2 nd half of the course, and in Q4. Slide 12 Patrick Blackburn, Johan Bos & Kristina Striegnitz Why Learn Prolog? Slide 13 It is the knowledge representation language of GOAL, which will be used to program UT2004 agents in Q4 Different programming paradigm It is a challenge! One of the most well-known AI languages Learn fundamental programming concepts, in particular recursion and recursive data structures WARNING: it seems easy at first Slide 14 Prolog Development Center advanced scheduling systems and speech based applications for manufacturing, retail and service businesses, larger public institutions, airlines and airports http://www.pdc.dk/ Slide 15 Visual Prolog support industrial strength programming of complex knowledge emphasized problems. combining the very best features of logical, functional and object-oriented programming paradigms in a consistent and elegant way. http://www.visual-prolog.com/ Slide 16 Clarissa at ISS fully voice-operated procedure browser, enabling astronauts to be more efficient with their hands and eyes and to give full attention to the task while they navigate through the procedure using spoken commands http://ti.arc.nasa.gov/project/clarissa/ Slide 17 OntoDLV OntoDLV is an intelligent ally for quickly and easily developing powerful knowledge-based applications and decision support systems (e.g. Planning, Customer Profiling or Workforce Scheduling) that otherwise require complex and labourious programming. http://www.exeura.com/ Slide 18 Ontological Logic Programming Murat Sensoy, Geeth de Mel, Wamberto W. Vasconcelos and Timothy J. Norman, "Position Paper: Ontological Logic Programming", Proceedings of the 3rd International Workshop on Semantic Sensor Networks (SSN10), 2010. Slide 19 Patrick Blackburn, Johan Bos & Kristina Striegnitz Facts, Rules and Queries Slide 20 Alle mensen zijn sterfelijk m(socrates). s(X) :- m(X). M(socrates), x(M(x) S(x)) fact rule Variables capitalized, predicates lower case Implication ( :- ) from right to left Each clause is terminated with a full stop. Clauses are implicitly universally quantified. horn clauses Slide 21 Head and Body of Rule m(socrates). s(X) :- m(X). fact rule Variables capitalized, predicates lower case Implication ( :- ) from right to left Each clause is terminated with a full stop. Clauses are implicitly universally quantified. body head Slide 22 Is socrates sterfelijk? m(socrates). s(X) :- m(X). M(socrates), x(M(x) S(x)) |= S(socrates) ?- is the SWI-Prolog prompt asking whether a goal formula logically follows from the knowledge base ?- s(socrates). query Slide 23 Is socrates sterfelijk? m(socrates). s(X) :- m(X). ?- is the SWI-Prolog prompt asking whether a goal formula logically follows from the knowledge base ?- s(socrates). yes ?- Slide 24 Patrick Blackburn, Johan Bos & Kristina Striegnitz Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). Slide 25 Patrick Blackburn, Johan Bos & Kristina Striegnitz Prolog Variables woman(mia). woman(jody). woman(yolanda). ?- woman(X). Slide 26 Patrick Blackburn, Johan Bos & Kristina Striegnitz Variable Instantiation woman(mia). woman(jody). woman(yolanda). ?- woman(X). X=mia returning variable instantiations instead of only whether a goal follows from the KB or not, is what gives Prolog its programming power! Slide 27 Patrick Blackburn, Johan Bos & Kristina Striegnitz Asking Alternatives woman(mia). woman(jody). woman(yolanda). ?- woman(X). X=mia; Slide 28 Patrick Blackburn, Johan Bos & Kristina Striegnitz Asking Alternatives woman(mia). woman(jody). woman(yolanda). ?- woman(X). X=mia; X=jody Slide 29 Patrick Blackburn, Johan Bos & Kristina Striegnitz Asking Alternatives woman(mia). woman(jody). woman(yolanda). ?- woman(X). X=mia; X=jody; X=yolanda Slide 30 Patrick Blackburn, Johan Bos & Kristina Striegnitz Asking Alternatives woman(mia). woman(jody). woman(yolanda). ?- woman(X). X=mia; X=jody; X=yolanda; no Slide 31