100% found this document useful (1 vote)
375 views6 pages

Ambo University Woliso Campus

This document contains a lab exercise assignment on representing family relationships in Prolog. It includes: 1) A family tree that is transformed into Prolog facts describing parent and child relationships. 2) Prolog rules defined to identify relationships like sister, brother, cousin, grandfather, and more. 3) Example Prolog queries to check relationships in the family tree like if two individuals are sisters or cousins.

Uploaded by

Tolosa Tafese
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
375 views6 pages

Ambo University Woliso Campus

This document contains a lab exercise assignment on representing family relationships in Prolog. It includes: 1) A family tree that is transformed into Prolog facts describing parent and child relationships. 2) Prolog rules defined to identify relationships like sister, brother, cousin, grandfather, and more. 3) Example Prolog queries to check relationships in the family tree like if two individuals are sisters or cousins.

Uploaded by

Tolosa Tafese
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

AMBO UNIVERSITY WOLISO CAMPUS

SCHOOL OF TECHNOLOGY AND INFORMATICS


DEPARTEMENT OF INFORMATION TECHNOLOGY

Course Name:- Artificial Intelligenc e


Course Code:-ITec4151
Author Name:- misgana muleta
ID Number:- 258999/11

Email: misgenamuleta@gmail.com

Submitted to:- Mr. Million

Woliso, Ethiopia
Lab Exercise Assignment

Lab Exercise Assignment


1. Transform the following family tree into facts

Here from this tree, we can understand that there are many relationships. Here gemeda is a
child of keniniand debela, and gemedaalso has two children — ebisa and ebise. Ebisa has two
children,hawi and chala.Ebise also has two children,kume and kuma. So we want to make
predicates as follows:

 parent(kenini,gemeda).
 parent (debela,gemeda).
 parent (gemeda,ebisa).
 parent (gemeda,ebise).
 parent (ebisa,hawi).
 parent (ebisa,chala).
 parent (ebise,kume).

Family Tree in Prolog Page 1


Lab Exercise Assignment

 parent (ebise,kuma).

Some facts can be written this ways, like sex of family members can be written
in this forms:

 female(kenini).
 male(debela).
 male(gemeda).
 male(ebisa).
 female(ebise).
 female(hawi).
 male(chala).
 female(kume).
 male(kuma).

 Prolog Rules

In Prolog syntax, we can write:

Prolog rule to identify who is sister of whom:-

 sister(X,Y) :- parent(Z,X), parent(Z,Y), female(X), X \== Y.

Prolog rule to identify who is brother of whom:-

 brother(X,Y) :- parent(Z,X), parent(Z,Y), male(X), X \== Y.

Prolog rule to identify who is cousin of whom:-

 cousin(X,Y) :- uncle(Unc , X),father(Unc,Y).

Prolog rule to identify who is grandfather of whom:-

 grandfather(X,Z):-parent(X,Y),parent(Y,Z),male(X).

Prolog rule to identify who is grandmother of whom:-

Family Tree in Prolog Page 2


Lab Exercise Assignment

 grandmother(X,Z):-parent(X,Y),parent(Y,Z),female(X).

Prolog rule to identify who is grandmother of whom:-

 aunt(X,Y) :- female(X),sister(X,Y),parent(Y,Z).

Prolog rule to identify who is uncle of whom:-

 uncle(X,Z):-brother(X,Y),parent(Y,Z).
2. Prolog query that check as:-

ebise is sister of ebisa?

 ?- sister(ebise,ebisa).

kume is cousin of chala?

 ?- cousin(kume,chala).

3. Write prolog query know:

Who is parent of feyisa?

 ?- parent(Y, feyisa).

Who is mother of whom?

 ?- mother(Y, X).

Family Tree in Prolog Page 3


Lab Exercise Assignment

?- brother(X,Y).
X = ebisa,
Y = ebise ;
X = chala,
Y = hawi ;
X = kuma,
Y = kume ;

?- sister(X,Y).

X = ebise,
Y = ebisa ;
X = hawi,
Y = chala ;
X = kume,
Y = kuma ;
X = ebise,
Y = ebisa.

?- grandfather(X,Y).

X = debela,
Y = ebisa ;
X = debela,
Y = ebise ;
X = gemeda,
Y = hawi ;
X = gemeda,
Y = chala ;
X = gemeda,
Y = kume ;
X = gemeda,

Family Tree in Prolog Page 4


Lab Exercise Assignment

Y = kuma ;

?- grandmother(X,Y).

X = kenini,
Y = ebisa ;
X = kenini,
Y = ebise ;

?- uncle(X,Y).

X = ebisa,
Y = kume ;
X = ebisa,
Y = kuma ;

?- sister(X,Y).

X = ebise,
Y = ebisa

Family Tree in Prolog Page 5

You might also like