Introduction to PROLOG

Slides:



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

Some Prolog Prolog is a logic programming language
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
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.
Logic.
PROLOG Modified last on Nov 30, Information Great tutorial at (these slides are a compressed version of this tutorial): –
Chapter 12 - Logic Programming
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
Outline Recap Knowledge Representation I Textbook: Chapters 6, 7, 9 and 10.
Logic Programming Languages. Objective To introduce the concepts of logic programming and logic programming languages To introduce a brief description.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
CHA2555 Week2: Knowledge Representation, Logic and Prolog Lee McCluskey First term:
1 About Prolog Lu Han Written at Modified at
1 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 13 Slides Courtesy to: Peter LO.
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
1 Prolog I. 2 Syllogisms “Prolog” is all about programming in logic. –Socrates is a man. –All men are mortal. –Therefore, Socrates is mortal.
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.
1 Lecture 6 Logic Programming introduction to Prolog, facts, rules Ras Bodik Shaon Barman Thibaud Hottelier Hack Your Language! CS164: Introduction to.
F28PL1 Programming Languages Lecture 16: Prolog 1.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
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.
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.
CS4026 Formal Models of Computation Part II The Logic Model Lecture 2 – Prolog: History and Introduction.
CS 603: Programming Languages Lecture 25 Spring 2004 Department of Computer Science University of Alabama Joel Jones.
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?
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Logical Agents Chapter 7. Outline Knowledge-based agents Logic in general Propositional (Boolean) logic Equivalence, validity, satisfiability.
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)
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Propositional Logic Predicate Logic
Logic Programming Dr. Yasser Ahmed Nada Fall 2010/2011 Lecture 2 1 Logic Programming.
Introduction to Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
1 Knowledge Based Systems (CM0377) Introductory lecture (Last revised 28th January 2002)
ISBN Chapter 16 Logic Programming Languages.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
1-1 An Introduction to Logical Programming Sept
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 Wednesday No reading Prolog handout 2 Chapter 9, exercise 4.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
Logical Agents. Outline Knowledge-based agents Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability.
علمتني الثلوج أن أكون كبياض الثلج لا يحمل قلبي غير الحب والعطف والرحمة لا أسيئ الظن بالأخرين ولا أحكم عليهم من مظهرهم فإذا لم تعاشرهم فأنت تجهلهم !
PROLOG. Information Great tutorial at (these slides are a compressed version of this tutorial): –
Prolog a declarative language
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Logic Programming Languages
Prolog a declarative language
Prolog a declarative language
Prolog a declarative language
Introduction to Prolog
Logic Programming Language
Predicate Logic: Syntax.
Predicate Logic.
Chapter 2: Prolog (Introduction and Basic Concepts)
PROLOG.
Supplemental slides for CSE 327 Prof. Jeff Heflin
Presentation transcript:

Introduction to PROLOG

Prolog A logic programming language created in 1972 PROgramming in LOGic Restricted to Horn clauses Head:- body Inference Backward chaining

Knowledge Base-facts Knowledgebase can have facts: woman(ruba). playsguitar(jane). ...

Knowledge Base-facts Knowledgebase can have facts: woman(ruba). playsguitar(jane). Consulting the KB is done in the Interpreter window: Prolog listens to your queries and answers: ?- woman(ruba). //asking if mia is a woman true

Consulting Consulting the KB: Prolog listens to your queries and answers: ?- woman(ruba) true ?- woman(jane) false doesn’t follow from KB ?- woman(salma) doesn’t know anything about alisa

KnowledgeBase - rules e.g. person (X) => mortal (X) male(yasin). female(ruba). male(yusuf). mortal(X) :- person(X). person(X) :- female(X). person(X) :- male(X). head := body means body => head e.g. person (X) => mortal (X)

KnowledgeBase - rules male(yasin). female(ruba). male(yusuf). mortal(X) :- person(X). person(X) :- female(X). person(X) :- male(X). If you save these in a file: mortal.pl (a prolog program), you can TELL these to the interpreter via (or when you click on file name): ?- consult(mortal). Yes If you type “listing”, Prolog will list all the facts and rules you just “read in” (consulted). ?- listing. male(yasin) ...

KnowledgeBase - rules male(yasin). female(ruba). male(yusuf). mortal(X) :- person(X). person(X) :- female(X). person(X) :- male(X). ... Now we can test the program inside the Listener with prolog queries: ?- mortal(ziggy). false ?- mortal(yasin). true

Rules - Logical AND , is used to indicate Logical AND Equivalent to: dances(vincent) :- happy(vincent) , listensToMusic(vincent). , is used to indicate Logical AND Equivalent to: happy(vincent)  listensToMusic(vincent) => dances(vincent) “Vincent dances if he listens to music and he is happy”. Other example: father(X,Y) :- parent(X,Y) , male(X).

Rules - Logical OR This can also be stated as: dances(john) :- happy(john). dances(john) :- listensToMusic(john). Indicates LOGICAL OR Equivalent to: happy(john)  listensToMusic(john) => dances(john) “John dances either if he listens to music, or if he is happy.” This can also be stated as: dances(john) :- happy(john) ; listensToMusic(john). where ; indicates OR.

Consulting ?- ; (remember that ; means OR woman(ruba). woman(jody). man(yusuf). woman(heba). ?- woman(X). X = mia ?- ; (remember that ; means OR so this query means: “are there any more women?”) X = jody ?- ; X = heba no ( No other match is possible)

Wildcard In Prolog predicates, underscore (_) is the wildcard (matches anything): Mother(M,C) :- Person(C,_,M,_,_). where Person is defined as Person(name, gender, mother, father, spouse). It means, Mother(M,C) holds, if the predicate Person holds for C and M in the right positions, with anything else for the other parts.

Arithmetic In particular, there is support for arithmetic and numbers: Basics of numbers: ?- 8 is 6+2. Yes ?- X is mod(7,2). X=1 ?- 2 < 4.

Arithmetic positive(N) :- N>0. non_zero(N) :- N<0 ; N>0. ?- X is sqrt(9), Y is 2 ** 4, Z is floor(3.14). X = 3.0 Y = 16.0 Z = 3 minimum(X,Y,X) :- X<Y. minimum(X,Y,Y) :- X>=Y. ?-minimum(3,8,A). (unification) A = 3 It’s a bit like: void minimum(int x, int y, int & z) { if (x < y) z = x; else z = y; }

There are more details about Prolog but we will leave it at that Good Luck