You are on page 1of 3

Roll No : ​18bce363

Name : praful parmar


Practical : 5
Aim : ​Write a program in PROLOG for Query based on family tree.
Knowledge base contain the data of at-least three generations.

Family Tree

Code
predicates
male(symbol)
female(symbol)
sister(symbol,symbol)
brother(symbol,symbol)
cousin(symbol,symbol)

father(symbol,symbol)
mother(symbol,symbol)
uncle(symbol,symbol)
aunt(symbol,symbol)
sibling(symbol,symbol)
grandparent(symbol,symbol)

clauses
male(ram).
male(a).
male(b).
male(ason).
male(bson).
male(bson1).

female(tina).
female(adau).
female(tinad1).
female(tinad2).

father(ram,a).
father(ram,b).
father(ram,tina).

father(a,ason).
father(a,adau).

father(b,bson).
father(b,bson1).

mother(tina,tinad1).
mother(tina,tinad2).

brother(X,Y):-male(X),father(Z,X),father(Z,Y),not(X=Y).

sister(X,Y):-female(X),mother(Z,X),mother(Z,Y),not(X=Y).
sister(X,Y):-female(X),father(F,X),father(F,Y),not(X=Y).

cousin(X,Y):-father(F,X),father(F1,Y),brother(F,F1),not(X=Y).
cousin(X,Y):-father(F,X),mother(M,Y),sister(M,F),not(X=Y).

uncle(X,Y):-male(Y),father(Z,X),father(Q,Z),father(Q,Y),not(X=Y),not(Z=Y)
. uncle(X,Y):-male(Y),mother(M,X),father(F,M),father(F,Y).

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

sibling(X,Y):-father(F,X),father(F,Y),not(X=Y).
sibling(X,Y):-mother(M,X),mother(M,Y),not(X=Y).

grandparent(X,Y):-father(F,X),father(Y,F),not(X=Y).
grandparent(X,Y):-mother(M,X),father(Y,M),not(X=Y).
Output

You might also like