CSCI 3675
Summer 2001
Homework assignment 3

Due: July 18

You may make use of the append predicate for these exercises. It is defined by
  append([],X,X).
  append([H|T],X,[H|Y]) :- append(T,X,Y).
  1. Using Prolog syntax, write a definition of a predicate called twice where twice(X,Y) is true just when list Y constists of two copies of list X. For example, twice([1,2,3],[1,2,3,1,2,3]) is true.

  2. Using your definition from question 1, show a proof tree diagram of the computation of twice([a,b],[a|X]).

  3. Using your definition from question 1, show a proof tree diagram of the computation of twice(X,[a,a]).

  4. Using Prolog syntax, write a definition of a predicate called allSame where allSame(X) is true if X is a list all of whose members are the same thing. For example, allSame([a,a,a]) is true. By definition, allSame([]) is true.