COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

Prolog Programming (Volume 2) Dr W.F. Clocksin. Lists Lists are the same as other languages (such as ML) in that a list of terms of any length is composed.
CS344: Introduction to Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 12–Prolog examples: Himalayan club, member, rem_duplicate,
Logic Programming Lecture 1: Getting started. Getting started We’ll use SICStus Prolog Free for UofE students Available on all DICE machines
1. An Overview of Prolog.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
Prolog.
Introduction to PROLOG ME 409 Lab - 1. Introduction to PROLOG.
Prolog The language of logic. History Kowalski: late 60’s Logician who showed logical proof can support computation. Colmerauer: early 70’s Developed.
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).
Prolog Programming for Artificial Intelligence Three edition 2001
About prolog  History  Symbolic Programming Language  Logic Programming Language  Declarative Programming Language.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
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/
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
(9.1) COEN Logic Programming  Logic programming and predicate calculus  Prolog statements  Facts and rules  Matching  Subgoals and backtracking.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Formal Models of Computation Part II The Logic Model
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
COSC 2P93 Logic Programming Instructor: Brian Ross Instructor: Brian Ross Texts: Texts: Prolog Programming for Artificial Intelligence,4e, Ivan Bratko,
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
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.
15/11/04 AIPP Lecture 14: Database Manipulation1 Database Manipulation Artificial Intelligence Programming in Prolog Lecturer: Tim Smith Lecture 14 15/11/04.
Artificial Intelligence Programming in Prolog Lecture 1: An Introduction 23/09/04.
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.
1 COMP 205 Introduction to Prolog Dr. Chunbo Chu Week 14.
For Monday Read “lectures” 1-5 of Learn Prolog Now: prolog-now/
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
UNIVERSITI TENAGA NASIONAL CMPB454 ARTIFICIAL INTELLIGENCE (AI) CHAPTER 6 LOGIC PROGRAMMING USING PROLOG CHAPTER 6 LOGIC PROGRAMMING USING PROLOG Instructor:
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
CS 403: Programming Languages Lecture 18 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
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.
MB: 26 Feb 2001CS Lecture 11 Introduction Reading: Read Chapter 1 of Bratko Programming in Logic: Prolog.
Knowledge Based Information System
For Friday No reading Prolog Handout 2. Homework.
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”
Pengenalan Prolog Disampaikan Oleh : Yusuf Nurrachman, ST, MMSI.
Section 16.5, 16.6 plus other references
For Friday No reading Prolog handout 3 Chapter 9, exercises 9-11.
For Wednesday Read “lectures” 7-10 of Learn Prolog Now:
Dr. Yasser Nada Fall 2010/2011 Lecture 1
Chapter 2: Prolog (Introduction and Basic Concepts)
PROLOG.
Presentation transcript:

COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University pursuant to Part VB of the Copyright Act 1968 (the Act). The material in this communication may be subject to copyright under the Act. Any further reproduction or communication of this material by you may be the subject of copyright protection under the Act. Do not remove this notice.

Prolog CSE2303 Formal Methods I Lecture 20

Overview Prolog Database List Arithmetic Implementing NFA Towers of Hanoi SWI-Prolog

Prolog PROgramming in LOGic Used for solving problems between objects and the relationships between objects. A logic program is a finite set of program clauses. Programs clauses are: –Facts. –Rules.

Parent Relationship We represent the statement: “bob is a parent of pat” as parent(bob, pat). The compound statement “If X is a parent of Z, then X is a predecessor of Z” is represented as: predecessor(X, Z) :- parent(X,Z).

database parent(bob, ann). parent(bob, pat). parent(pat, jim). predecessor(X, Z) :- parent(X,Z). predecessor(X, Z) :- parent(X,Y), predecessor(Y, Z). Facts Rules Constants Variables

Using Prolog To read in the file database. Type: [database]. To ask if bob is the parent of pat. Type: parent(bob, pat). To ask who is the predecessors of jim. Type: predecessor(X, jim). To quit. Type: ctrl-D

