You are on page 1of 2

Practical No.

3
AIM: Create a family tree program(of EXP2) to include following rules

1. M is the mother of P if she is a parent of P and is female

2. F is the father of P ifhe is a parent of P and is male

3. X is a sibling of Y if they both have the same parent.

4. Then add rules for grandparents.

Software Requirement: SWI-Prolog

Program:

male(chester).
male(clarence).
male(irvin).
male(ron).
male(charlie).
male(ken).

female(sharon).
female(mary).
female(mildred).
female(shirley).
female(goldy).

parent(chester,irvin).
parent(chester,clarence).
parent(chester,mildred).
parent(irvin,ron).
parent(irvin,ken).
parent(clarence,shirley).
parent(clarence,sharon).
parent(clarence,charlie).
parent(mildred,mary).
parent(goldy,ken).

father(X,Y) :- parent(X,Y), male(X).


grandparent(X,Y) :- parent(X,Z), parent(Z,Y).
paternalgrandfather(X,Y) :- father(X,Z),
father(Z,Y).
sibling(X,Y) :- parent(Z,X), parent(Z,Y).
OUTPUT:
1) M is the mother of P if she is a parent of P and is female

Ans.

1 ?- parent(X,ken), female(X).
X = goldy

2) F is the father of P ifhe is a parent of P and is male

Ans.

1 ?- parent(clarence,X), male(X).
X = charlie
yes

3) X is a sibling of Y if they both have the same parent.

Ans.

1?-sibling(ken,X).
X = ron;
X = ken;

4) Then add rules for grandparents.

Ans.

1?-grandparent(X,ken).

X = chester

Conclusion:

You might also like