home *** CD-ROM | disk | FTP | other *** search
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; File: deriv.cl
- ; Description: The DERIV benchmark from the Gabriel tests.
- ; Author: Vaughan Pratt
- ; Created: 8-Apr-85
- ; Modified: 10-Apr-85 14:53:50 (Bob Shaw)
- ; Language: Common Lisp
- ; Package: User
- ; Status: Public Domain
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-
- ;;; DERIV -- Symbolic derivative benchmark written by Vaughn Pratt.
- ;;; It uses a simple subset of Lisp and does a lot of CONSing.
-
- (defun deriv-aux (a) (list '/ (deriv a) a))
-
- (defun deriv (a)
- (cond
- ((atom a)
- (cond ((eq a 'x) 1) (t 0)))
- ((eq (car a) '+)
- (cons '+ (mapcar #'deriv (cdr a))))
- ((eq (car a) '-)
- (cons '- (mapcar #'deriv
- (cdr a))))
- ((eq (car a) '*)
- (list '*
- a
- (cons '+ (mapcar #'deriv-aux (cdr a)))))
- ((eq (car a) '/)
- (list '-
- (list '/
- (deriv (cadr a))
- (caddr a))
- (list '/
- (cadr a)
- (list '*
- (caddr a)
- (deriv (caddr a))))))
- (t 'error)))
-
- (defun run ()
- (do ((i 0 (1+ i)))
- ((= i 1000))
- (declare (fixnum i))
- (deriv '(+ (* 3 x x) (* a x x) (* b x) 5))
- (deriv '(+ (* 3 x x) (* a x x) (* b x) 5))))
-
- ;;; call: (run)
-
- (run-benchmark "Deriv" '(run))
-