Practical Work of AI
Practical Work of AI
Topic:
Prolog Programming
Submitted to:
MRS. Ayesha
Submitted by:
Faiza Altaf
Roll no.
926412
Course title:
Artificial Intelligence
Semester:
6th BSCS
Govt. Islamia College for Woman FSD
Some examples program: defining family relations
Prolog is a programming language for symbolic, non-numeric computation. It is specially well
suited for solving problems that involve objects and relations between objects. Figure 1.1
shows an example: a family relation. The fact that Tom is a parent of Bob can be written in
Prolog as: parent( tom, bob). Here we choose parent as the name of a relation; tom and bob
are its arguments. For reasons that will become clear later we write names like tom with an
initial lower-case letter. The whole family tree is defined by the following Prolog program:
parent( pam, bob).
parent( tom, bob).
parent( tom, liz).
parent( bob, ann).
parent( bob, pat).
parent( pat, jim).
parent( X, liz).
parent( bob, X).
1.1 Assuming the parent relation as defined in this section (see Figure 1.1), what
will be Prolog's answers to the following questions?
parent( Y, jim), parent( X, Y).
parent( Y, jim), parent( X, Y).
parent( jim, X).
parent( X, jim).
parent( paffi, X), parent( X, pat).
parent( paffi, X), parent( X, Y), parent( Y, jim).
1.2 Formulate in Prolog the following questions about the parent relation:
(a) Who is Pat's parent?
Offsprings:
mother( X, Y) :- parent( X, Y), female( X).
grandparent(X, Z) :- parent( X, Y), parent( Y, Z).
grandparent(X, Z) :- parent( X, Y), parent( Y, Z).