Spring 2001, CSE 428: Quiz 11.4 - 19 April 2001


Please write your Name and Student ID at the top of the page. By default, this quiz will be returned in Section 1 (afternoon section).
  1. [Pts 2]   Consider the following program computing the reverse of a list with the method of the accumulator:
       rev(L,M) :- aux(L,M,[]).
       aux([],Acc,Acc).       
       aux([X|L],M,Acc) :- aux(L,M,[X|Acc]).
    
    What is the result produced by the query ?- aux([1,2,3],M,[4,5]). ? (only one answer, please)

  2. [Pts 2]   Consider the standard way of representing trees in logic programming, and the following definition of a predicate p:
       p(leaf(X),1).
       p(node(T1,X,T2),N) :- p(T1,N1), 
                             p(T2,N2), 
                             N is N1 + N2 + 1. 
    
    Consider now the query ?- p(t,N). where t is a term representing a certain tree. What is the result returned by it? (only one answer, please)

  3. [Pts 2]   Consider the Prolog query ?- X is 1+Y, Y = 2+3. What is the result returned by it? (only one answer, please)

  4. [Pts 2]   Consider the Prolog query ?- not(X=Y). What is the result returned by it? (only one answer, please)

  5. [Pts 2]   Assume given the following Prolog program:
     
       nat(0).
       nat(N) :- nat(M), N is M+1.
    
    Consider now the query ?- nat(N), N is N + N. What is the result returned by this query? (only one answer, please)