Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.

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

Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
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
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
CPSC 322 Introduction to Artificial Intelligence September 15, 2004.
CPSC 322, Lecture 23Slide 1 Logic: TD as search, Datalog (variables) Computer Science cpsc322, Lecture 23 (Textbook Chpt 5.2 & some basic concepts from.
Introduction to Prolog What is Prolog? Application Areas of Prolog How does Prolog work? (Syntax of Prolog) Program Structure.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
CPSC 322 Introduction to Artificial Intelligence September 20, 2004.
CPSC 322, Lecture 23Slide 1 Logic: TD as search, Datalog (variables) Computer Science cpsc322, Lecture 23 (Textbook Chpt 5.2 & some basic concepts from.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
CHA2555 Week2: Knowledge Representation, Logic and Prolog Lee McCluskey First term:
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 15 Logic Programming Q: How many legs does.
1 Artificial Intelligence CSC 361 Prof. Mohamed Batouche Department of Computer Science CCIS – King Saud University Riyadh, Saudi Arabia
Prolog Programming Lecture Module 13. Objective ● What is Prolog? ● Prolog program ● Syntax of Prolog ● Prolog Control Strategy ● Execution of Prolog.
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.
Evolution of Programming Languages Generations of PLs.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
F28PL1 Programming Languages Lecture 16: Prolog 1.
Logic Programming Module 2AIT202 Website Lecturer: Dave Sharp Room: AG15
Getting Started with Visual Prolog
Artificial Intelligence Programming in Prolog Lecture 1: An Introduction 23/09/04.
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.
ARTIFICIAL INTELLIGENCE DR. ABRAHAM AI a field of computer science that is concerned with mechanizing things people do that require intelligent.
Introduction to Prolog Facts, Questions & Rules Atoms & Variables.
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:
CIS2326 Week2: Logic and Prolog Lee McCluskey First term:
PROLOG SYNTAX AND MEANING Ivan Bratko University of Ljubljana Faculty of Computer and Info. Sc. Ljubljana, Slovenia.
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?
Logical and Functional Programming
UNIVERSITI TENAGA NASIONAL CMPB454 ARTIFICIAL INTELLIGENCE (AI) CHAPTER 6 LOGIC PROGRAMMING USING PROLOG CHAPTER 6 LOGIC PROGRAMMING USING PROLOG Instructor:
CS 337 Programming Languages Logic Programming I (Logic, Intro to Prolog)
Logic Programming Dr. Yasser Ahmed Nada Fall 2010/2011 Lecture 2 1 Logic Programming.
COMP307 Artificial Intelligence Xiaoying Gao Victoria University of Wellington Lecture 2:1 
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.
Logic Programming Tarik Booker. What will we cover?  Introduction  Definitions  Predicate Calculus  Prolog  Applications.
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
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.
1 Artificial Intelligence CS370D Prolog programming Declarative meaning of Prolog programs and Lists representation.
1 Artificial Intelligence CS370D Prolog programming Introduction to Prolog.
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
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 programming Introduction to Prolog (part2)
Knowledge Representation and Inference
Chapter Two: Syntax and Meaning of Prolog Programs
Dr. Yasser Nada Fall 2010/2011 Lecture 1
Chapter 2: Prolog (Introduction and Basic Concepts)
Representations & Reasoning Systems (RRS) (2.2)
PROLOG.
Presentation transcript:

Introduction to Prolog

Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples

What is Prolog? Prolog is the most commonly used logic –Simple syntax PROgramming in LOGic High-level interactive language. Logic programming language.

What is Prolog? (Cont.) Programming languages are of two kinds: –Procedural (BASIC, Pascal, C++, Java); –Declarative (LISP, Prolog, ML). In procedural programming, we tell the computer how to solve a problem. In declarative programming, we tell the computer what problem we want solved. (However, in Prolog, we are often forced to give clues as to the solution method).

The use of Prolog Prolog is used in artificial intelligence applications such as: –Natural language interfaces, –automated reasoning systems and –Expert systems: usually consist of a data base of facts and rules and an inference engine, the run time system of Prolog provides much of the services of an inference engine.

What is Prolog used for? Good at –Grammars and Language processing, –Knowledge representation and reasoning, –Unification, –Pattern matching, –Planning and Search. Poor at: –Repetitive number crunching, –Representing complex data structures, –Input/Output (interfaces).

Basic Elements of Prolog A program consists of clauses. These are of 3 types: facts, rules, and questions (Queries). Some are always true (facts): father( ali, haya). Some are dependent on others being true (rules): parent( Person1, Person2 ) :- father( Person1, Person2 ). To run a program, we ask questions about the database. KB Prolog Interpreter Query Answer

Prolog in English Example Database: –Saleh is a teacher –Nora is a teacher –Saleh is the father of Jaber. –Nora is the mother of Jaber. –Hamza is the father of Saleh –Person 1 is a parent of Person 2 if Person 1 is the father of Person 2 or Person 1 is the mother of Person 2. –Person 1 is a grandparent of Person 2 if some Person 3 is a parent of Person 2 and Person 1 is a parent of Person 3. Example questions: –Who is Jaber's father? –Is Nora the mother of Jaber? –Does Hamza have a grandchild? Facts Rules

A knowledge base of facts teacher(saleh). teacher(nora). father( saleh, jaber). mother( nora, jaber ). father( hamza, saleh ). Queries we can ask ?- teacher(saleh).Yes ?- teacher(nora).Yes ?- mother( nora, jaber ).Yes ?- mother( nora, saleh ). No ?- grandparent( hamza, X). Jaber ?- nurse(nora). ERROR: Undefined procedure: nurse/1

More queries we can ask ?-teacher(X). –X=saleh ; –X=nora ; –No. ?-mother(X,Y). –X = nora –Y = jaber ; –No

Syntax: Atoms and Variables Atoms: –All terms that consist of letters, numbers, and the underscore and start with a non-capital letter are atoms: uncle_ali, nora, year2007,.... –All terms that are enclosed in single quotes are atoms: ’Aunt Hiba’, *+ ’,.... –Certain special symbols are also atoms: +,,,.... Variables: –All terms that consist of letters, numbers, and the underscore and start with a capital letter or an underscore are variables: X, Jaber, Lama,.... –_is an anonymous variable: two occurrences of _are different variables. –E.g. if we are interested in people who have children, but not in the name of the children, then we can simply ask: ?- parent(X,_).

Syntax: Complex Terms Complex terms –Complex terms are of the form: functor (argument,..., argument). – Functors have to be atoms. – Arguments can be any kind of Prolog term, e.g., complex terms. likes(lama,apples), likes(amy,X).

Syntax: Facts & Queries Facts are complex terms which begin with lower case alphabetic letter and ends with a full stop. –teacher(nora). –female( aunt hiba). –likes(alia,choclate). Queries are also complex terms followed by a full stop. –?- teacher(nora). Query Prompt provided by the Prolog interpreter.

Syntax: Rules A Prolog rule consists of a head and a body. a(X) :- b(X), c(X) Rules are of the form Head :- Body. Like facts and queries, they have to be followed by a full stop. Head is a complex term. Body is complex term or a sequence of complex terms separated by commas. happy(uncle_ yussef) :- happy(nora). grandparent( Person1, Person2 ) :- parent( Person3, Person2 ), parent( Person1, Person3 ). head body

A knowledge base of facts & Rules happy(uncle _ yussef ) :- happy(nora). if... then...: If happy(nora) is true, then happy(uncle_ yussef) is true. parent( Person1, Person2 ) :- father( Person1, Person2 ). parent( Person1, Person2 ) :- mother( Person1, Person2 ). Person 1 is a parent of Person 2 if Person 1 is the father of Person 2 or Person 1 is the mother of Person 2. grandparent( Person1, Person2 ) :- parent( Person3, Person2 ), parent( Person1, Person3 ). Person 1 is a grandparent of Person 2 if some Person 3 is a parent of Person 2 and Person 1 is a parent of Person 3.

Querying slide 15 ?- happy(nora).Yes ?-happy(uncle_yussef). yes ?- happy(X). –X = uncle_yussef ; –X = nora ; –No Does Hamza have a grandchild? ?- grandparent(hamza,_). –Yes

Facts & Rules containing variables teacher(saleh). teacher(nora). father( saleh, jaber). mother( nora, jaber ). This knowledge base defines 3 predicates: –teacher/1. –father/2, and –mother/2. teacher(X) :- father(Y,X), teacher(Y),mother(Z,X), teacher(Z). For all X, Y, Z, if father(Y,X)is true and teacher (Y) is true and mother(Z,X) is true and teacher (Z) is true, then teacher (X) is true. I.e., for all X, if X’s father and mother are teachers, then X is a teacher.

Summary A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-.... –Query: ?-.... –Variables: must begin with an upper case letter or underscore. Nora, _nora. –Constants (atoms): begin with lowercase letter, or enclosed in single quotes. uncle_ali, nora, year2007,. numbers 3, 6, 2957, 8.34,... –complex terms An atom (the functor) is followed by a comma separated sequence of Prolog terms enclosed in parenthesis (the arguments). likes(lama,apples), likes(amy,X).