Rules Statements about objects and their relationships Expess ◦ If-then conditions  I use an umbrella if there is a rain  use(i, umbrella) :- occur(rain).

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 Two possible work modes: 1.At the lab: Use SICstus Prolog. To load a prolog file (*.pl or *.pro extension) to the interpreter, use: ?-
Chapter 11 :: Logic Languages
Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
11/10/04 AIPP Lecture 6: Built-in Predicates1 Combining Lists & Built-in Predicates Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
CS344 : Introduction to Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 16- 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).
CSE 425: Logic Programming I Logic and Programs Most programs use Boolean expressions over data Logic statements can express program semantics –I.e., axiomatic.
Prolog: Unification & Recursion © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
For Friday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Logic Programming About the course –Taught in English –Tuesday: mostly theory –Thursday: practical.
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
© 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.
Prolog Programming Lecture Module 13. Objective ● What is Prolog? ● Prolog program ● Syntax of Prolog ● Prolog Control Strategy ● Execution of Prolog.
INFERENCE IN FIRST-ORDER LOGIC IES 503 ARTIFICIAL INTELLIGENCE İPEK SÜĞÜT.
CS344 : Introduction to Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 22, 23- Prolog.
DEDUCTIVE DATABASE.
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.
CS 321 Programming Languages and Compilers Prolog part 2.
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.
CS 403: Programming Languages Lecture 19 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
14/10/04 AIPP Lecture 7: The Cut1 Controlling Backtracking: The Cut Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 7 14/10/04.
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.
15/11/04 AIPP Lecture 14: Database Manipulation1 Database Manipulation Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 14 15/11/04.
CSC 270 – Survey of Programming Languages Prolog Lecture 2 – Unification and Proof Search.
1 Knowledge Based Systems (CM0377) Lecture 3 (Last modified 5th February 2001)
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.
Logic Programming CSC 358/ Outline Pattern matching Unification Logic programming.
Ch. 13 Ch. 131 jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (notes?) Dr. Carter Tiernan.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 21.
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.
Introduction to Prolog
Introduction to Prolog © Patrick Blackburn, Johan Bos & Kristina Striegnitz.
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.
C. Varela1 Logic Programming (PLP 11, CTM 9.1) Terms, Resolution, Unification, Search, Backtracking (Prolog) Relational Computation Model (Oz) Carlos Varela.
In The Name Of Allah Lab 03 1Tahani Aldweesh. objectives Searching for the solution’s. Declaration. Query. Comments. Prolog Concepts. Unification. Disjunction.
Prolog 3 Tests and Backtracking 1. Arithmetic Operators Operators for arithmetic and value comparisons are built-in to Prolog = always accessible / don’t.
07/10/04 AIPP Lecture 5: List Processing1 List Processing Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 5 07/10/04.
1 TP #2: How does Prolog answer questions? n Miscellaneous info; n Last TP exercises solved; n How does Prolog answer questions? n Recursive Prolog programs;
Prolog Fundamentals. 2 Review Last Lecture A Prolog program consists of a database of facts and rules, and queries (questions). –Fact:.... –Rule:... :-....
Instructor :Bayan Ghozlan الاستاذه : بيان غزلان.  البرولوغ Prolog هي لغة برمجة منطقية. وتعني برمجه المنطق programing language  تم اختراع اللغة بواسطة.
O A procedure: a set of axioms (rules and facts) with identical signature (predicate symbol and arity). o A logic program: a set of procedures (predicates),
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
Matching Matching and unification. Rules for matching terms. Examples of matching. –The most general instantiation. Computation using matching.
A Conjunction is a logical operator that connects two logical terms.
PROLOG.
Tests, Backtracking, and Recursion
Prolog fundamentals Module 14.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Chapter 11 :: Logic Languages
Prolog syntax + Unification
© Patrick Blackburn, Johan Bos & Kristina Striegnitz
Chapter 12 :: Logic Languages
Chapter 12 :: Logic Languages
PROLOG.
Presentation transcript:

Rules Statements about objects and their relationships Expess ◦ If-then conditions  I use an umbrella if there is a rain  use(i, umbrella) :- occur(rain). ◦ Generalizations  All men are mortal  mortal(X) :- man(X). ◦ Definitions  An animal is a bird if it has feathers  bird(X) :- animal(X), has_feather(X).

Matching Artificial Intelligence Programming in Prolog LAB 4 2

the =/2 predicate tests whether its two arguments match. For example, if we pose the query: =(mia,mia). =(mia,vincent). Prolog will respond ‘no’. mia = mia. yes

4 The central ideas of Prolog MATCHING –any two data items can be compared for similarity, and values can be bound to variables in order to allow a match to succeed.  If term1 and term2 are constants.  If term1 is a variable and term2 is any type of term, then term1 and term2 match, and term1 is instantiated to term2. And vica versa.

 If term1 and term2 are complex terms, then they match if and only if: (a) They have the same functor and arity. (b) All their corresponding arguments match (c) and the variable instantiations are compatible. (I.e. it is not possible to instantiate variable X to mia, when matching one pair of arguments, and to then instantiate X to vincent, when matching another pair of arguments.)

Let’s try an example with a variable: mia = X. X = mia yes

Now, let’s look at an example involving complex terms: kill(shoot(gun),Y) = kill(X,stab(knife)). X = shoot(gun) Y = stab(knife) yes

?- X=mia, X=vincent. no  ?- k(s(g),Y) = k(X,t(k)). X=s(g) Y=t(k) yes ?- k(s(g),t(k)) = k(X,t(Y)). X=s(g) Y=k yes

?- loves(X,X) = loves(marsellus,mia). no

10 Structure unification 2 structures will unify if ◦ the functors are the same, ◦ they have the same number of components, ◦ and all the components unify. | ?- person(Nm,london,Age) = person(bob,london,48). Nm = bob, Age = 48? yes | ?- person(Someone,_,45) = person(harry,dundee,45). Someone = harry ? yes (A plain underscore ‘_’ is not bound to any value. By using it you are telling Prolog to ignore this argument and not report it.)

11 Structure unification (2) A structure may also have another structure as a component. |?-addr(flat(4),street(‘Home Str.’),postcode(eh8_9lw)) = addr(flat(Z),Yy,postcode(Xxx)). Z = 4, Yy = street(‘Home Str.’), Xxx = eh8_9lw ? yes Unification of nested structures works recursively: ◦ first it unifies the entire structure, ◦ then it tries to unify the nested structures. Remember to close brackets! Reported variables are ordered according to number of characters in the variable name.

12 Structures = facts? The syntax of structures and facts is identical but: ◦ Structures are not facts as they are not stored in the database as being true (followed by a period ‘.’); ◦ Structures are generally just used to group data; ◦ Functors do not have to match predicate names. However predicates can be stored as structures command(X):- X. | ?- X = write(‘Passing a command’), command(X). Passing a command X = write('Passing a command') ? yes By instantiating a variable with a structure which is also a predicate you can pass commands.

Exercises

SEARCH TREE

Another Example

21 Summary Prolog’s proof strategy can be represented using AND/OR trees. Tree representations allow us trace Prolog’s search for multiple matches to a query. They also highlight the strengths and weaknesses of recursion (e.g. economical code vs. infinite looping). Recursive data structures can be represented as structures or lists. Structures can be unified with variables then used as commands. Lists can store ordered data and allow its sequential processing through recursion.