Computer Science: An Overview: Global Edition (12th Edition)

Published by Pearson Higher Education
ISBN 10: 1292061162
ISBN 13: 978-1-29206-116-0

Chapter 6 - Programming Languages - Section 6.7 - Declarative Programming - Questions & Exercises - Page 323: 4

Answer

Prolog will conclude that Carol is her own sibling. To solve this problem, the rule needs to include the fact that X cannot be equal to Y, which in Prolog is written X \ = Y. Thus an improved version of the rule would be sibling (X, Y) :-X \= Y, parent(Z, X), parent(Z, Y). which says that X is Y’s sibling if X and Y are not equal and have a common parent. The following version would insist that X and Y are siblings only if they have both parents in common: sibling (X, Y) :− X \= Y, Z \= W parent (Z, X), parent (Z, Y), parent (W, X), parent (W, Y).

Work Step by Step

Prolog will conclude that Carol is her own sibling. To solve this problem, the rule needs to include the fact that X cannot be equal to Y, which in Prolog is written X \ = Y. Thus an improved version of the rule would be sibling (X, Y) :-X \= Y, parent(Z, X), parent(Z, Y). which says that X is Y’s sibling if X and Y are not equal and have a common parent. The following version would insist that X and Y are siblings only if they have both parents in common: sibling (X, Y) :− X \= Y, Z \= W parent (Z, X), parent (Z, Y), parent (W, X), parent (W, Y).
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.