0% found this document useful (0 votes)
56 views

Practical Work of AI

This document discusses examples of Prolog programming to define family relations. It provides a Prolog program that defines the parent relation between various family members like Tom, Bob, Pam, Liz, Ann, Pat and Jim. It then asks questions about determining relationships based on this parent relation, like who is Pat's parent or grandparent. It also discusses extending the example by adding rules to define relations like mother, grandparent, and translations of statements into Prolog rules.

Uploaded by

Mughal G
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Practical Work of AI

This document discusses examples of Prolog programming to define family relations. It provides a Prolog program that defines the parent relation between various family members like Tom, Bob, Pam, Liz, Ann, Pat and Jim. It then asks questions about determining relationships based on this parent relation, like who is Pat's parent or grandparent. It also discusses extending the example by adding rules to define relations like mother, grandparent, and translations of statements into Prolog rules.

Uploaded by

Mughal G
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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?

(b) Does Liz have a child?

(c) Who is Pat's grandparent?


Solutions:
Extending the example program by rules
female( pam).
male( tom).
sex( pam, feminine).
sex( tom, masculine).
sex( bob, masculine).

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

1.3 Translate the following statements into prolog rules:


(a) Everybody who has a child is happy (introduce a one-argument relation
happy).
(b) For all X, if X has a child who has a sister then X has two children (introduce
new relation hastwochildren).
1.4 Define the relation grandchild using the parent relation. Hint: It wilt be similar
to the grandparent relation (see Figure 1.3).
1.5 Define the relation aunt( X, Y) in terms of the relations parent and sister. As an
aid you can first draw a diagram in the style of Figure 1.3 for the aunt relation.
1.6 Consider the following alternative definition of the predecessor relation:
predecessor(X, Z) :- parent( X, Z).
predecessor(X, Z) :- parent( Y, Z), predecessor( X, Y).

You might also like