; Symbolic differentiation skeleton code ; ; Original concept and code by Gordon Novak at the University of ; Texas at Austin ; - http://www.cs.utexas.edu/users/novak/asg-symdif.html ; ; Minor modifications by Yoonsuck Choe ; - http://faculty.cs.tamu.edu/choe/ ; ; Fri Sep 13 11:34:38 CDT 2002 ;---------------------------------------------------------------------------- ; ; deriv ; ;---------------------------------------------------------------------------- (defun deriv (expr var) (if (atom expr) (if (equal expr var) 1 0) (cond ((eq '+ (first expr)) ; PLUS (derivplus expr var)) ((eq '* (first expr)) ; MULT (derivmult expr var)) (t ; Invalid (error "Invalid Expression!")) ) ) ) ;---------------------------------------------------------------------------- ; ; derivplus: utilizes splus ; ;---------------------------------------------------------------------------- (defun derivplus (expr var) (splus (deriv (second expr) var) (deriv (third expr) var) ) ) ;---------------------------------------------------------------------------- ; ; splus: simplifies addition ; ;---------------------------------------------------------------------------- (defun splus (x y) (if (numberp x) (if (numberp y) (+ x y) (if (zerop x) y (list '+ x y) ) ) (if (and (numberp y) (zerop y)) x (list '+ x y) ) ) )