1 / 25

PROLOG

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

alisa
Download Presentation

PROLOG

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PROLOG “Programmationen Logique” Juan ChenCory TaylorLucas LopesJustin Khan

  2. Topics covered • Compilers • History of the Language • Features of the language • Modifications and sub-branches • Modern use of language

  3. History • Created by Alain Colmerauer and Philippe Rousselin 1972 • Grouped'IntelligenceArtificielle • 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

  4. Other Offshoots of Prolog • CLP(R) • CHIP • Prolog III • Trilogy • HCLP • FCP • Strand

  5. More on Prolog • Declarative Logic Language • Among the first logic programming languages • Original purpose: Natural Language Processing • Current Use: (predominately) A.I. Programming • Still very popular • Prolog standardization created in 1995 • Individual parts of the language defined to ensure the language core is fixed.

  6. 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

  7. 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.

  8. 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

  9. 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.

  10. Syntax • Program logic is expressed in terms of relations • Computations are queries over these relations • Single data type: TERM • Relations defined by clauses

  11. The TERM • Terms are divided amongst many different sub-types • Atom • Numbers • Variables • Compound Term

  12. Compound Terms • Compound terms can be further divided into a few special cases • Lists • Strings

  13. Features • Supports recursion • Relational Databases • Natural Language processing • Query Database Commands • Unification

  14. Features • Prolog automatically searches for an answer • Quantification Logic • 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

  15. 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.”

  16. 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. • Query • When 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.

  17. 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:

  18. 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

  19. 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 ;

  20. 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).

  21. 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()

  22. 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.

  23. Sample programs • Hello World • Recursion • Books • Query Exploration. • Lists

  24. 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

  25. 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

More Related