Example Session ?- [database]. ?- parent(bob, pat). yes ?- parent(bob, jim). no ?- predecessor(X, jim). X = pat ; X = bob ; no Nothing matches no prompt Ask for another solution

Program Clauses Rule –The head and the body are nonempty. –The body is the conditional part. –The head is the conclusion. Fact –The body is empty, and is written as: A.A. A :- B 1, …, B n. Head Body End of clause marker “ if ”

Interpretations Logic  X 1,..X m ((B 1  …  B n )  A) Procedural –To execute A, first execute B 1, then execute B 2,... Process –A, B 1, …, B n are considered processes. –Shared variables are communication channels A :- B 1, …, B n.

Syntax Constants –Names: which always begin with a lowercase letter. likes mary parent predecessor –Numbers: Variables –Always begin with either an capital letter or an underline character. X Answer _ _Input Structures –Compound terms. owns(john, book) parent(X, parent(Y, jim))

Lists A list t 1,…, t n can be represented as: [t 1,…, t n ] For example: [a,b,c,d] Also represented as: [a | b,c,d] The empty list is [ ] Head of the list Tail of the list

Membership Problem Write a Prolog program which finds the members of a list.

Membership Relationships X is always a member of a list whose head is X. member(X, [X | T]). If X is a member of a list T, then X is a member of a list whose tail is T. member(X, [H | T]) :- member(X, T).

Member member(X, [X | T]). member(X, [H | T]) :- member(X, T). ?- member(john, [paul, john]). yes ?- member(X, [paul, john]). X = paul ; X = john ; no

Arithmetic Operators –X + Y, -X, X-Y, X*Y, X/Y, … Functions –abs(X), max(X, Y), sin(X), … Relations –X Y, X =< Y, X =:= Y, X =\= Y,.. –is “Evaluates arithmetic expression” ?- X is 2* X = 10 yes

Factorial Relationships The factorial of 0 is 1. factorial(0,F) :- F is 1. If N > 0, and N1 is N – 1, and the factorial of N1 is F1, and F is N*F1, then the factorial of N is F. factorial(N, F) :- N > 0, N1 is N-1, factorial(N1, F1), F is N*F1.

Factorial factorial(0, F) :- F is 1. factorial(N, F) :- N > 0, N1 is N-1, factorial(N1, F1), F is N*F1. ?- factorial(3, F). F = 6 yes

Size Relationships The size of an empty list is 0. size([ ], 0). If the size of the list T is N1 and N is N1+1, then the size of the list with tail T is N. size([H | T], N) :- size(T, N1), N is N1+1.

Size size([ ], 0). size([H | T], N) :- size(T, N1), N is N1+1. ?- size([a,b,c], N). N = 3 yes Note: There is a predefined funtion in SWI-Prolog called length

accept(W) :- start(S), path(S, W). path(S, [ ]) :- final(S). path(S, [H | T]) :- arc(S, H, N), path(N, T). start(1). final(3). arc(1, a, 1). arc(1, b, 2). arc(1, b, 3). arc(2, b, 3). arc(3, a, 3). a a b b b ?- [nfa]. ?- accept([a, b, a]). yes NFA

Towers of Hanoi The object is to move the disks, one at a time, from the left peg to the right peg. You are allowed to use the middle peg. At no stage are you allowed to place a bigger disk on top of a smaller one.

Solution move(1, X, Y, Z) :- write(’ Move top disk from ’), write(X), write(’ to ’), write(Z), nl. move(N, X, Y, Z) :- N > 1, M is N-1, move(M, X, Z, Y), move(1, X, Y, Z), move(M, Y, X, Z). ?- move(3, left, middle, right).

More Information Courseware web site. Links to: –Prolog tutorial, SWI-Prolog, etc. Books: –“The Art of Prolog: Advanced Programming Techniques”, by L.Sterling and E. Shapiro. –“Prolog Programming for Artificial Intelligence”, by I. Bratko. –“Programming in Prolog”, by W. Clocksin and D. Mellish