Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have have been stuck on this in prolog Design a set of predicates that encode

ID: 3597210 • Letter: I

Question

I have have been stuck on this

in prolog

Design a set of predicates that encode genealogical relationships..

male((XX)) - X is male..

female((XX)) - X is female..

parent((XX,,YY)) - X is the parent of Y..

mother((XX,,YY)) - X is the mother of Y..

father((XX,,YY)) - X is the father of Y..

child((XX,,YY)) - X is the child of Y..

sibling//22 (rreflexive))

grandparent((XX,,YY)) - X is the grandparent of Y..

grandmother((XX,,YY)) - X is the grandmother of Y..

grandfather((XX,,YY)) - X is the grandfather of Y..

grandchild((XX,,YY)) - X is the gradchild of Y..

grandson((XX,,YY)) - X is the grandson of Y..

granddaughter((XX,,YY)) - X is the granddaughter of Y..

Note:: Your definitions should avoid infinite recursion and return a single result set.. For

example,, siblings((XX,,YY)) should queries should return a single result set,, i..ee.. not X==bbob ,

Y==jjoe ; X==jjoe , Y==bbob .

Note:: The Knowledge Base of people below is for example only.. You are just responsible for the definitions of predicate rules.. The Knowledge Base used for grading will be different..

Examples::

% Knowledge Base

male((aadam))..

male((bbob))..

male((bbrett))..

male((ccharles))..

male((cchris))..

male((cclay))..

female((aava))..

female((bbarbara))..

female((bbetty))..

female((ccolette))..

female((ccarrie))..

parent((aadam,,bbob))..

parent((aadam,,bbarbara )..

parent((aava,,bbob))..

parent((aava,,bbarbara))..

parent((bbob,,cclay))..

parent((bbarbara,,ccolette))..

? - mother((aava,,KKid))

Kid = bob;;

Kid = barbara..

? - sibling((XX,,YY))..

X = bob,,

Y = barbara;;

? - grandparent((GGParent,,ccolette))..

GParent = adam;;

GParent = ava..

Explanation / Answer

I have written the relations in prolog for the same. The trick is to use the basic relations defined and then use them to make the relations.

• mother((XX,,YY)) - X is the mother of Y..

• father((XX,,YY)) - X is the father of Y..

• child((XX,,YY)) - X is the child of Y..

• sibling//22 (rreflexive))

• grandparent((XX,,YY)) - X is the grandparent of Y..

• grandmother((XX,,YY)) - X is the grandmother of Y..

• grandfather((XX,,YY)) - X is the grandfather of Y..

• grandchild((XX,,YY)) - X is the gradchild of Y..

• grandson((XX,,YY)) - X is the grandson of Y..

• granddaughter((XX,,YY)) - X is the granddaughter of Y..

mother(XX, YY) :-

female(XX),

parent(XX, YY).

father(XX, YY) :-

male(XX),

parent(XX,YY).

child(XX, YY) :-

parent(YY, XX).

sibling(XX, YY) :-

parent(QQ,XX),

parent(QQ,YY),

XX=YY.

grandparent (XX,YY) :-

parent(QQ,YY),

parent(XX,QQ).

grandmother (XX,YY) :-

female(XX),

parent(QQ,YY),

parent(XX,QQ).

grandfather (XX,YY) :-

male(XX),

parent(QQ,YY),

parent(XX,QQ).

grandchild (XX,YY) :-

parent(QQ,XX),

parent(YY,QQ).

grandson (XX,YY) :-

male(XX)

parent(QQ,XX),

parent(YY,QQ).

granddaughter (XX,YY) :-

female(XX)

parent(QQ,XX),

parent(YY,QQ).

The logic implemnted is simple where the existing basic functions like parent, male and femal are used to define all the other relationship in prolog. Let us take one simple example:

granddaughter (XX,YY) :-

female(XX)

parent(QQ,XX),

parent(YY,QQ).

The relationship above defines that XX is the granddaughter of YY.

So this can be depicted as

XX is a female

QQ is the parent of XX

and YY is the parent of QQ. so which means that XX which is a female is the granddaughter of YY.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote