You are on page 1of 2

1.

) Write a prolog program to represent a family tree and write the


predicates for different relationships like father, mother, brother, sister,
grandmother, grandfather, etc.

Program Code:
parent(pam,bob).
parent(tom,bob).
parent(tom,liz).
parent(bob,ann).
parent(bob,pat).
parent(pat,jim).

female(pam).
male(tom).
male(bob).
female(liz).
female(pat).
female(ann).
male(jim).

father(X,Y):- parent(X,Y),male(X).
mother(X,Y):- parent(X,Y),female(X).
bother(X,Y):- parent(Z,X),parent(Z,Y),male(X).
sister(X,Y):- parent(Z,X),parent(Z,Y),female(X).
grandfather(X,Z):-parent(X,Y),parent(Y,Z),male(X).
grandmother(X,Z):-parent(X,Y),parent(Y,Z),female(X).
Output:

You might also like