Computer Science 3675
Section 001
Fall 2018
Programming Assignment 7

Assigned: Monday, November 12
Due: Wednesday, November 21, 11:59pm

Purpose of this assignment

This is an exercise in defining and using a type with multiple constructors. The language is Cinnameg.

The assignment

Assignment 4 discusses derivatives. This assignment is to do the same thing using a type Expression to represent expressions. The language is Cinnameg.

Start with deriv.cmg. The expression type currently handles constants, xx (the independent variable), and addition. Extend type Expression and function $. Extend functions derivative and simplify that they handle subtraction, multiplication and power, as in assignment 4.

So that everybody uses the same names (making programs easier for me to test) use operator − for subtraction, operator * for multiplication and operator ^ for exponentation. Design your program so that each of these operators takes two expressions as parameters.

Be careful about types. 0 is a number, not an expression. The corresponding expression is constant(0).

Important notes

Note. The program is broken into two parts. deriv.cmg implements expressions, derivatives and the simplifier. File testderiv.cmg contains a tester. Extend it to do more tests. Be sure to test your new code!

Note. You are only supposed to deal with constant powers. If your deriv function is asked to produce the derivative of an expression where the exponent is not constant, it should fail. File deriv.cmg has an exception called derivativeX defined in it. You can indicate failure to compute the derivative of expression e using expression fail(derivativeX(e)), as in

  …
  else deriv(e) = fail(derivativeX(e))

Note. Internal documentation is important in any program, and it is important that it be correct. When you make modifications, keep the documentation up to date. Failure to do so will cause you to lose points.

Note. Pay attention to what you are writing. I have received submissions for this assignment containing "facts" such as

and assorted other goodies. (By the way, 00 is undefined. It is not terribly important how your program handles that problem. If you treat x0 as 1, that is okay. But in unusual cases, it can lead to some serious problems.)

Note. To compute a real number to a real power, use operator ^*. It computes powers using logarithms and exponentials. (x^*y = exp(y ln(x)).) You can still call your expression exponentiation operator ^.

Submitting the program

Submit both of your programs, the derivative finder and the tester, in the usual way, using the submit command. Be sure to indicate that the assignment number is 7. So use command

  ~abrahamsonk/3675/bin/submit 7 deriv.cmg testderiv.cmg
Command
   ~abrahamsonk/3675/bin/submit 7
will tell you what you have submitted.


Asking Questions

To ask a question about your program, first submit it, but use assignment name q1. For example, use command

  ~abrahamsonk/3675/bin/submit q7 deriv.cmg
Then send me an email with your question. Do not expect me to read your mind. Tell me what your question(s) are. I will look at the file that you have submitted as q7. If you have another question later, resubmit your new file as assignment q7 and send another email.