Homework XI

 

 

1. [20 points]

In terms of the relations defined in the familial file, define the predicate childrenOf(P, Cs) to succeed when P is a parent and Cs is a list of all the children of P. Your submission should be a printout showing your predicate definition, along with tests that demonstrate that a list of all possible solutions is always found (e.g., including none)_.

 

 

2. [20 points]

In the domain of familial relations, "cousins" normally refers to two persons who have exactly two grandparents in common -- those with four grandparents in common are either “double cousins” or siblings. Write a definition of the predicate cousinOf(Person1, Person2). Your submission should be a printout showing your predicate definition, along with tests that demonstrate that all possible solutions are always found.

 

 

3. [40 points]

Write a Prolog definition of the predicate subSum(List, Sum, SubList) that succeeds repeatedly for each SubList that is a list consisting of some items extracted from List, so that the sum of the items in SubList is Sum. For instance, subSum([1,2,3,4], 6, Ans) should succeed with Ans= [2,4], and with Ans = [1,2,3]. Your submission should be a printout showing your predicate definition, along with tests that demonstrate that all possible solutions are always found.