/**************************/ /* */ /* Answers to worksheet 3 */ /* */ /**************************/ /* NOTE THE ORDER OF CLAUSES AND SUBGOALS IN THE RECURSIVE DEFINITIONS */ /* Exercise 3.1: Family trees */ /* For these definitions to work you have to load in facts such */ /* as those given in the file family. */ /* a) Nonrecursive definitions of grandparent and great-grandparent */ grandparent(Gradparent, Grandchild) :- parent(Grandparent, Parent), parent(Parent, Grandchild). great_grandparent(GGrandparent, GGrandchild) :- parent(GGrandparent, Grandparent), grandparent(Grandparent, GGrandchild). /* b) Recursive definition of ancestor */ ancestor(A, D) :- parent(A, D). ancestor(A, D) :- parent(A, Int), ancestor(Int, D). /* Exercise 3.2: Evolution */ /* For these definitions to work you have to load in facts such */ /* as those given in the file evolution. */ higher(C1, C2) :- evolved(C1, C2). higher(C1, C3) :- evolved(C1, C2), higher(C2, C3). /* WITH THE CLAUSES AND SUBGOALS ORDERED IN THE WAY SHOWN HERE, */ /* ALL DEFINITIONS WILL BE POLYMODAL. */