title: Simplifying Derivation Expression Scheme
body: <p>I am using Scheme language to take the derivative of an inputted expression, and for the most part I believe my table driven function is working well enough but now I'd like to create a few expressions to handle simplifying the output. <br />
  For Example: <br />
  (d '(* (+ x 1) (+ x -1))) -> '(* 2 x) Rather than -> '(+ (* (+ x 1) (+ 1 0)) (* (+ 1 0) (+ x -1)))
  <br />I am rather new to Scheme so I know this is just a matter of being able to recursively parse lists but I'm not sure where to start, any idea how to achieve this? </p>
  
  <p>Here is my code for the function</p>
  
  <pre><code>(define lookup (lambda (x alist) (cadr (assoc x alist))))
  
  
  ;-----------------------------------------------------
  
  (define d
    (lambda (e)
      (cond ((number? e) 0)
        ((equal? e 'x) 1)
        (else
         (let ((op (car e)) (args (cdr e)))
           (apply (lookup op d-op-table) args))))))
  
  
  (define d-op-table
    (list(list '+   (lambda (u v)(list '+ (d u) (d v))))
         (list '-   (lambda (u v)(list '- (d u) (d v))))
         (list '*   (lambda (u v)(list '+ (list '* u (d v))(list '* (d u) v))))
         (list 'sin (lambda (u)(list '*( list 'cos (d u)))))
         (list 'cos (lambda (u)(list '*( list '-sin (d u)))))
         (list 'log (lambda (u)(list '* (list '/ 1 u) (d u))))
         (list 'exp (lambda (u)(list '* (d u)(list 'exp u))))
         (list 'expt (lambda (u v) (list 'expt (list '* v  u) (- v 1))))))
  </code></pre>