egallesio / STklos

STklos Scheme
http://stklos.net
GNU General Public License v2.0
70 stars 17 forks source link

Review precision of exp #341

Closed jpellegrini closed 1 year ago

jpellegrini commented 2 years ago

Hi @egallesio ! While working on SRFI-194, I noticed that the tests signal errors in STklos but not in Gauche. I think it may have to do with the precision of exp:

stklos> (exact (exp (- 280)))
2323769751519553/93035356709837681990313447409664580397266094167976711716030745495121828878514934185752454491361736391777602765602070775492429008462675968

gosh$ (exact (exp (- 280)))
1/40036392008717839792514824508740314371434646680826053093074218662528138779093603265783857283893665565833624695659497852541

Since STklos seems to not converge as well as Gauche in the tests, probably Gauche has a more precise implementation of exp.

Using Maxima, I found this:

Distance of Gauche to Maxima:

(%i1) exp (-280) - 1/40036392008717839792514824508740314371434646680826053093074218662528138779093603265783857283893665565833624695659497852541;
(%o1) 18662528138779093603265783857283893665565833624695659497852541

Distance of STklos to Maxima:

(%i2) exp (-280) - 2323769751519553/93035356709837681990313447409664580397266094167976711716030745495121828878514934185752454491361736391777602765602070775492429008462675968;
(%o2) 679767117160307454951218288785149341857524544913617363917776027656020707754924\
29008462675968

So,

This is probably a very simple thing to change; I'm including it here as an issue just so the information doesn't get lost.

jpellegrini commented 2 years ago

Hm, Gauche seems the only one that behaves that way:

The SRFI tests seem to have been written using Gauche as a working implementation, so it would be better to contact the SRFI authors. I'll do that later.

But still, I'd like to know why Gauche gets closer to Maxima than other implementations...

jpellegrini commented 2 years ago

A bit more information:

In Fricas,

(2) -> exp(-280.0) :: Fraction(Integer)

   (2)
     1
  /
    40036392008717845384023194539837641702592926796795578830468085063699784991_
     158734743483937142825539955730779771077406274555

Which is different from Maxima:

(%07) ratsimp( exp(-280.0));
(%o8) 1/4003639200871784237108441773933670223268126617736359191639377307649967\
3088732009021285915289711101142511335022542771453952

Still investigating

egallesio commented 2 years ago

:thinking:

jpellegrini commented 1 year ago

All Schemes out there seem to agree with STkos, except Gauche (I just verified). So I suppose we don't have to keep this open.