Prolog programming Using Amzi Prolog create and test prolog
Prolog programming …
Using Amzi Prolog, create and test prolog clauses to perform relation between mother,father, sister, brother, nephew, granddad, grandmother.
(make up something interesting relating to families.)
Solution
%trace
 predicates
   
 father(symbol,symbol)
 mother(symbol,symbol)
 male(symbol)
 female(symbol)
 sister(symbol,symbol)
 brother(symbol,symbol)
 uncle(symbol,symbol)
 wife(symbol,symbol)
 aunty(symbol,symbol)
 sisterinlaw(symbol,symbol)
 cousin(symbol,symbol)
 nephew(symbol,symbol)
 grand_son(symbol,symbol)
 grand_duaghter(symbol,symbol)
clauses
sister(X,Y) :- father(X,A),father(Y,A),female(Y).
father(dhanjiBhai,vithhaldas).
 father(chuniBhai,vithhaldas).
 father(harshad,dhanjibhai).
 father(darshan,dhanjibhai).
 father(nilam,dhanjibhai).
 father(kiran,dhanjibhai).
 father(kamleshbhai,chunibhai).
   
 mother(harshad,prabhaben).
 mother(X,Y) :- father(X,Z),wife(Y,Z).
   
 brother(X,Y) :- father(X,A),father(Y,A),male(X).
% brother(X,Y) :- brother(Y,X).
   
 male(harshad).
 male(darshan).
 male(dhanjibhai).
 male(chunibhai).
   
 female(nilam).
 female(kiran).
 female(prabhaben).
 female(nimishaben).
 female(kokilaben).
   
 wife(prabhaben,dhanjibhai).
 wife(nimishaben,kamleshbhai).
 Wife(kokilaben,chunibhai).
   
   
 grand_son(X,Y) :- father(A,Y),father(X,A),male(X).
 grand_duaghter(X,Y) :- father(A,Y),father(X,A),female(Y).
   
 uncle(X,Y) :- father(X,Z),brother(Y,Z).
   
 aunty(X,Y) :- wife(Y,Z),
 brother(Z,W),
 father(X,W).
   
 sisterinlaw(X,Y) :- wife(X,Z),cousin(Y,Z),female(X).
   
   
 cousin(X,Y) :- father(X,A),father(Y,B),brother(A,B).
   
 nephew(X,Y) :- wife(Y,A),brother(A,B),father(X,B),male(X).


