Prolog1 (231801167)
Prolog1 (231801167)
Name : sivamurugan.B
Introduction of Prolog
Program:
male(peter).
male(john).
male(chris).
male(kevin).
female(betty).
female(jeny).
female(lisa).
female(helen).
parentOf(chris,peter).
parentOf(chris,betty).
parentOf(helen,peter).
parentOf(helen,betty).
parentOf(kevin,chris).
parentOf(kevin,chris).
parentOf(jeny,john).
parentOf(jeny,helen).
father(X,Y):-male(Y),
parentOf(X,Y).
mother(X,Y):-female(Y),
parentOf(X,Y).
grandfather(X,Y):-male(Y),
parentOf(X,Z),
parentOf(Z,Y).
grandmother(X,Y):-female(Y),
parentOf(X,Z),
parentOf(Z,Y).
brother(X,Y):-male(Y),
father(X,Z),
father(Y,W),
Z==W.
sister(X,Y):-female(Y),
father(X,Z),
father(Y,W),
Z==W.
pg. 1
OUTPUT:
% c:/Users/HDC0719088/Desktop/231501128/prolog.txt compiled 0.00 sec, 22 clause
?- male(peter).
true.
?- father(chris,peter).
true.
?- father(chris,betty).
false.
?-
| grandfather(kevin.peter).
true.
?- grandfather(jenny.peter).
false.
?- grandmother(jenny.peter).
false.
?- brother(helen,chris).
true.
?- brother (chris,helen).
false.
?- father(X,Y).
X = chris,
Y = peter.
?- mother(X,Y).
X = chris,
Y = betty.
?- grandmother(X,Y).
X = kevin,
Y = betty.
?- grandfather(X,Y).
X = kevin
Y = peter.
2- hrother (X,Y)
XY, Y = chris.
?- sister(X,Y).
X = Y. Y = jeny
pg. 2