Professional Documents
Culture Documents
Spring 2011
1. 2. 3. 4. 5. 6. 7. 8.
History Of Prolog Language A Brief Identification Basic Elements and How to Program? Syntax and semantics & Some Examples Usages Why Prolog? Criticisms About this language References
Date Of Creation :
Around 1972
Robert Kowalski
Brief Identification
Prolog is a general purpose logic programming language associated with artificial intelligence
and computational linguistics. There is some Useful Information :
1. Paradigms : Logic Programming ( It should be mentioned here that there are many extensions of Prolog with other Paradigms features)
2. Some Features Of Prolog : Declarative , Reflective , Rule-based & High-level interactive language.
Brief Identification
3. Major implementations (Extensions) :
HiLog and Prolog extend Prolog with higher-order programming features. Logtalk and Oblog are some prolog extension with Object Orientation features. SWI-prolog , Visual-prolog and B-Prolog are some Prolog systems that
provide a graphics library.
Some Prolog implementations, notably SWI-Prolog, support server-side web programming with support for web protocols, HTML and XML.
4. Usual File Extensions : .PL & .PRO
5. Web-site : ????????????????????????????????
Procedural : (BASIC, ForTran, C++, Pascal, Java); Declarative : (LISP, Prolog, ML).
In procedural programming, we tell the computer In declarative programming, we tell the computer
(However, in Prolog, we are often forced to give clues as to the solution method).
database. (Queries)
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.
The Prolog comment characters: Single line comments: (%) % This is a comment This is not a comment, but an error
Multiple line comments: ( /* */ ) /* This is a multi-line comment which must be closed with a */
Prolog's single data type is the term. Terms are either atoms, numbers, variables or compound terms.
3)Variables are denoted by a string consisting of letters, numbers and underscore characters, and beginning with an upper-case letter or underscore. Variables closely resemble variables in logic in that they are placeholders for arbitrary terms.
4)A compound term is composed of an atom called a "functor" and a number of "arguments", which are again terms.
Given the beside fact, one can ask: is tom a cat? ?- cat(tom). Yes what things are cats? ?- cat(X). X = tom
which is equivalent to the rule: cat(tom) :- true. An example of a rule is: animal(X):- cat(X).
| ?- greetings. What is your name? |: tim. Hello tim X = tim ? yes Terminal
mother_child(trude, sally). father_child(tom, sally). Prolog Code father_child(tom, erica). father_child(mike, tom). sibling(X, Y) :- parent_child(Z, X), parent_child(Z, Y). parent_child(X, Y) :- father_child(X, Y). parent_child(X, Y) :- mother_child(X, Y).
This results in the following query being evaluated as true: ?- sibling(sally, erica). Terminal Yes
Recursive Definitions
For all X and Y X is in Ys food chain if Y eats X
or Y eats some Z and X is in Zs food chain: food_chain(X,Y) :- eats(Y,X). food_chain(X,Y) :- eats(Y,Z), food_chain(X,Z). Afterwards we can ask: ?-food_chain(X,rat). X=salmon ; X=worm Or: ?-food_chain(worm,X). X=rat ; X=bear
Hello world !
As an example of a query:
?- write('Hello world!'), nl. Hello world! true. ?-
Artificial intelligence or any Intelligent systems Complicated knowledge databases Natural language processing Logic data analysis intelligent data base retrieval natural language understanding expert systems specification language machine learning robot planning automated reasoning problem solving
Prolog is interactive. It comes with a toplevel interpreter: a command interface that you can type code at and get it executed immediately. Prolog is fast. Some extensions like SWI-Prolog are free, open-source, and very well maintained. Unlike many other programming languages, Prolog is declarative
Complicated syntax
Difficult to understand programs at first sight Programming in the large is considered to be complicated because not all Prolog compilers support modules, and there are compatibility problems between the module systems of the major Prolog compilers. Portability of Prolog code across implementations has also been a problem
The slides included information was taken from the Site Wikipedia And Books: 1) Learn Prolog Now!, Patrick Blackburn, Johan Bos, Kristina Striegnitz, 2006
2) PROLOG Programming for Artificial Intelligence, William F. Clocksin, Christopher S., 2000
3) Programming in Prolog: Using the ISO Standard. Springer, 5th ed., 2003