Basics of PROLOG
Basics of PROLOG
RESHMA R
ASSISTANT
PROFESSOR
CSE, KAHE
A Little History
Prolog was invented by Alain Colmerauer, a
professor of computer science at the
university of Aix-Marseille in France, in
1972
The first application of Prolog was in natural
language processing
Prolog stands for programming in logic
(PROgrammation en LOgique)
Its theoretical underpinning are due to
Donald Loveland of Duke university through
Robert Kowalski (formerly) of the university
of Edinburgh
Logic Programming
Prolog is the only successful example of the
family of logic programming languages
A Prolog program is a theory written in a
subset of first-order logic, called Horn
clause logic
Prolog is declarative. A Prolog programmer
concentrates on what the program needs to
do, not on how to do it
The other major language for Artificial
Intelligence programming is LISP, which is a
functional (or applicative) language
Defining Relations by Facts
parent( tom,bob).
parent is the name of a relation
A relation of arity n is a function from n-tuples
(elements of a Cartesian product) to {true, false}.
(It can also be considered a subset of the n-tuples.)
parent( pam, bob). parent( tom,bob).
parent( tom,liz). parent( bob, ann). parent(
bob,pat). parent( pat,jim).
A relation is a collection of facts
Queries
?-parent( bob,pat).
yes
A query and its answer, which is correct for
the relation defined in the previous slide:
this query succeeds
?-parent( liz,pat).
no
A query and its answer, which is correct for
the relation defined in the previous slide:
this query fails
More Queries
cf. pr1_1.pl
?-parent( tom,ben). /* who is Ben? */
?-parent( X,liz).
?-parent( bob,X). /* Bob’s children */
?-parent( X,Y). /* The relation, fact by fact */
Composite Queries
Grandparents:
?-parent( Y,jim), parent( X,Y).
the comma stands for “and”