Reading: Webster Ch. 19
Define your answers to the following exercises in terms of the base relations parent(X,Y)
, female(X)
, and male(X)
. To test your code, define some parent
facts like those in the example code, along with appropriate female
and male
facts. But your solutions should be general enough to work with any set of such facts.
Define a mother
predicate so that mother(X,Y)
says that X
is the mother of Y
.
mother(X, Y) :- female(X), parent(X, Y).
Define a father
predicate so that father(X,Y)
says that X
is the father of Y
.
father(X, Y) :- male(X), parent(X, Y).
Define a sister
predicate so that sister(X,Y)
says that X
is the sister of Y
. Be careful, a person cannot be her own sister.
sister(X, Y) :- parent(Z, X), parent(Z, Y), female(X), not(X = Y).
Define a grandson
predicate so that grandson(X, Y)
says that X
is the grandson of Y
.
grandson(X, Y) :- parent(X, F), parent(F, Y), male(Y).