Name_________________________      CCC Unix login__________________________

 

CS 2136                                       EXAM 1                                                 November 20, 2003

 

All five problems count equally.

 

1.      Define each of the following terms.  (One or two sentences each.)

a)      closed-world assumption

b)      Horn clause

c)      unification

d)      backtracking

 

2.      Suppose you have a Prolog database with the following facts:

 

travel(amtrak,new_york,washington,train).

travel(path,new_york,princeton,train).

travel(amtrak,providence,portland,train).

travel(greyhound,providence,portland,bus).

travel(delta,new_york,washington,train).

travel(amtrak,new_york,providence,train).

travel(delta,burlington,new_york,plane).

 

In each fact, the four arguments are: company, origin, destination, and type. For example, the first fact says that you can travel from New York to Washington on Amtrak, using a train.

 

For each of the following queries, what will Prolog print? Assume that when Prolog gives you an answer you hit the semicolon to keep re-satisfying goals, until the query is complete. Do not forget the “Yes” and “No”. You can show the semicolon you type, if you want. (5 points each).

 

         a.      travel(amtrak,new_york,washington,train).

         b.      travel(amtrak,new_york,washington,X).

         c.      travel(amtrak,new_york,X,Y).

         d.      travel(amtrak,new_york,X,train), travel(amtrak,X,portland,train).

 

3.       A programming language could be called a “pure logic programming language” if the language used only the principles of logic.  State three ways in which Prolog fails to be a pure logic programming language, and explain why each of them involves some extra-logical concept.

 

4.      In the following program, the predicate register is true if the Student is permitted to register for the Course.

 

a) Explain what the effect of the cut is.  You explanation should be in terms of this program, and not just a general description of cut.

b) Give a specific example in which the cut makes a difference.  That is, give specific input for which the program would give different results with and without the cut, describe what those results would be, and explain why.  To give a specific example, you may have to assume other clauses in the Prolog program.

 

register(Pers,Course) :-

      student(Pers),

      fees_overdue(Pers),

      !,

      required(Course).

 

register(Pers,Course) :-

      student(Pers),

      required(Course).

 

register(Pers,Course) :-

      student(Pers),

      elective(Course).

 

/* Courses */

required(calculus).

required(cs2136).

elective(swim_and_stay_dry).

 

/* Fees */

fees_overdue(watzer).

 

student(watzer).

student(jones).

student(smith).

 

5.      Write a complete Prolog program to determine if a list of letters contains each of the letters a and b exactly once.  Write a Prolog predicate hasabonce(L) which is true if the list L contains each of these letters exactly once. You may assume that all the letters on the list are lower case.

 

For example,

 

hasabonce([a, b, c, d, e, i, o, x, u]) is true

hasabonce([a, a, b, c, d, e, i, o , u , w]) is false

hasabonce([u, o, i, e, a]) is false.

 

Hint: Write a predicate numtimes(X, L, N) which is true if the element X occurs on the list L exactly N times.