Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE PROLOG LANGUAGE TO SOLVE THIS PROBLEM 2. Consider the following diagram of a family tree: [25 points] /* Database for family tree. It consists

USE PROLOG LANGUAGE TO SOLVE THIS PROBLEM

2. Consider the following diagram of a family tree: [25 points]

/* Database for family tree. It consists of facts and rules. */

/* A portion of the family tree has been implemented for you */ /* Facts */

male(kam).

male(rob).

female(ana).

female(syd). father_of(kam, rob). /* kam is the father of rob */

father_of(kam, syd). /* kam is the father of syd */

mother_of(ana, rob). /* ana is the mother of rob */

mother_of(ana, syd). /* ana is the mother of syd */ /* Rules */

is_male(X) :-

male(X);

father_of(X, _). Enter the program using a text editor, such as nano or pico, under Unix operation system and save the file as family_tree.pl. You may enter the program on your own computer using a simple editor, such as Notepad, and upload the program into your cse240prolog directory in general server. Compile the program using the Prolog command:

> gplc family_tree.pl Enter GNU Prolog programming environment by executing the Unix command " gprolog ". Execute the program family_tree by typing GNU Prolog command

|?- [family_tree]. To exit from GNU Prolog, type your end-of-file character at the main Prolog prompt ^d (Ctrl-d).

| ?- ^d Ask questions by typing, e.g.:

|?- father_of(kam, rob).

|?- mother_of(ana, syd). Please read Textbook Appendix B.4 Prolog for more detail. You can also find a complete set of GNU Prolog commands at http://www.gprolog.org/manual/gprolog.html. Now, you can start to add your code into the program. 2.1 Complete the program by adding facts and rules for the remaining members on the family tree. A portion has already been completed for you above for clarification. Please pay close attention when adding the remaining famiy members. All letters should be lowercase. [5] For all of the following questions, please label them. For example, if Question 1.0 asks you to define a rule called is_male (X) that returns "yes" (or "true") if X is the father of a member of the family, then your code should look like:

/* Question 1.0 */

is_male(X) :-

male(X);

father_of(X, _).

2.2 Define (add into the database) a rule called is_female(X) that returns "yes" (or "true") if X is a female or the mother of a member of the family. [4] Note: the system will return a "yes", if it finds a "true" answer and there exist no more true answers. The system will return "true ?" if it finds a "true" answer and there are still possibly further matches. In this case, if you type "enter", it will return "yes" and stop. If you type ";", it will continue to search for further answers.

2.3 Define a rule called parent_of(X, Y) that returns yes (or true) if X is a parent of Y. [4]

2.4 Define a rule called sibling_of(X, Y) that returns yes (or true) if X is a sibling of Y. [4]

2.5 Define one rule called grandmother_of(X, Z) that returns yes (or true) if X is a grandmother of Z and one rule called grandfather_of(X, Z) that returns yes (or true) if X is a grandfather of Z. [4]

2.6 Define a rule called descendent_of(X, Y) that returns yes (or true) if X is a descendent of Y. Note: you will need to use recursion as well as the parent rule defined above. [4]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+ What are their individual interests regarding bargaining issues?

Answered: 1 week ago