Foundations of Computer Science Fall 2007 For today you should have: 1) Read from Sipser and answered the questions in notes15. 2) Finished the Prolog list exercises, with the optional set intersection and union. 3) Chosen an additional Prolog project and started work. For next time, you should: 1) Read from Casti and answer the questions below. 2) Finish your Prolog project. 3) Prepare for a quiz. Prolog list solutions --------------------- See notes15 for part one. 1) Basic subset works as a boolean, and it works backward, but it overflows if run forward. 2) subset works as a boolean, forward and backward, but it requires the elements of the set to be unique (which is reasonable). Run backward, it generates all permutations of all subsets (which is necessary in order to work as a boolean). 3) power is really another implementation of subset, but this version requires the elements of the sets to be in order. 4) power_set is a fairly natural recursive definition of a power set. It works forward. Does it work as a boolean? Does it work backward? % basic_subset(X,Y) if X is a subset of Y basic_subset([F|R], Y) :- member(F, Y), basic_subset(R, Y). basic_subset([], _). % subset(X,Y) (only works if members of X are unique) subset([],_). subset([F|R],A) :- member(F,A), takeout(F,A,X), subset(R,X). % "power" enumerates the subsets of X; it avoids permutations % by requiring the elements to be in order (so the elements have % to be integers) % This is from http://kti.mff.cuni.cz/~bartak/prolog/sets.html power([H1|T1],[H2|T2]) :- lt(H1,H2), power(T1,[H2|T2]). power([H|T1],[H|T2]) :- power(T1,T2). power(_,[]). % lt is true if either argument is a variable; otherwise it uses < lt(X,Y) :- var(X); var(Y). lt(X,Y) :- nonvar(X), nonvar(Y), X