Homework # 11 (corrected)
due Tuesday, April 27, 4:00 PM

Cost Models

Do the following exercises from Chapter 21 on paper: Exercises 21.1-3,9.

Arithmetic

As mentioned in the textbook, arithmetic is not well integrated into Prolog. Suppose < and other relation operators were fully invertible predicates that would work on variables (assuming integers only for now):


?- X>2, X<5.
X = 3;

X = 4

Yes
Suppose further, there was a predicate eval that would evaluate arithmetic terms, which would work even with variables:

?- eval(X*X+1,5).
X = 2;

X = -2

Yes

?- eval(X,2).
X = 2;

X = 0+2;

% many, many more solutions
Yes
Write (on paper) the definition of eval that can handle arbitrary expressions involving addition and multiplication with variables and constants. Your definition may use (unimplemented) predicates add(_,_,_), mul(_,_,_), and isNum(_).

Why do you think Prolog does not do things this way? Hint: think about how add(_,_,_) and isNum(_) would be implemented and how they would work. Your discussion should include information on the cost model for these (hypothetical) predicates.

Optimization

Do Exercises 22.2 and 22.8. Put the results in optimize.pl; your solution will use subseq and minlist (analogous to your answer to 22.2). It is permitted to return the same (optimal) cover more than once.

Submitting Your Work

You submit your program work by putting it in the homework11 directory in your AFS class volume. You may do all your work in this directory, or you may wish to do your work in a different directory and copy things when correct into this directory. In any case, you will lose permission to write things in this directory after the deadline, which is 4:00pm on Tuesday, April 27. In other words, you must be done before lecture starts.

The homework11 directory should include the following:


About this document



John Tang Boyland
2004-04-20