© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog.

Slides:



Advertisements
Similar presentations
Getting started with Prolog
Advertisements

Logic Programming Lecture 1: Course orientation; Getting started with Prolog.
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
Logic Programming in Prolog
Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Lecturer: Dr. Abeer Mahmoud Logic Programming in Prolog.
Prolog.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
Prolog: List © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
1 Introduction to Prolog References: – – Bratko, I., Prolog Programming.
1 Logic Programming. 2 A little bit of Prolog Objects and relations between objects Facts and rules. Upper case are variables. parent(pam, bob).parent(tom,bob).
4. PROLOG Data Objects And PROLOG Arithmetic
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 4: Lists Theory –Introduce lists, an important recursive data structure often used in Prolog.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 2 Theory –Unification –Unification in Prolog –Proof search Exercises –Correction exercises.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 4: Lists Theory –Introduce lists, an important recursive data structure often used in Prolog.
Logic Programming Languages
DEDUCTIVE DATABASE.
PROLOG KAIST Gunwoo Park 1. What’s Prolog? 2  General purpose logic programming language  Declarative, which means that the program logic is.
Formal Models of Computation Part II The Logic Model
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
1 Visual Prolog Programs LabLecture # 3 Lecturer : Sheriff Nafisa TA : Mubarakah Otbi, Duaa al Ofi, Huda al Hakami.
LING 388: Language and Computers Sandiway Fong Lecture 4.
Agile Software Development Lab 2008 Dr. Günter Kniesel, Daniel Speicher, Tobias Rho, Pascal Bihler Spring 2008 R O O T S Prolog - Part 1 Alexis Raptarchis.
Introduction to AgentSpeak and Jason for Programming Multi-agent Systems (1) Dr Fuhua (Oscar) Lin SCIS Athabasca University June 19, 2009.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
ARTIFICIAL INTELLIGENCE Lecture 3 Predicate Calculus.
CSC 270 – Survey of Programming Languages Prolog Lecture 2 – Unification and Proof Search.
Prolog Programming in Logic. 2 SWI-Prolog SWI-Prolog is a good, standard Prolog for Windows and Linux Can be installed on Macintosh with a little more.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
Programming Languages. A Logic Programming Language: Prolog This lesson describes the basic structures and functions of the logic programming language:
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
Semantic Construction lecture 2. Semantic Construction Is there a systematic way of constructing semantic representation from a sentence of English? This.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
Prolog Kyle Marcotte. Outline What is Prolog? Origins of Prolog (History) Basic Tutorial TEST!!! (sort of…actually not really at all) My example Why Prolog?
Key Concepts Representation Inference Semantics Discourse Pragmatics Computation.
By: Cory Canter CSC 415 Programming Languages. History  Created by Alain Colmerauer, Phillipe Roussel and Robert Kowalski in 1971  Started as a natural.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
CS6133 Software Specification and Verification
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 9: A closer look at terms Theory –Introduce the == predicate –Take a closer look at term structure.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
Introduction to Prolog
Introduction to Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
CSE 3302 Programming Languages Chengkai Li Spring 2008 Logic Programming: Prolog Lecture 21 – Prolog, Spring CSE3302 Programming Languages, UT-Arlington.
1 Knowledge Based Systems (CM0377) Lecture 6 (last modified 20th February 2002)
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
Logic Programming Dr. Yasser Nada Fall 2010/2011 Lecture 1 1 Logic Programming.
ISBN Chapter 16 Logic Programming Languages.
Artificial Intelligence CS370D
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Done By :- -Nesreen Basem -Sara nabil -Rawan Prolog Program.
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Logic Programming Logic programming Candidates should be familiar with the concept of logic programming for declaring logical relationships.
Instructor :Bayan Ghozlan الاستاذه : بيان غزلان.  البرولوغ Prolog هي لغة برمجة منطقية. وتعني برمجه المنطق programing language  تم اختراع اللغة بواسطة.
علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Prolog programming Introduction to Prolog (part2)
Chapter Two: Syntax and Meaning of Prolog Programs
Introduction to Prolog
Chapter 2: Prolog (Introduction and Basic Concepts)
Representations & Reasoning Systems (RRS) (2.2)
PROLOG.
Presentation transcript:

© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog Now! –SWI Prolog interpreter

© Johan Bos Learn Prolog Now!

© Johan Bos SWI Prolog Freely available Prolog interpreter Works with –Linux, –Windows, or –Mac OS There are many more Prolog interpreters Not all are ISO compliant

© Johan Bos Lecture 1 Theory –Introduction to Prolog –Facts, Rules and Queries –Prolog Syntax Exercises –Exercises of LPN chapter 1 –Practical work

© Johan Bos Aim of this lecture Give some simple examples of Prolog programs Discuss the three basic constructs in Prolog: –Facts –Rules –Queries Introduce other concepts, such as –the role of logic –unification with the help of variables Begin the systematic study of Prolog by defining terms, atoms, and variables

© Johan Bos Prolog "Programming with Logic" Declarative Very different from other (procedural) programming languages Good for knowledge-rich tasks

© Johan Bos History of Prolog s/1990s 2005 first Prolog interpreter by Colmerauer and Roussel

© Johan Bos History of Prolog s/1990s 2005 implementation of DEC10 compiler by Warren

© Johan Bos History of Prolog s/1990s 2005 Definite Clause Grammars implementation by Pereira and Warren

© Johan Bos History of Prolog s/1990s 2005 Prolog grows in popularity especially in Europe and Japan

© Johan Bos History of Prolog s/1990s 2005 Prolog used to program natural language interface in International Space Station by NASA

© Johan Bos Basic idea of Prolog Describe the situation of interest Ask a question Prolog logically deduces new facts about the situation we described Prolog gives us its deductions back as answers

© Johan Bos Consequences Think declaratively, not procedurally –Challenging –Requires a different mindset High-level language –Not as efficient as, say, C –Good for rapid prototyping –Useful in many AI applications

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party.

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?-

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- woman(mia).

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- woman(mia). yes ?-

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- woman(mia). yes ?- playsAirGuitar(jody).

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- woman(mia). yes ?- playsAirGuitar(jody). yes ?-

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- woman(mia). yes ?- playsAirGuitar(jody). yes ?- playsAirGuitar(mia). no

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- tattoed(jody).

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- tattoed(jody). no ?-

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- tattoed(jody). ERROR: predicate tattoed/1 not defined. ?-

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- party.

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- party. yes ?-

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- rockConcert.

© Johan Bos Knowledge Base 1 woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). party. ?- rockConcert. no ?-

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda).

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact rule

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact rule

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). fact rule

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). headbody

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). ?-

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). ?- playsAirGuitar(mia). yes ?-

© Johan Bos Knowledge Base 2 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). ?- playsAirGuitar(mia). yes ?- playsAirGuitar(yolanda). yes

© Johan Bos Clauses happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). There are five clauses in this knowledge base: two facts, and three rules. The end of a clause is marked with a full stop.

© Johan Bos Predicates happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda). There are three predicates in this knowledge base: happy, listens2music, and playsAirGuitar

© Johan Bos Knowledge Base 3 happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch).

© Johan Bos Expressing Conjunction happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch). The comma," expresses conjunction in Prolog

© Johan Bos Knowledge Base 3 happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch). ?- playsAirGuitar(vincent). no ?-

© Johan Bos Knowledge Base 3 happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch). ?- playsAirGuitar(butch). yes ?-

© Johan Bos Expressing Disjunction happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch). playsAirGuitar(butch):- listens2music(butch). happy(vincent). listens2music(butch). playsAirGuitar(vincent):- listens2music(vincent), happy(vincent). playsAirGuitar(butch):- happy(butch); listens2music(butch).

