Define your answers toExercise1 through 6 in terms of the base relations parent
ID: 3697696 • Letter: D
Question
Define your answers toExercise1 through 6 in terms of the base relations parent (X, Y), female (X), and male (X). To test your code, define some parent, facts like those in this chapter, along with appropriate female and male facts. But your solutions should be general enough to work with any set of such facts. Exercise 1 Define a mother predicate so that mother (X, Y) says that X is the mother of Y. Exercise 2 Define a father predicate so that father (X, Y) says that X is the father of Y. Exercise 3 Define a sister predicate so that sister (X, Y) says that X is a sister of Y. Be careful, a person cannot be her own sister. Exercise 4 Define a grandson predicate so that grandson (X, Y) says that X is a grandson of Y. Exercise 5 Define the firstCousin predicate so that firstCousin (X, Y) says that X is a first co8usin of Y. Be careful, a person cannot be his or her own cousin, nor can a brother or sister also be a cousin. Exercise 6 Define the descendant predicate so that descendant (X, Y) says that X is a descendant of Y. Exercise 7 Define a third predicate so that third(X, Y) says that Y is the third element of the list X. (The predicate should fail if X has fewer than three elements.) Exercise 8 Define a firstPair predicate so that firstPair(X) succeeds if and only if X is a list of at least two elements, with the first element the same as the second element.Explanation / Answer
female(abc).
female(cde).
female(efg).
female(fgh).
male(lmn).
male(nop).
male(pqr).
male(rst).
mother(abc,cde).
mother(abc,efg).
mother(cde,nop).
mother(fgh,pqr).
father(lmn,cde).
father(lmn,efg).
father(rst,abc).
father(rst,fgh).
1.parent(X,Y) : mother(X,Y), female(X).
here X is female from that X is mother of Y
4.grandson(X,Y) : grandparent(X,Y), male(X).
here X is male and from that above X is grandson of Y
5.firstCousin(X,Y) : parent(Z,X), parent(W,Y), sibling(Z,W).
in this X is first cousin of Y as per the above syntax
6.descendant(X,Y) : parent(X,Y).
descendant(X,Y) : parent(Z,X), descendant(Z,Y).
from the above formats X is a descendent of Y
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.