25
PROLOG “Programmation en Logique” Juan Chen Cory Taylor Lucas Lopes Justin Khan

PROLOG

  • Upload
    alisa

  • View
    31

  • Download
    1

Embed Size (px)

DESCRIPTION

PROLOG. “ Programmation en Logique ” Juan Chen Cory Taylor Lucas Lopes Justin Khan. Topics covered. Compilers History of the Language Features of the language Modifications and sub-branches Modern use of language. History. Created by Alain Colmerauer and Philippe Roussel in 1972 - PowerPoint PPT Presentation

Citation preview

Page 1: PROLOG

PROLOG

“Programmation en Logique”

Juan ChenCory Taylor

Lucas LopesJustin Khan

Page 2: PROLOG

Topics covered

CompilersHistory of the LanguageFeatures of the languageModifications and sub-branchesModern use of language

Page 3: PROLOG

History Created by Alain Colmerauer and Philippe Roussel in 1972

Groupe d'Intelligence Artificielle University of Marseille With collaboration from Robert Kowalski of University of Edinburgh Researching automatic proving of theorems Then branched out into other dialects Main branches stayed in their respective universities

Page 4: PROLOG

Other Offshoots of PrologCLP(R)

CHIPProlog III

TrilogyHCLP

FCPStrand

Page 5: PROLOG

Declarative Logic LanguageAmong the first logic programming languagesOriginal purpose: Natural Language Processing

Current Use: (predominately) A.I. Programming

Still very popularProlog standardization created in 1995Individual parts of the language defined to ensure the language core is fixed.

More on Prolog

Page 6: PROLOG

WARREN ABSTRACT MACHINE (WAM) Developed in 1983

Ushered the “Wonder years” of prolog implementation

A structure-copying execution model for PROLOG

Standard implementation technique High level instruction set

Extremely memory efficient

Page 7: PROLOG

Vienna Abstract Machine (VAM) Considerably faster than WAM VAM does argument setup and Argument

Unification Simultaneously These are then combined into a single

operation, saving work-time.

Page 8: PROLOG

List of PROLOG compilers BinProlog SWI Prolog (what we will be using later) GNU Prolog Kernel Prolog Open Prolog Allegro Prolog ECLiPSe Prolog And several others

Page 9: PROLOG

Modern Use A.I. Programming

NASA's “clarissa” in the ISS

Database Design and Implementation www.intologic.com's MOVIS software – companies like Ericsson use the

graphical prolog tool for rule-based systems and business solutions

Computer Science Teaching Tool Used in colleges for instruction in A.I.

Expert Systems (Human Level Decision Making) Expert Systems tutorials in prolog include an E.S. that solves a rubik's

cube.

Page 10: PROLOG

Syntax

Program logic is expressed in terms of relations

Computations are queries over these relations Single data type: TERM Relations defined by clauses

Page 11: PROLOG

The TERM

Terms are divided amongst many different sub-types

Atom Numbers Variables Compound Term

Page 12: PROLOG

Compound Terms

Compound terms can be further divided into a few special cases

Lists Strings

Page 13: PROLOG

Features

Supports recursion Relational Databases Natural Language processing Query Database Commands Unification

Page 14: PROLOG

Features

Prolog automatically searches for an answerQuantification Logic

o a variable can have attributes---in other words, it is not just "If A and B then C" it can also be "If A(a,b,c) and B(m,n) then C(a,b,n)" where a, b, c, m and n are attributes of A, B and C. For example: If Between(x,y,z) and Between(x,k,y) then Between(x,k,z)" would be hard to express in any other language---it would certainly take more than one line in any other language

Page 15: PROLOG

RULES AND FACTS

PROLOG programs describe relations, defined by means of clauses.

Rules are of the form: “Life:-Heartbeat.” That is read as: “Life is true if Heartbeat is true”

Facts are of the form: “cat(Nyan).” Which is equivalent to the rule: “cat(Nyan):-true.”

Page 16: PROLOG

How to program prolog

Program

Contain the facts and rules that will be used by the user of the program. It contains all the relations that makes a program. QueryWhen you launch a program you are in query mode. This mode is represented by the sign ? - at the beginning of the line. In query mode you ask questions about relations described in the program.

Page 17: PROLOG

Facts

Facts

factname..

In Prolog we can make some statements by using facts. Facts either consist of a particular item or a relation between items.

?-factname.We can ask a query of Prolog by asking like this.

Facts with arguments relation(<argument1>,<argument2>,....,<argumentN> ).More complicated facts consist of a relation and the items that this refers to. These items are called arguments. Facts can have arbitrary number of arguments from zero upwards. A general model is shown below:

Page 18: PROLOG

Variables How do we ask

eats(cory, apples).

?-eats(cory, what).

Wrong, “what” is not an legal variable What are legal variables? Capitial letters at the start

?-eats(cory,What).

What = apples. ?-eats(Who,apples).

Who = cory. Now say we have the following in our database of facts

eats(cory, apples). eats(cory,banana).

If we ask ?- eats(cory,What). We get

What = apples. What = banana

Page 19: PROLOG

Unification

Consider we have a library.

book(1,hitchhikersguide,adams).

book(2,themeaningofliff,adams).

book(3,title3,author2).

book(4,title4,author3).

Query you could ask

?- book(_,_,adams).

It would respond with a TRUE output, saying that that is indeed an author.

If we wanted to know which book adams wrote. We would ask it like this.

?- book(_,X,adams). This would give us a response of below.

X=hitchhikersguide ; X=themeaningofliff ;

Page 20: PROLOG

Rules

Consider the following sentence : 'All men are mortal' We can express this thing in Prolog by :

mortal(X) :- human(X).

The clause can be read as 'X is mortal if X is human'.

To continue with this example, let us define the fact that Socrate is a human. Our program will be

mortal(X) :- human(X).

human(socrate).

Now if we ask to prolog :

?- mortal(socrate).

Prolog will respond :

Yes

In order to solve the query -? mortal(socrates). Prolog uses the rule we gave it. In order to prove that someone is mortal we can prove that he is human. So from the goal mortal(socrate) Prolog generate the subgoal human(socrate).

Page 21: PROLOG

Adding Rules

You can also add rules or facts with the instruction for example. Assert(fact1) which will add the fact called fact1.

The predicates added with this command are considereted like any other in the source of the program.

assert(c). Add the rule c in the database.assert()

retract(c). Remove the c from the database.retract(c)

asserta(c). Add c at the beginning of the database.asserta()

assertz(c). Add c at the end of the database.assertz()

Page 22: PROLOG

Compiler

The compiler we used for this demonstration was called SWI-Prolog

It was created by Jan Wielemaker from the University of Amsterdam, department of Social Science Informatics .

It was written in ASCI-C and should configure nicely with most Unix machines that have an ASCI-C compiler.

Ports where made for Linux, Windows, MacOSX.

It is open source “free”.Information should be free yo.

Page 23: PROLOG

Sample programs

Hello World Recursion Books Query Exploration. Lists

Page 24: PROLOG

Operators

=,is,<,>,=<,>=,==,=:=,/,*,+,-,mod,div Binary trees

– y*5+10*x are written in Prolog : +(*(y,5),*(10,x)).

Prolog uses “is”

X is 3 + 4.

Prolog responds

X = 7

yes

Page 25: PROLOG

Bibliography● www.stackoverflow.com● www.learnprolognow.org● www.intologic.com● http://homepages.cwi.nl/~apt/ps/a-mit.pdf● http://en.wikipedia.org/wiki/Prolog● www.mta.ca/~rrosebru/oldcourse/371199/

prolog/history.htm● http://groups.engin.umd.umich.edu/CIS/

course.des/cis400/prolog/prolog.html