Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prolog Assignment 4 : father_of(X,Y) :- parent_of(X,Y),male(X). mother_of(X,Y) :- parent_of(X,Y),female(X). son_of(X,Y) :- parent_of(Y,X),male(X). daughter_of(X,Y) :- parent_of(Y,X),female(X). sibling_of(X,Y) :- parent_of(Z,X),parent_of(Z,Y). brother_of(X,Y) :- sibling_of(X,Y), male(X). sister_of(X,Y) :-

Prolog

Assignment 4 :

father_of(X,Y) :- parent_of(X,Y),male(X).

mother_of(X,Y) :- parent_of(X,Y),female(X).

son_of(X,Y) :- parent_of(Y,X),male(X).

daughter_of(X,Y) :- parent_of(Y,X),female(X).

sibling_of(X,Y) :- parent_of(Z,X),parent_of(Z,Y).

brother_of(X,Y) :- sibling_of(X,Y), male(X).

sister_of(X,Y) :- sibling_of(X,Y), female(X).

grandparent_of(X,Y) :- parent_of(X,Z),parent_of(Z,Y).

ancestor_of(X,Y) :- parent_of(X,Y).

ancestor_of(X,Y) :- parent_of(X,Z),ancestor_of(Z,Y)

Rewrite your family database (assignment 4 GIVEN ABOVE), but this time use PROLOG's lists ([H|T]) to represent the basic facts of your family. Save it as an ordinary text file named familylists.pro.

Your program should implement the following facts for your immediate family, grandparents, and great-grandparents.

family([mom,dad],[[daughter1, daughter2],[son1,son2]]). 
 

In other words, each nuclear family is comprised of two lists: family(ParentList, ChildrenList). The ParentList is formatted with the name of the mother, followed by the name of the father. The ChildrenList consists of two sublists, the first giving the names of the daughters, in chronological order, and the second giving the names of the sons, in chronological order.

All other predicates should be defined in terms of the above facts. For example, consider the following definitions:

father_of(D,C) :- family([_,D],[Ds,Ss]), 
 (member(C,Ds); 
 member(C,Ss)). 
parent_of(P,C) :- father_of(P,C). 
parent_of(P,C) :- mother_of(P,C). 
 
male(M) :- family([_,M],_). 
male(M) :- family(_,[_,Ss]), member(M,Ss). 
 
member(M,[M|_]). % base case 
member(M,[H|T] :- member(M,T). % recursive case 
 

Define the following predicates for your database:

predicate interpretation 
--------- -------------- 
father_of(X,Y) X is the father of Y 
mother_of(X,Y) X is the mother of Y 
son_of(X,Y) X is the son of Y 
daughter_of(X,Y) X is the daughter of Y 
sibling_of(X,Y) X is the sibling of Y 
brother_of(X,Y) X is the brother of Y 
sister_of(X,Y) X is the sister of Y 
grandparent_of(X,Y) X is the grandparent of Y 
ancestor_of(X,Y) X is the ancestor of Y 
oldest_son(S,P) S is the oldest son of P 
oldest_daughter(D,P) D is the oldest daughter of P 

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions