PROLOG: using kb below, answer a, b, c. female(mum). female(kydd). female(elizab
ID: 3728050 • Letter: P
Question
PROLOG: using kb below, answer a, b, c.
female(mum).
female(kydd).
female(elizabeth).
female(margaret).
female(diana).
female(anne).
female(sarah).
female(zara).
female(beatrice).
female(eugenie).
male(george).
male(spencer).
male(philip).
male(charles).
male(mark).
male(andrew).
male(edward).
male(william).
male(harry).
male(peter).
parent(george,elizabeth).
parent(george,margaret).
parent(mum,elizabeth).
parent(mum,margareth).
parent(spencer,diana).
parent(kydd,diana).
parent(elizabeth,charles).
parent(elizabeth,anne).
parent(elizabeth,andrew).
parent(elizabeth,edward).
parent(philip,charles).
parent(philip,anne).
parent(philip,andrew).
parent(philip,edward).
parent(diana,william).
parent(diana,harry).
parent(charles,william).
parent(charles,harry).
parent(anne,peter).
parent(anne,zara).
parent(mark,peter).
parent(mark,zara).
parent(andrew,beatrice).
parent(andrew,eugenie).
parent(sarah,beatrice).
parent(sarah,eugenie).
a) Enter the information from this family tree as a set of Prolog facts using only the three predicates wife, son and daughter. Note, the females are: Mum, Kydd, Elizabeth, Margaret, Diana, Anne, Sarah, Zara, Beatrice, and Eugenie.
b) Now add Prolog rules that will allow you to infer information for the predicates husband, spouse, child, parent, grandChild, greatGrandParent, brother, sister, aunt, uncle, brotherInLaw, sisterInLaw and firstCousin. You may not use any facts other than those from part (a), but you may create rules for additional predicates if you find that helpful. You may look up the definitions of terms like “aunt,” “uncle,” “brother-in-law,” “sister-in-law,” and “first cousin” in the dictionary, in order to be certain that you have captured their full meaning. Please attach a printout of your program to your submission.
c) Test your Prolog program by asking it the following questions. Note, in some cases, it may be impossible to avoid getting the same answer more than once for a query. i) Who is Sarah’s husband? ii) Who are Elizabeth’s grandchildren? iii) Who are Zara’s great-grandparents? iv) Who are Diana’s sisters-in-law? v) Who are Beatrice’s uncles?
Explanation / Answer
female(mum).
female(kydd).
female(elizabeth).
female(margaret).
female(diana).
female(anne).
female(sarah).
female(zara).
female(beatrice).
female(eugenie).
male(george).
male(spencer).
male(philip).
male(charles).
male(mark).
male(andrew).
male(edward).
male(william).
male(harry).
male(peter).
parent(george,elizabeth).
parent(george,margaret).
parent(mum,elizabeth).
parent(mum,margareth).
parent(spencer,diana).
parent(kydd,diana).
parent(elizabeth,charles).
parent(elizabeth,anne).
parent(elizabeth,andrew).
parent(elizabeth,edward).
parent(philip,charles).
parent(philip,anne).
parent(philip,andrew).
parent(philip,edward).
parent(diana,william).
parent(diana,harry).
parent(charles,william).
parent(charles,harry).
parent(anne,peter).
parent(anne,zara).
parent(mark,peter).
parent(mark,zara).
parent(andrew,beatrice).
parent(andrew,eugenie).
parent(sarah,beatrice).
parent(sarah,eugenie).
wife(X,Y):-female(X),parent(X,Z),parent(Y,Z).
son(X,Y):-male(X),parent(Y,X).
daughter(X,Y):-female(X),parent(Y,X).
husband(X,Y):-wife(Y,X).
spouse(X,Y):-wife(X,Y);wife(Y,X).
child(X,Y):-son(X,Y);daughter(X,Y).
parent(X,Y):-son(Y,X);daughter(Y,X).
grandChild(X,Y):-parent(Z,X),parent(Y,Z).
greatGrandParent(X,Y):-parent(X,Z),parent(Z,W),parent(W,Y).
brother(X,Y):-male(X),parent(Z,X),parent(Z,Y).
sister(X,Y):-female(X),parent(Z,X),parent(Z,Y).
aunt(X,Y):-sister(X,Z),parent(Z,Y).
uncle(X,Y):-brother(X,Z),parent(Z,Y).
brotherInLaw(X,Y):-husband(Y,Z),brother(X,Z);wife(Y,Z),brother(X,Z).
sisterInLaw(X,Y):-husband(Y,Z),sister(X,Z);wife(Y,Z),sister(X,Z).
firstCousin(X,Y):-parent(Z1,X),parent(Z2,Y),parent(Z,Z1),parent(Z,Z2).
Do give thumbs up for the effort and in case there are doubts leave a comment.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.