CSE 230: Principles of Programming Languages
Homework Assignments


NOTES:
  1. Due 13 January:
    1. Briefly compare Java with at least three other languages, such as 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.
    2. 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, such as those described in the Essay on Comparative Programming Linguistics.

  2. Due 20 January:
    1. Give a BNF definition (do not use extended BNF) of a language of balanced parentheses, in which the only two tokens are ( and ). For example, ()() and ((()))()((()())) are in the language, but ((() is not.
    2. Write the grammar for regular expressions in section 2 of the notes on Sethi 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 ], or by making them optional).
    3. Write an expression that will cause grep to search for, and print the instances of, all the Ada identifiers (as defined below), 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.
             L(L + D)* (_(L + D)(L + D)*)*
      where L indicates an upper or lower case letter, D indicates a decimal digit, and _ is the underbar character.

  3. Due 27 January:
    1. Give a denotational semantics for the grammar for binary numbers at the end of section 2 of the notes on Sethi.
    2. Exercise 2.15 of Sethi (p. 51).
    3. Exercise 3.3 of Sethi (p. 96).

  4. Due 3 February:
    1. Give an OBJ syntax for each of the assignment statements in the list in the notes on chapter 3 of Sethi; give some OBJ3 input and output showing that your signatures work.
    2. 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.
    3. 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.
     
  5. Due 10 February:
    1. Exercise 1, pp.43-46 of Algebraic Semantics; be sure hand in your input and output.
    2. Exercise 4, p.64 of Algebraic Semantics.
    3. Exercise 6, p.64 of Algebraic Semantics.
    4. Exercises 5.2 and 5.3, pages 198-99 of Sethi.
     
  6. Due 17 February:
    1. Write the Black-Scholes algorithm in OBJ; you should import the module FLOAT, which includes the function sqrt.
    2. Exercise 9, p.65 of Algebraic Semantics using OBJ.
    3. Exercise 12, pp.76-77 of Algebraic Semantics using OBJ.
    4. Exercise 6.5, p.248-9 of Sethi.
    5. Run two more proofs using Propositional logic in OBJ.
    6. Please give me a tentative outline of your final paper (project).
     
  7. Due 26 February:
    1. Exercise 17, p.88 of Algebraic Semantics using OBJ.
    2. Exercise 18, p.88 of Algebraic Semantics using OBJ.
    3. Exercise 6.6, p.249 of Sethi.
    4. Code the following Post system in OBJ, and run some examples:
                    N x         N x        x . y = z       x|| . y|| = z
           ---     ------      -----      -----------      -------------
            N       N x|       x . =      x . y| = xz           z         
      What does this system do? Hint: It can be described in just three words (or even one if you cheat a bit).

  8. Due 5 March:
    1. Exercise 22, p.105 of Algebraic Semantics using OBJ.
    2. Exercise 23, p.106 of Algebraic Semantics using OBJ.
    3. Exercises 11.6 and 11.7, p.471 of Sethi.
    4. Find the most general unifier of each pair of terms below, using the OBJ3 spec for unification; explain what this code does, roughly how it does it, and comment on the results of running these pairs of terms; use OBJ3 and include your output.
                 f(a,x)       f(b,x)
                 f(a,x)       g(a,b)
                 f(a,x)       f(a,y)
                 f(a,b)       f(a,b)
                 f(a,x)       f(a,h(x))
       g(f(a,b),h(x,y))       g(f(z,b),h(b,b))
       g(f(a,x),h(x,b))       g(f(a,b),h(a,b))
       g(f(a,x),h(x,b))       g(f(a,b),h(b,b))
       g(f(a,x),h(y,b))       g(z,y)
       g(f(a,x),h(y,b))       g(z,x)  
      where x, y, z are variables, and the rest are constants.
    Note: You may use a different Prolog than BinProlog if you prefer.
     
  9. Due 12 March:
    1. Use OBJ to prove the following identities in the combinatory calculus:
             S K = K I
             S (K I) = B I
             S I (K K) = C I K  
      where Kxy = x, Sxyz = (xz)(yz), Ix = x, Bxyz = x(yz), Cxyz = xzy, and equality means alpha,beta-equivalence (see Combinators in OBJ).
    2. Exercises 14.3 and 14.6, p.576 of Sethi.


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 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.


To CSE 230 homepage
Maintained by Joseph Goguen
© 2000, 2001, 2002, 2003 Joseph Goguen
Last modified: Thu Mar 6 15:30:01 PST 2003