PROLOG KAIST 20061013 Gunwoo Park 1. What’s Prolog? 2  General purpose logic programming language  Declarative, which means that the program logic is.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

© Johan Bos Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical work [lab] Teaching material –Learn Prolog.
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
Chapter 11 :: Logic Languages
Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
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).
Answer Set Programming Overview Dr. Rogelio Dávila Pérez Profesor-Investigador División de Posgrado Universidad Autónoma de Guadalajara
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
Chapter 8: The Logical Paradigm Lecturer: Xinming (Simon) Ou CIS 505: Programming Languages Fall 2010 Kansas State University 1.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
1 CILOG User Manual Bayesian Networks Seminar Sep 7th, 2006.
1 Artificial Intelligence CSC 361 Prof. Mohamed Batouche Department of Computer Science CCIS – King Saud University Riyadh, Saudi Arabia
Logic Programming Languages
1 Software Development Topic 2 Software Development Languages and Environments.
Formal Models of Computation Part II The Logic Model
CSC 270 – Survey of Programming Languages Prolog Lecture 1 – Facts, Rules, and Queries.
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
LING 388: Language and Computers Sandiway Fong Lecture 4.
1 Lecture 15: Introduction to Logic Programming with Prolog (Section 11.3) A modification of slides developed by Felix Hernandez-Campos at UNC Chapel Hill.
Introduction to Logic Programming with Prolog (Section 11.3)
F28PL1 Programming Languages Lecture 16: Prolog 1.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
For Wednesday No new reading Prolog handout 2 Chapter 9, exercise 4.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now Chapter 9, exs 4 and 6. –6 must be in Horn clause form Prolog Handout 2.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
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.
CHAPTER 15 & 16 Functional & Logic Programming Languages.
CT214 – Logical Foundations of Computing Lecture 8 Introduction to Prolog.
1 Prolog and Logic Languages Aaron Bloomfield CS 415 Fall 2005.
Programming Languages. A Logic Programming Language: Prolog This lesson describes the basic structures and functions of the logic programming language:
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?
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
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.
For Monday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
Introduction to Prolog
Introduction to Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
Programming Language Concepts Lecture 17 Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Logic Programming.
ISBN Chapter 16 Logic Programming Languages.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
Invitation to Computer Science, Java Version, Second Edition 1 Logic Programming Logic programming  Various facts are asserted to be true  On the basis.
Knowledge Based Information System
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.
For Friday No reading Prolog Handout 2. Homework.
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.
PROLOG “Programmation en Logique”
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !
Section 16.5, 16.6 plus other references
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
PROLOG.
Prolog programming Introduction to Prolog (part2)
Introduction to Prolog
Introduction to PROLOG
Chapter 2: Prolog (Introduction and Basic Concepts)
Presentation transcript:

PROLOG KAIST Gunwoo Park 1

What’s Prolog? 2  General purpose logic programming language  Declarative, which means that the program logic is written in terms of relations (A → B)  The concept is developed by a group around Alan Colmerauer in Marseille, France, in the early 1970s  First implementation is launched at 1972  Initially aimed at natural language processing, but now its usage is stretched far into other areas  Even you can make Prolog program in GUI by using modern Prolog environments What than How

Schematic View of Prolog Programming 3  A program is written by many clauses (.pl )  A clause is a fact or rule  Fact Example: cindy is beautiful  Rule Example: If someone is beautiful, I love him/her  Then, how to use the program? It’s done by sending query to the virtual machine  Query Example: Do I love cindy?  Then the inference engine(virtual machine) analyzes the clauses to make an answer to the query  Program Answers: Yes

Schematic View of Prolog Programming (cont’d) 4 Program (Clauses) Inference Engine (Prolog Environment) Program User 1. User asks query “Do I love cindy?” 2. Inference engine gets query, and sees clauses. 3. Inference engine checks that cindy is beautiful, and I love any beautiful person. 4. So, inference engine concludes I love cindy, and answer “Yes”

