In previous article we have seen how to find the reverse of a list. The following program shows the implementation of rules. It describes the relationships of brother, sister, grandparents, son, daughter and uncle in a family. The facts used here include male, female, parents, and father.
Relations to be define:-
1) Brother
2) Grandparents
3) Son
4) Sister
5) Daughter
6) Uncle.
PROGRAM:
male(a). female(b). male(c). female(d). parents(a,m1,f1). parents(b,m1,f1). parents(c,m1,f1). parents(d,m2,f2). parents(f1,f5,f6). parents(f2,f5,f6). parents(f3,f7,f8). parents(f4,f7,f8). father(f1,a). father(f2,b). father(f3,c). father(f4,d). brother(X,Y):-male(X),parents(X,M,F),parents(Y,M,F). sister(X,Y):- female(X),parents(X,M,F),parents(Y,M,F). son(X,F):-male(X),father(F,X). daughter(X,M,F):-female(X),parents(X,M,F). uncle(Y,X):- male(X),father(M,X),parents(M,M1,F1),parents(Y,M1,F1). grandparents(M,F1,X):-father(F,X),parents(F,M,F1).
OUTPUT: