Problem PS.2.2.1: Derivative Rules


In this problem we will explore the use of backward chaining to implement a simple differentiation system. Some sample rules would be:
 (plus  
   IF
   (deriv ?v ?dv)
   (deriv ?w ?dw)
   THEN (deriv (plus ?v ?w) (plus ?dv ?dw)))
 (times  
  IF
  (deriv ?v ?dv)
  (deriv ?w ?dw)
  THEN (deriv (times ?v ?w) (plus (times ?v ?dw) (times ?dv ?w))))
Each (deriv w dw/dx) assertion in these rules expresses that the second entry is the derivative of the first entry with respect to x.

We will use an auxiliary rule that can tell us if an expression can be treated as a constant, that is, when it does not contain x.

 (aux
   IF
   AND-IF
   (not (contains? 'x '?x))
   THEN
   (constant ?x))

Your job is to finish up this system of rules so that we can differentiate expression involving the sum and product of terms (some of which involve the variable x). For example, we would do

(backchain '(deriv (plus x (times x x)) ?ans))
and expect to find a binding for ?ans. To keep things simple, we will not attempt to simplify any expressions for now. We are looking for a couple of very simple rules.


Below is an applet that flashes matching parens and does Scheme indenting when you type Tab.