Homework 2 - Further Prolog programming


Set Friday Oct 11th, due Thursday Oct 17th

0. Corresponds to SS Chapters 6 through 11 and Bratko Chapters 5 through 8.

1. Write a version of split (from homework 1) using a cut.
Predicate split(Numbers,Positives,Negatives) splits a list of numbers into two lists,
one containing the positive ones and the other the negatives.

2. Write a version of SS Program 10.1 for a plus predicate for integers,
plus(X,Y,Z) is true if X + Y = Z,
but which will work for all combinations of values including unbound, for X, Y and Z.
You may need to use the predicate between, defined in SS page 157,
between(I,J,K) is true if K is between I and J inclusive, I, J, and K being integers.

3. Add cuts to the following insertion sort program to improve its efficiency.
/*
	sort(Xs,Ys) :- 
		The list Ys is an ordered permutation of the list Xs.
*/

	sort([X|Xs],Ys) :- sort(Xs,Zs), insert(X,Zs,Ys).
	sort([],[]).

	insert(X,[],X).
	insert(X,[Y|Ys],[Y|Zs]) :- X > Y, insert(X,Ys,Zs).
	insert(X,[Y|Ys],[X,Y|Ys]) :- X =< Y.

4. Use bagof to define the relation powerset(Set,Subsets) to compute the set of all subsets of a given set, where all sets are represented as lists.


Please email a URL with your solutions to me. You should include data cases showing that your programs work correctly.