Blob
1 (defun cube (x)2 (* x x x))3 (defun sum (term a next b)4 (if (> a b)5 06 (+ (funcall term a)7 (sum term (funcall next a) next b))))8 (defun sum-integers (a b)9 (sum #'identity a #'1+ b))10 (defun pi-sum (a b)11 (defun pi-term (x)12 (/ 1.0 (* x (+ x 2))))13 (defun pi-next (x)14 (+ x 4))15 (sum #'pi-term a #'pi-next b))16 (defun integral (f a b dx)17 (defun add-dx (x)18 (+ x dx))19 (* (sum f (+ a (/ dx 2.0)) #'add-dx b) dx))21 (defun simpson-integral (f a b n)22 (let ((h (float (/ (- b a) n))))23 (defun simpson-term (k)24 (* (funcall f (+ a (* k h)))25 (cond ((or (= k 0) (= k n)) 1)26 ((oddp k) 4)27 (t 2))))28 (* (/ h 3)29 (sum #'simpson-term 0 #'1+ n))))