Due in lecture Dec 9, 1998
No late assignments accepted this time,
since we want to post the solution right away. Paper turnin only
(no electronic turnin).
Define the append and sum relations as follows:
append([],L,L). append([H|T],L,[H|U]) :- append(T,L,U). sum([],0). sum([X|Xs],X+S) :- sum(Xs,S).Try append on the following. In each case reject the answers to see what happens when CLP(R) backtracks.
append([a,b,c],[w,x,y,z],L). append([a,b],Y,[a,b,c,d]). append([a,c],Y,[a,b,c,d]). append(X,Y,[a,b,c,d]). append(X,Y,Z).Now try sum on the following, again backtracking when possible.
sum([5,10,20],N). sum([5,10,20],8). sum([5,X],100). sum([5,X,Y],100). sum(A,100).
listmax([10,5,8],X) succeeds with X=10 listmax([A,5,8],100) succeeds with A=100 listmax([A,5,8],5) failsTry your rule on the above cases, and also listmax([A,B,C],100) and listmax(A,100). (Backtrack to find all of the answers, or if there are an infinite number, the first several answers that are produced.)