CSc 404 Assignment 5

Your New Uniform

Assigned
Due

Apr 2
45 pts
Apr 15

Create two (mostly unrelated) Prolog relations.

Create a prolog relation isall which takes an item and a list and asserts that all members of the list are the indicated item. Like so:

?- consult(inc). true. ?- isall(s,[s,s,s,s]). true ; false. ?- isall(t,[s,t,s,t]). false. ?- isall(W,[a,a,a,a,a]). W = a ; false. ?- isall(W,[a,a,a,y,a]). false. ?- isall(W,[a,X,a,Z,a]). W = a, X = a, Z = a ; false. ?- isall(q,Q). Q = [] ; Q = [q] ; Q = [q, q] ; Q = [q, q, q] ; Q = [q, q, q, q] . ?-

Note that on the last one, the system was offering additional solutions, but I told it to stop.

Create a Prolog relation alt which is true when the second argument is a list which is the first argument with every other element removed (the second, fourth, sixth, etc.) To wit:

?- consult(inc). true. ?- alt([a,y,b,z,c],[a,b,c]). true ; false. ?- alt([a],[a]). true ; false. ?- alt([a,b],[a]). true. ?- alt([a,b,c],[a,c]). true ; false. ?- alt([this,is,a,list,of,atoms,okay],X). X = [this, a, of, okay] ; false. ?- alt([a,b,c],[a,e,b,f,g]). false. ?- alt([a,b,c],[]). false. ?- alt([],[a,b,c]). false. ?- alt([x,y,z],[a,b,c]). false. ?- alt([a,b,c,d,e],[a,c]). false. ?- alt(A,[a,b,c]). A = [a, _6638, b, _6650, c] ; A = [a, _6638, b, _6650, c, _6662]. ?- alt([],[]). true. ?- alt([],X). X = []. ?- alt(X,[]). X = []. ?- alt(X,[a]). X = [a] ; X = [a, _7004]. ?- halt.

Submission

Put both relations in the same prolog file. When they works, are nicely formatted and documented, submit the file this form.