Professional Documents
Culture Documents
Use Prolog to create a knowledge base for the family tree of Figure 1 and then ask queries about
the family tree. Assume the intended interpretation of all predicates of the form p(x,y) is that “x is
the p of y”.
wife(philip, mum).
wife(charles, diana).
wife(mark, anne).
wife(andrew, sarah).
wife(edward, sophie).
wife(peter, autumn).
wife(mike, zara).
son(charles, mum).
son(andrew, mum).
son(edward, mum).
son(william, diana).
son(harry, diana).
son(peter, anne).
son(zara, anne).
daughter(anne, mum).
daughter(elizabeth, mum).
daughter(margaret, mum).
daughter(beatrice, andrew).
daughter(eugenie, andrew).
b) Here are the rules added to infer information about the family tree:
?- husband(X, sarah).
X = andrew.
?- grandChild(X, elizabeth).
X = william ;
X = harry ;
X = peter ;
X = zara.
?- greatGrandParent(X, zara).
X = philip ;
X = mum ;
X = elizabeth.
?- sisterInLaw(X, diana).
X = anne ;
X = sarah.
?- uncle(X, beatrice).
X = charles ;
X = edward.
Question 2
degree_lower(hs,_).
degree_lower(bs,hs).
degree_lower(ms,bs).
degree_lower(phd,ms).
dateable(Female, Male) :-
degree_lower(FemaleDegree, MaleDegree),
?- dateable(lily, richard).
false.
?- dateable(lily, bob).
true.
?- dateable(jenny, tom).
true.