CSE 230: Principles of Programming Languages
Homework Assignments

Two students have complained that there is more homework towards the end of the class, so I will allow you to hand in the last two sets up to 7 days late if you wish.

Homework for the rest of the quarter is now online, but is subject to change in case problems are out of sync with the readings.

Homework will be due on Thursdays for the rest of the quarter, to better synchronize with the lectures, after the delay induced by the midterm.


Binary for OBJ3 is at /net/cs/class/wi99/cse230/obj on the CSE network, and also at /net/cat/disk1/goguen/obj, but this is a slower, older machine. To execute OBJ3, you need a Sun workstation running Solaris or SunOS, such as the CSE instructional machines beowulf, bintijua, kongo, or the machines in the APE lab. If you are not a CSE student, you may need to email csehelp@cs.ucsd.edu to get a CSE student account. Personally, I like to run OBJ3 in a shell inside of emacs; this allows easy editing and easy capture of the output, for use inside of other documents. The OBJ3 Survival Guide may help you along. See also the code that generates the OBJ3 builtin modules (this is also in the OBJ3 Manual). The OBJ3 semantics of the small programming languages used in some exercises below is on the class website; there is also a version without the html wrapping.

Standard ML of New Jersey, version 110.0.6 is available on all CSE unix machines at /net/cs/class/development/elkan/cse230/sml-110/bin/sml, which you can either define as an alias for sml, or else you can add the path for its directory to the PATH variable of your environment. You should actually run your ML code for all of the ML programming problems, and turn in your code along with its output.

Binary for BinProlog 4.00 for Solaris machines (such as the CSE instructional machines beowulf, bintijua, kongo, or the machines in the APE lab) can be found at /net/cs/class/wi99/cse230/prolog/bp, and also as a backup, at /net/cat/disk1/prolog/bp; the latter directory also contains some other files, including some relevant to exercises, so that you don't have to do all the typing yourself. Some basic notes on using BinProlog 4.00 are at binpro.html.


NOTES:
  1. Due 15 January:
    1. Say where Java would go in the Figure on p.23 of Stansifer; write a short paragraph of about 30 words justifying your choice. (You can just photocopy the figure and add a line and dot for Java in red ink.)
    2. Briefly compare Java with at least three other languages from among those described in Chapter 1 of Stansifer (FORTRAN, COBOL, BASIC, Algol, C, Lisp, ML, Ada, C++, etc.); the languages that you choose for comparison should be very different from each other; write one paragraph for each comparison; please try to hit the main points and avoid the trivial points. Note: If you are unfamiliar with Java, you should be able to learn enough to answer the above questions in about 30 minutes, by going to the campus bookstore (or nearly any other bookstore in the country) and skimming parts of one or more of the many Java books there.
    3. Say what is your own favorite programming language, and explain why you like it, without falling into merely subjective considerations; i.e., you should base your argument on real historical, cultural, and pragmatic considerations, as described in the Preliminary Essay on Comparative Programming Linguistics.

  2. Due 22 January:
    1. Write a regular expression that will cause grep to search for, and print the instances of, all the Ada identifiers (as defined on p.45 of Stansifer) that occur as lines in an input file; test it on the file grep.data.html. You may use any convenient variant of grep, such as egrep; you can type "man grep" or "man egrep" etc. at any Sun workstation to learn what you need to know. Be sure to hand in your output file, plus of course your regular expression.
    2. Exercise 2.3 of Stansifer (p.69).
    3. Write the grammar for regular expressions on p.48 of Stansifer as an OBJ3 signature, and run at least 10 test cases, of diverse character, for it using the OBJ3 "parse" command (see p.19 of Algebraic Semantics); be sure to hand in your output, and of course the code. (Note: you will have to fudge the use of parentheses somehow, for example, by replacing them with [ and ].)
    4. Exercises 2.8 and 2.9 of Stansifer (p.70).

  3. Due 29 January:
    1. Exercise 2.13 of Stansifer (p.71).
    2. Exercise 2.20 of Stansifer (p.73). [Due to a possible ambiguity in this problem, if you failed to give an explanation of why your less than 10 word answer is correct, you may hand in such an explanation on Thursday, 7 February.]
    3. Let Sigma be the signature of the OBJ module NATEXP given on page 19 of Algebraic Semantics, with the following added:
             ops x y z : -> Exp .
      Let A be the Sigma algebra with carrier the set of natural numbers, with x,y,z interpreted as 1,2,3 (resp.), and with 0,s,+,* interpreted in the usual way. Then every Sigma term gets a unique interpretation in A, according to the map phi-bar defined on page 21. Calculate the value under phi-bar of the following terms:
      1. s(x + y) + z ;
      2. (x * y) + s s 0 ;
      3. (s s 0 * x) + s(y * z) .
      Now explain how to get OBJ3 to do these calculations, and then actually get it to do so; hand in your input and output.
     
  4. Due 5 February: No homework is due this week; please study for the midterm. The following questions, as well as some of those assigned for next week, might help you with this.
    1. Give an OBJ syntax for each of the assignment statements on page 78 of Stansifer, and for each of the "updating assignment statements" on page 80; give some OBJ3 input and output showing that your signatures work.
    2. If Sigma is the signature of the module NATEXPEQ on page 39 of Algebraic Semantics, give two Sigma-algebras where the first equation (0 + X = X) does not hold.
    3. Exercise 3.5 of Stansifer (p.101).
    4. Exercise 3.8 of Stansifer (p.102).
     
  5. Due 12 February:
    1. Exercise 1, pp.43-46 of Algebraic Semantics; be sure hand in your input and output.
    2. Exercise 4.8 of Stansifer (p.138).
    3. Exercise 4.11 of Stansifer (p.138).
    4. Exercise 4, p.64 of Algebraic Semantics.
    5. Exercise 6, p.64 of Algebraic Semantics.
     
  6. Due 21 February:
    1. Exercises 2.1.4, 2.3.2 and 2.4.3 of Ullman (pp. 20, 33, 43).
    2. Exercise 9, p.65 of Algebraic Semantics using OBJ.
    3. Exercise 12, pp.76-77 of Algebraic Semantics using OBJ.
    4. Exercise 15, p.78 of Algebraic Semantics using OBJ.
    5. Exercise 5.6 of Stansifer (p.179-180).
    6. Exercise 5.8 of Stansifer (p.180-181).

  7. Due 28 February:
    1. Exercises 3.1.2, 3.2.4, 3.3.3, 3.3.10 of Ullman (pp. 53, 65, 75, 76).
    2. Exercise 17, p.88 of Algebraic Semantics using OBJ.
    3. Exercise 20, p.89 of Algebraic Semantics using OBJ.
    4. Exercise 22, pp.105-106 of Algebraic Semantics using OBJ.
    5. Exercises 3.4.4, 3.4.7, 3.5.2 of Ullman (pp. 83, 83, 88). Note: there is a typo in problem 3.4.4: instead of "3.2.1(e)", it should say "3.2.1(f)"; also, in 3.2.1(f), "list of reals" should be changed to "list of strings".
    6. Exercises 3.6.1 and 3.6.3 of Ullman (p. 98).

  8. Due 7 March:
    1. Exercise 6.1 of Stansifer (p.208); use of Prolog is optional, but include your output if you do use it; in each case be sure to say how many answers there are.
    2. Exercise 6.4 of Stansifer (p.209) using Prolog.
    3. Exercise 6.5 of Stansifer (p.210) using Prolog. (Dana Dahlstrom points out that "dangerous" is an adjective, not an adverb.)
    4. Exercise 6.21 of Stansifer (p.213) using Prolog.
    5. Exercise 6.17 of Stansifer (p.212), using the OBJ3 spec for unification; explain what this code does, roughly how it does it, and comment on the results of running the cases in Stansifer; use OBJ3 and include your output.
    6. Exercises 5.1.4, 5.2.1, 5.3.1b,c,e,g,h, 5.4.2, and 5.4.4 of Ullman (pp. 132, 141, 154, 166, 167).
    Note: If you prefer another Prolog system over BinProlog, you may use it instead.
     
  9. Due 14 March:
    1. Exercise 6.9 of Stansifer (p.211) using Prolog.
    2. Prove partial correctness of the little program on p.312 of Stansifer using OBJ3 and the approach of algebraic denotational semantics; in particular, be sure to treat the variables correctly (as opposed to the treatment in Stansifer).
    3. Exercises 7.2 and 7.3 of Stansifer (p.260).
    4. Exercise 7.17 of Stansifer (p.262)
    5. Exercise 7.20 of Stansifer (p.263) using OBJ (for some helpful hints see Section C.6, p.72 of Introducing OBJ), or alternatively, see Lambda calculus in OBJ; please have trace turned on for this problem. (You don't need to hand in all of the output, just the first and last few rewrites would be enough. Also there is an inconsistency in the definition of S, but you can check page 228 of Stansifer, or Lambda calculus in OBJ for the right definition.)
    6. Exercises 5.5.7b, 5.6.1d,f of Ullman (pp. 173, 183).
    7. Exercises 6.2.3 and 6.3.1 of Ullman (pp. 206, 222).

To CSE 230 homepage
Maintained by Joseph Goguen
© 2000, 2001, 2002 Joseph Goguen
Last modified: Thu Mar 7 17:45:59 PST 2002