Tests and alternate definitions of lg and exn.
Bradley Lucier 12 Jul 2020 19:30 UTC
There now seem to be four active github repositories and I can't tell
what I should look at to test. It's confusing.
I just spent an hour comparing these two definitions (which I found in
one of the repositories somewhere, and which I thought were current):
(define (exn lg)
(define (trm n u lg) (* lg (+ 1 (/ (* 1ms u) n))))
(trm 2 (trm 3 (trm 4 1 lg) lg) lg))
(define (lg y)
(define yms (* y 1ms))
(define (trm n u r) (- (/ 1 n) (* u r)))
(* y (trm 1 yms (trm 2 yms (trm 3 yms (trm 4 yms 0))))))
to
(define (exn2 lg)
(/ (flexp-1 (* 1ms lg)) 1ms))
(define (lg2 y)
(/ (fllog1+ (* y 1ms)) 1ms))
using flexp-1 and fllog1+ from SRFI 144.
The test had
(define s (+ 1. (/ 300)))
(define 1ms (- 1. s))
and the argument ranges 0..1 and 0..10.
With 100 random arguments between 0 and 1, the errors were
srfi-194-lg samples= 100 max-error-exact= 2.4120156483630522e-11
max-error-exact-arg= .9938914540059453 max-error-double=
2.412011003270222e-11 max-error-double-arg= .9938914540059453
RMS-error-exact= 9.26188658779087e-12 RMS-error-double=
9.261889084258697e-12
srfi-144-lg samples= 100 max-error-exact= 2.8631583467959265e-16
max-error-exact-arg= .8162050798467028 max-error-double=
2.968540443309035e-16 max-error-double-arg= .747060807279462
RMS-error-exact= 1.006292573961332e-16 RMS-error-double=
1.0743385538886467e-16
srfi-194-exn samples= 100 max-error-exact= 2.2907460366860719e-10
max-error-exact-arg= .6693165861577378 max-error-double=
2.2907455638360778e-10 max-error-double-arg= .6693165861577378
RMS-error-exact= 1.4585244601511403e-10 RMS-error-double=
1.4585244661242198e-10
srfi-144-exn samples= 100 max-error-exact= 2.541209861688772e-16
max-error-exact-arg= .17363812148494864 max-error-double=
3.19787020611924e-16 max-error-double-arg= .17363812148494864
RMS-error-exact= 8.649187030413897e-17 RMS-error-double=
1.0121258400120375e-16
max-error-exact: The maximum relative error between the computed result
and the true result
max-error-exact-arg: The argument for which this error was attained
max-error-double: The maximum relative error between the computed result
and the exact result rounded to the nearest double
max-error-double-arg: The argument for which this error was attained
RMS-error-exact: The root-mean-square relative error comparing with the
exact results
RMS-error-double: The root-mean-square relative error comparing with the
exact result rounded to the nearest double.
With 100 random arguments between 0 and 10, the errors were:
srfi-194-lg samples= 100 max-error-exact= 2.43654288848215e-7
max-error-exact-arg= 9.938914540059452 max-error-double=
2.4365428893560356e-7 max-error-double-arg= 9.938914540059452
RMS-error-exact= 9.347325630743659e-8 RMS-error-double=
9.347325631641298e-8
srfi-144-lg samples= 100 max-error-exact= 2.4161776587142494e-16
max-error-exact-arg= 6.496204559507443 max-error-double=
2.70473939316792e-16 max-error-double-arg= 6.496204559507443
RMS-error-exact= 9.859988888510362e-17 RMS-error-double=
1.0280475565778006e-16
srfi-194-exn samples= 100 max-error-exact= 1.3861092173990686e-6
max-error-exact-arg= 9.964086369734716 max-error-double=
1.3861092174439402e-6 max-error-double-arg= 9.964086369734716
RMS-error-exact= 5.738343244244537e-7 RMS-error-double=
5.738343244254292e-7
srfi-144-exn samples= 100 max-error-exact= 2.2955756055570096e-16
max-error-exact-arg= 2.786427743168774 max-error-double=
2.1586819406506796e-16 max-error-double-arg= 8.343860682920326
RMS-error-exact= 8.662566055193718e-17 RMS-error-double=
9.942145881356304e-17
I don't know whether you want to rely on SRFI-144, but it appears that
the error is greater with the current definitions and it would be a good
idea to use
(define (exn2 lg)
(/ (flexp-1 (* 1ms lg)) 1ms))
(define (lg2 y)
(/ (fllog1+ (* y 1ms)) 1ms))
as definitions, relying on fllog1+ and flexp-1 from SRFI 144.
Now that I have the test code, it is easy for me to test alternate
implementations of exn and lg if I didn't test the right definition here.
Brad