Chapter 14: Introduction to prolog
14.1 Converting English to Prolog:
Here are few sentences converted into PROLOG.
English: PROLOG:
The cakes are Delicious. delicious(cakes).
The pickles are delicious. delicious(pickles).
Biryani is delicious. delicious(biryani).
The pickles are spicy. spicy(pickles).
Priya relishes Coffee. relishes(priya,coffee).
Priya likes food if they are delicious. likes(priya,Food):-delicious(Food).
Prakash likes food if they are spicy and likes(prakash,Food):-
delicious. spicy(Food),delicious(Food).
In PROLOG:
Ifs have been replaced by (:-).
Commas have been replaced by (,).
Rule and Goal is terminated by a (.).
Comments could be of any of the following forms:
%this comments only this line.
/* this comments everything in between the asterisks and the slashes. */
KINJAL PATEL[AI-Introduction to Prolog] Page 1
, LJIET 2020
14.2 Goals:
Now compile the program.
Suppose we wish to ask the program:
“Which food items are delicious?”
This, in PROLOG terminology, is called GOAL and is presented on the ?-
prompt as :
?-delicious(Food).
Food = cakes
Press ; to get the remaining alternatives for Food viz.
Food = pickles;
Food = biryani
Try the goal:
?-likes (priya , Food).
Food = cakes;
Food = pickles;
Food = biryani
You could ask other questions like:
Who relishes coffee and also likes pickles?
Using goal given below:
?-relishes(Who , coffee),likes(Who , pickles).
Who = priya
14.3 Prolog Terminology
1. Predicates:
A predicate name is the symbol used to define a relation.
For instance: relishes(priya , coffee) where relishes is predicate while the
contents within viz. priya and coffee comprise its arguments.
2. Clauses:
Clauses are the actual rules and facts that constitute the PROLOG program.
KINJAL PATEL[AI-Introduction to Prolog] Page 2