Xref: utzoo comp.lang.scheme:1820 comp.lang.lisp:4015 Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!julius.cs.uiuc.edu!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!dali.cs.montana.edu!ogicse!zephyr.ens.tek.com!tektronix!percy!data!kend From: kend@data.UUCP (Ken Dickey) Newsgroups: comp.lang.scheme,comp.lang.lisp Subject: Numerical gotcha's Keywords: Interval-Arithmetic Bignums Rationals Message-ID: <431@data.UUCP> Date: 21 Nov 90 17:10:40 GMT Organization: Microcosm, Beaverton, OR Lines: 54 I heard an interesting talk recently on interval arithmetic. One of the messages was about getting bogus answers due to numeric instabilities but not knowing the numbers were bogus. I am interested in knowing what results are obtained for the following on various Scheme & Lisp implementations. Please indicate machine, OS, and what numerics are available {floats, bignums, rationals}. I will post a summary [kend@data.uucp]. f(x,y) = 333.75 y^6 + x^2 (11 x^2 y^2 - y^6 - 121 y^4 - 2) + 5.5 y^8 + x / (2 y). for x = 77617 and y = 33096 The Scheme code for the above follows... ;;===================================================================== ;; from talk on interval arithmetic by G. W. Walster, 1990 Nov 19. (define (f x y) (+ (* (/ 1335 4) (expt y 6)) (* (expt x 2) (- (* 11 (expt x 2) (expt y 2)) (expt y 6) (* 121 (expt y 4)) 2) ) (* (/ 11 2) (expt y 8)) (/ x (* 2 y)) ) ) (define (tryit) (f 77617 33096)) ;; with flonums is {IBM FORTRAN note wrong sign!} ;; f = 1.17260... single precision ;; f = 1.1726039400531... double precision ;; f = 1.172603940053178... extended precision ;; PC Scheme: f = 1.17260394005318 [Intel 386] {bignums, but not rationals} ;; ELK 1.1: f = 1.18059162071741e+21 [Sun3] ??? {floats only} ;; THE CORRECT ANSWER IS: ;; ;; (tryit) -> -54767/66192 {Gambit 1.4; sun3; rationals+bignums} ;; ;; flonum approx of (- (/ 54767 66192)) is -0.827396059946821 {ELK 1.1} ;; ; ---- e o f ---- ;; Thanks, ;; Ken Dickey kend@data.uucp