An exercise in symbolic manipulation: in Scheme, write a package to perform formal differentiation of algebraic expressions and elementary functions.

Input is an expression in parenthesized prefix notation, for example:

(* 5.0 (sin (* 2 x)))

to denote 5.0 sin (2x) in more conventional notation.

The function Derive takes two arguments: an expression and the variable with respect to which derivation is to be evaluated.

Typically a direct application of the rules of derivation yields expressions with redundant terms (multiplications by zero, for example). Your package should include some simplification rules of the kind : A * 0 => 0, A + 0 => A, and so on, encapsulated in a function Simplify. Simplify should also do some standard constant folding, so the result of differentiating the expression above with respect to x should be:

(* 10.0 (cos (* 2 x)))

This is a very standard example of symbolic manipulation, found in many texts and software packages. Please try to do this without reference to these examples, the exercise will be much more beneficial that way!

pointers to Scheme