;;; elementary functions: take rationals return intervals (require 'affinrat2) ;(require 'intclass) ;; here's the explanation for EXP Arbitrary precision rational exponential function. input: rational number x, interval width w. output: an interval of two rational numbers I=[a,b] of width less than or equal to w, such that exp(x) is in I. Let r = log2(e) [ note: log2(e) = 1/ln(2) = 1.442695040888963...]. Decompose x as x = U*r + V where 0<=V x 0)) (error "non-pos arg to ratlog"))) (let*((e (car (rat-e tol))) (over (/ 1 e)) ) ;; here we should do some argument reduction ;; to get argument between 1/e and e. (do ((n 0 (1+ n)) (oldans 2 ans) ;; huh.. (ans 0 (+ ans (* 2 (/ term (1+ (* 2 n)))))) (term 1 (* term x))) ((< (abs(- ans oldans)) tol) (list ans oldans)))))