© Johan Bos Prolog and Logic Clearly Prolog has something to do with logic Operators –Implication :- –Conjunction, –Disjunction ; Use of modus ponens Negation

© Johan Bos Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin).

© Johan Bos Prolog Variables woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X).

© Johan Bos Variable Instantiation woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia

© Johan Bos Asking Alternatives woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia;

© Johan Bos Asking Alternatives woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia; X=jody

© Johan Bos Asking Alternatives woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia; X=jody; X=yolanda

© Johan Bos Asking Alternatives woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- woman(X). X=mia; X=jody; X=yolanda; no

© Johan Bos Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- loves(marsellus,X), woman(X).

© Johan Bos Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- loves(marsellus,X), woman(X). X=mia yes ?-

© Johan Bos Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- loves(pumpkin,X), woman(X).

© Johan Bos Knowledge Base 4 woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marsellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). ?- loves(pumpkin,X), woman(X). no ?-

© Johan Bos Knowledge Base 5 loves(vincent,mia). loves(marsellus,mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). jealous(X,Y):- loves(X,Z), loves(Y,Z).

© Johan Bos Knowledge Base 5 loves(vincent,mia). loves(marsellus,mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). jealous(X,Y):- loves(X,Z), loves(Y,Z). ?- jealous(marsellus,W).

© Johan Bos Knowledge Base 5 loves(vincent,mia). loves(marsellus,mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). jealous(X,Y):- loves(X,Z), loves(Y,Z). ?- jealous(marsellus,W). W=vincent ?-

© Johan Bos Prolog Syntax What exactly are facts, rules and queries built out of? Terms Simple TermsComplex Terms ConstantsVariables AtomsNumbers Terms Simple TermsComplex Terms ConstantsVariables AtomsNumbers

© Johan Bos Atoms A sequence of characters of upper-case letters, lower-case letters, digits, or underscore, starting with a lowercase letter Examples: butch, big_kahuna_burger, playGuitar An arbitrary sequence of characters enclosed in single quotes Examples: 'Vincent', 'Five dollar shake', A sequence of special characters Examples: :, ;. :-

© Johan Bos Numbers Integers: 12, -34, Floats:

© Johan Bos Variables A sequence of characters of upper- case letters, lower-case letters, digits, or underscore, starting with either an uppercase letter or an underscore Examples: X, Y, Variable, Vincent, _tag

© Johan Bos Complex Terms Atoms, numbers and variables are building blocks for complex terms Complex terms are built out of a functor directly followed by a sequence of arguments Arguments are put in round brackets, separated by commas The functor must be an atom

© Johan Bos Examples of complex terms Examples we have seen before: –playsAirGuitar(jody) –loves(vincent, mia) –jealous(marsellus, W) Complex terms inside complex terms: –hide(X,father(father(father(butch))))

© Johan Bos Arity The number of arguments a complex term has is called its arity Examples: woman(mia) is a term with arity 1 loves(vincent,mia) has arity 2 father(father(butch)) arity 1

© Johan Bos Arity is important In Prolog you can define two predicates with the same functor but with different arity Prolog would treat this as two different predicates In Prolog documentation arity of a predicate is usually indicated with the suffix "/" followed by a number to indicate the arity

© Johan Bos Example of Arity This knowledge base defines –happy/1 –listens2music/1 –playsAirGuitar/1 happy(yolanda). listens2music(mia). listens2music(yolanda):- happy(yolanda). playsAirGuitar(mia):- listens2music(mia). playsAirGuitar(yolanda):- listens2music(yolanda).

© Johan Bos Exercises

© Johan Bos Summary of this lecture Simple examples of Prolog programs Introduced three basic constructs in Prolog: –Facts –Rules –Queries Discussed other concepts, such as –the role of logic –unification with the help of variables Definition of Prolog constructs: terms, atoms, and variables

© Johan Bos Next lecture Discuss unification in Prolog Prolog's search strategy