November 6, 1995
Due in quiz sections November 21, 1995
?- 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).You don't have to hand in anything for this question.
next_color relation. (This is just a Prolog version of the
Lisp function you wrote for Question 5 in Assignment 1.) The
next_color relation has two arguments -- it should succeed if
both arguments are atoms representing stoplight colors, and if the second
argument is the color that follows the first argument. Otherwise it should
fail. Examples:
twice rule that takes two arguments. (This
is also a Prolog version of a previous Lisp question.)
A call to twice succeeds
if both arguments are lists of the same length. Each element
in the second list should itself be a list of length two, with
the original element repeated. Examples:
twice([A],S).) Again, try backtracking in each case and see
if there are more answers. Then try the following goal and see what is
produced upon backtracking:
twice,
called flat_twice, that succeeds if the second list is twice
as long as the first, with each element of the first list repeated.
Examples:
~borning/341/deriv.pl contains the ever-popular
symbolic differentiation program, this time in Prolog. The goal
go1(X) will try the first example, and similarly for
go2(X) and so forth.
The simplification rules contain a number of cuts (the "!" symbol). Why are these there? Try backtracking on the goals with the program as given. Now remove the cuts and try backtracking again. Explain the resulting behavior.