Assume the Prolog knowledge base contains a set of facts: parent (parent, child)
ID: 3845995 • Letter: A
Question
Assume the Prolog knowledge base contains a set of facts: parent (parent, child) describes biological parent-child relationships. Assume that the Prolog knowledge base describes only families where all siblings share the same two parents. You are required to write rules that describe the cousin relationship. Consider the following definitions First cousins are the children of two siblings. First cousins have grandparents in Common Second cousins are the children of first cousins. Second cousins have great grandparents in common First cousins once removed are two people such that a parent of one of these people is a first cousin of the other person. First cousins twice removed are two people such that a grandparent of one of these people is a first cousin of the other person. The following Prolog definitions could be used to describe first and second cousins. sibling(A, B): - parent(M, A), parent(M, B), parent(F, A), parent(F, B), A==B, M==F. cousinl(A, B): = parent(X, A), parent(Y, B), sibling(X, Y), A==B. cousin2(A, B): -parent(X, A), parent(Y, B), cousin1(X, Y), A==B. (a) Write the general rule cousin (N, Person1, Person2) that is true if Person1 and Person2 are N^th cousins. cousin1(Person1, Person2) cousin (1, Person1, Person2) and cousin2(Person1, Person2) cousin(2, Person1, Person2) and so on for third and fourth and even higher level cousins. (b) Write the general rule cousinR(N, R, Person1, Person2) that is true if Person1 and Person2 are N^th cousins and they are removed by R steps. cousinR(2, 1, Person1, Person2) is true for second cousins, once removed and cousinR(1, 2, Person1, Person2) is true for first cousins, twice removed.Explanation / Answer
cousin(1, A, B) :- parent(X, A), parent( Y, B), sibling( X, Y). cousin(N, A, B) :- J == N-1, parent( X, A), parent(Y, B), cousin( J, A, B). %% cousinR(N, zero, A, B ) :- cousin(N, A, B). cousinR(N, R, A, B ) :- K == R-1, parent(Y, B), cousinR( N, K, A, Y).