Computer Science 3675
Summer 2000
Programming Assignment 5

Due: June 7

The derivative of an expression is a concept from calculus. The derivative of x (with respect to x) is 1, and the derivative of expression x^2 is 2x. If you are unfamiliar with derivatives, the general rules that are needed here are given below.

Symbolic mathematics packages such as Mathematica and Maple will take derivatives for you. They do so symbolically, in the same way as you do when you are doing it by hand.

For this assignment, you will write a program in Astarte to compute the derivative of an expression. In file /export/stu/3675/deriv.ast, you will find a start: a program that computes derivatives of expressions involving only a variable called xx, constants and addition. The variable is called xx just because it is probably a bad idea to have a global constant called x. File deriv.ast is also available here.

Your assignment is to extend the given program so that it can handle subtraction, multiplication and constant powers.

The rules for taking the derivative a' of an expression a (with respect to x) are as follows. Here, c is a constant and x is the independent variable, called xx in the program.

c' = 0
x' = 1
(a+b)' = a' + b'
(a-b)' = a' - b'
(ab)' = ab' + a'b
(a^c)' = ca^{c-1}a'

These rules can lead to some rather silly looking expressions. If you apply them exactly as stated, you find that the derivative of 2+3*x is 0 + (3)(1) + 0*x. It is nice to do some simplifications. A simplification function is provided. You should extend the simplifier as well, to get simplifications involving subtractions, multiplication and constant powers.

Note. The program is broken into two parts. deriv.ast implements expressions and derivatives. File testderiv.ast contains a tester. Extend it to do more tests.

Note. You are only supposed to deal with constant powers. The equation given for the derivative of a power does not work when c is a general expression. So when you modify the definition of species Expression, be sure to insist that the power be a number, not an expression.

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 0*x = x, x^0 = x, x^0 = 0, 0-x = x and assorted other goodies. By the way, 0^0 is undefined.

Email your solution in the usual way.