## Suggested Homework #7 (for Quiz #7 on 03/12/07)

Problem 1. Recall the following prolog predicate described in class:

``` parent(kim,holly). parent(margaret,kim). parent(herbert,margaret). parent(john,kim). parent(felix,john). parent(albert,felix). ```

In addition, suppose we define the following predicates:

``` male(herbert). male(john). male(felix). male(albert). female(kim). female(holly). female(margaret). ```
• (a) Write a predicate sibling(X,Y) that is true if X is a sibling of Y.
• (b) Write a predicate uncle(X,Y) that is true if X is an uncle of Y.
• (c) Write a predicate niece(X,Y) that is true if Y is a niece of X.
• (d) Write a predicate first_cousin(X,Y) that is true if X and Y are first cousins (i.e. they have parents who are siblings).
• (e) Write a predicate cousin(X,Y) that is true if X and Y are cousins (i.e. including first, second, third etc. cousins).

Problem 2. List manipulation

• (a) Write a predicate reverse(X,Y) that is true if the list Y is the reverse of the list X.
• (b) Write a predicate sum(L,N) that is true if the number N is the sum of the numbers in the list L.
• (c) Write a predicate max(L,N) that is true if the number N is the largest (maximum) of the numbers in the list L.
• (d) Write a predicate sorted(L) that is true if the list L is sorted in increasing order.
• (e) Write a predicate subsequence(L1,L2) that is true if the list L2 is a subsequence of the list L1. For example: subsequence([1,2,3,4],[2,4]) and subsequence([1,2,3],[]) but not subsequence([1,2,3],[3,1]).