Environment of Prolog 5  SWI-Prolog is a popular development environment for Prolog (  There are many versions of SWI to support various operating systems like Windows, Mac, and Linux

Data Type 6  Before seeing real examples, data type should be understood  Prolog’s single data type is the term. Terms are either atoms, numbers, variables or compound terms.  The first letter of data name is very important in Prolog because it determines the type  Type of cindy => Atom  Type of Cindy => Variable

Data Types (cont’d) 7  The types of the term  Atom : General-purpose name with no inherent meaning Starts with lower-case: x, blue, gunwoo With single quote: ‘Taco’, ‘some atom’  Number : Floats or integers (13, 14.23)  Variable : String consisting of letters and special characters, which is used as placeholder of arbitrary terms (X, Y, Z, Someone)  Compound terms: Composed of an atom called functor and a number of arguments, which are again terms trunk_year(‘Mazda’, 1986) Person_Friend(zelda, [tom, jim])

Rules and Facts  Program describes relations, defined by means of clauses.  A set of clauses is contained in.pl file  Two types of clauses – Facts and Rules  A rule is of the form of Head :- Body, which means that Head is true if Body is true  Clauses with empty bodies are called facts. An example of fact is cat(tom), means that tom is a cat. 8

Rules and Facts - Example  As mentioned, clauses can be either facts or rules. female(jessica). female(cindy). child(jessica, cindy). daughter(X, Y) :- female(X), child(X, Y). Semantics: jessica and cindy are female. jessica is cindy’s daughter. But there is a rule. If X is female and child of Y, then X is daughter of Y. Then let’s ask question to the set of clauses !!! Facts Rule The comma is AND operation The dot is end of a clause 9

Query  Let’s ask a query (question) to the virtual machine, then the machine give answer by backtracking declared facts and rules. ?- daughter(jessica, cindy). yes ?- professor(jessica, mack). no 10

Boolean Operation 11  Negation  failure(X) :- \+ success(X).  AND (Conjunction)  mom(X) :- female(X), parent(X)  OR (Disjunction)  good(X) :- money(X); power(X)

Knowledge Base Example 1 12 [kb1.pl] woman(mia). woman(jody). woman(yolanda). playsAirGuitar(jody). [Usage Scenario] ?- woman(mia). ?- playsAirGuitar(mia). ?- playsAirGuitar(yolanda). ?- tatooed(jody).

Knowledge Base Example 2 13 [kb2.pl] listenToMusic(mia). happy(yolanda). playsAirGuitar(mia) :- listensToMusic(mia). playsAirGuitar(yolanda) :- listensToMusic(yolanda). listensToMusic(yolanda) :- happy(mia). [Usage Scenario] ?- happy(yolanda). ?- playsAirGuitar(mia). ?- playsAirGuitar(yolanda). ?- listensToMusic(yolanda).

Knowledge Base Example 3 14 [kb3.pl] happy(vincent). listensToMusic(butch). playsAirGuitar(vincent) :- listensToMusic(vincent), happy(vincent). playsAirGuitar(butch) :- happy(butch). playsAirGuitar(butch) :- listensToMusic(butch). [Usage Scenario] ?- playsAirGuitar(vincent). ?- playsAirGuitar(butch).

Using Variables in Query  We can use variable in a query  After executing a query, value is bound to the variable as a result ?- daughter(X, cindy).=> X : jessica ?- female(X).=> X : jessica, cindy ?- daughter(jessica, _).=> yes ※ ’_’ means “there is anything which satisfies the question”. (Existential Quantification) 15

Knowledge Base Example 4 16 [kb4.pl] woman(mia). woman(jody). woman(yolanda). loves(vincent, mia). loves(marcellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). [Usage Scenario] ?- woman(X). ?- loves(marcellus, X), woman(X).

Knowledge Base Example 5 17 [kb5.pl] loves(vincent, mia). loves(marcellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). jealous(X, Y) :- loves(X, Z), loves(Y, Z). [Usage Scenario] ?- jealous(marcellus, W).

Other features  Built-in predicates  I/O, like printing a character in the screen, is almost impossible to be defined by user-defined clauses.  So, Prolog provides built-in predicates for systematic operation.  By using the built-in predicates we can do Using graphics Communication with operating system  Loop and recursion  Prolog provides the means of recursive predicates  Loop can be made by those recursive predicates 18

Example Program 1 19 [ example.pl ] son(jack, george). father(B, A) :- son(A, B). After loading example.pl to SWI, execute a simple query…

Example Program 2 Print “Hello World” in the screen using built-in predicate 20

Demonstration 21 readLine.pl

Applications of Prolog  Natural language processing (Relation)  Intelligent systems (Inference)  Complicated knowledge databases (Knowledge)  Logic data analysis (Inference) 22

Extensions of Prolog  Constraint logic programming  HiLog and λ Prolog  F-logic  OW Prolog  Logtalk  Prolog-MPI  Oblog  Although logic programming is lack of some aspects like efficiency or flexibility, its programming paradigm is used considerably  Prolog can be considered as the father of logic programming 23

Thank you 24