Question

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

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..

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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.

Add a comment
Know the answer?
Add Answer to:
I have have been stuck on this in prolog Design a set of predicates that encode...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. For your family (or any other real or hypothetical family) write a PROLOG program "family.pro"...

    1. For your family (or any other real or hypothetical family) write a PROLOG program "family.pro" that is based on the following facts: - is male (NAME). is female (NAME). is_parent_of (PARENT, CHILD ). e.g. e.g. e.g. is_male (tom). is_female (ann). is_parent_of (ann, tom). Add to these facts the following inference rules: - mother (MOTHER, CHILD) - father (FATHER, CHILD) sibling1 (NAME1, NAME2) brotheri (NAME1, NAME2) sisteri (NAME1, NAME2) (1 parent in common) (1 parent in common) (1 parent in...

  • QUESTION 1 Given the following relationships in Prolog clauses: father(X,Y) /* X is the father of...

    QUESTION 1 Given the following relationships in Prolog clauses: father(X,Y) /* X is the father of Y */ mother(X,Y) /* X is the mother of Y */ male(X) /* X is male */ female(X) /* X is female */ parent(X,Y) /* X is a parent of Y */ diff(X,Y) /* X and Y are different */ Write Prolog clauses to define rules for the following relationships: is_mother(X) /* X is a mother */ is_father(X) /* X is a father */...

  • 4. [201 Use Prolog (e.g., SWI-Prolog) to create a knowledge base for the family tree of...

    4. [201 Use Prolog (e.g., SWI-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" George eMum r-Kydd Elizabeth Philip Margaret Diana-Charles Anne-Mark Andrew Sarah E William Harry Peter Zara Beatrice Eugenie Figure 1. A typical family tree. The symbol-connects spouses and arrows point to children. Enter the information from...

  • for questions 25 - 26 using the letters below. This set of questions refers to Mendel’s...

    for questions 25 - 26 using the letters below. This set of questions refers to Mendel’s plants with either Purple flowers or White flowers A. PP B. Pp C. pp D. PP or Pp E. Pp or pp F. PP or pp G. none of these answers 25. A purple flowering pea plant of unknown genotype would be best described by which answer above 26. To determine the genotype of a purple flowering plant of unknown genotype, you would cross...

  • 16. So far we have been dealing with alleles found on autosomal chromosomes. These chromosomes contain...

    16. So far we have been dealing with alleles found on autosomal chromosomes. These chromosomes contain all the genetic information that is not gender related. As a human, you have 44 autosomal chromosomes (22 pairs → 11 chromosomes from your Mom and 11 chromosomes from your Dad). You also contain a pair of sex chromosomes. These chromosomes contain all the genetic information related to your gender. If you are female, you received an X chromosome from your Mom and an...

  • 1-Summarize the article briefly in your own words. 2-Explain the main theme of this case and...

    1-Summarize the article briefly in your own words. 2-Explain the main theme of this case and its implications for the future of forensic science. 3-Several genealogy sites (including ancestry.com, 23andme.com, familytreedna.com, findmypast.com) were used in this case -- do you believe that law enforcement should have access to these databases as a standard practice? Why or why n Article How a Jane Doe child case uncovered a serial killer, identified victims and changed the use of DNA forensics Investigators and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT