vermaseren / form

The FORM project for symbolic manipulation of very big expressions
GNU General Public License v3.0
985 stars 118 forks source link

[WIP] Float tests #492

Open jodavies opened 3 months ago

jodavies commented 3 months ago

Here I have added the example from the Madrid workshop slides.

jodavies commented 3 months ago

To do: why does F1 print with e+0 and F2 without? Which is the desired behaviour?

tueda commented 3 months ago

Well, if we put it into example.frm (examples in the manual), then should we put this example into the manual with the following comment?

% THIS EXAMPLE IS PART OF THE TESTSUITE. CHANGES HERE SHOULD BE APPLIED THERE AS
% WELL! (Float_1)
jodavies commented 3 months ago

The e+0 is a bug actually: F1 should be e+3 (easy to see from the rational form of F1/F2).

Edit: digits wise, I confirmed that there is agreement with PolyLogTools in Mathematica.

vermaseren commented 3 months ago

Very funny indeed. It is the term +89/18*mzv_(9,3,3) that is the culprit. If you leave it out, it prints without the e+0 and if you include it but leave the last term out, it just prints e. Gotta have a good look on the linux computers, because gdb does not work on my apple. I can leave some more terms out to just get the e, but I have not yet discovered the ‘pattern'

On 11 Mar 2024, at 14:26, jodavies @.***> wrote:

To do: why does F1 print with e+0 and F2 without? Which is the desired behaviour?

— Reply to this email directly, view it on GitHub https://github.com/vermaseren/form/pull/492#issuecomment-1988439979, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPCES4BYIDJ5YJLMYDUM3YXWWKBAVCNFSM6AAAAABEQJ5KHWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBYGQZTSOJXHE. You are receiving this because you are subscribed to this thread.

jodavies commented 3 months ago

The ouput is truncated here: https://github.com/vermaseren/form/blob/e99543ad939ef823f5e8db0678aa18028e7de707/sources/float.c#L950

If you ask for numdigits+1 then you get e+03 (and now a bare e appears on the output of F2). I think the required buffer size for the print can be found by calling gmp_snprintf(NULL,0,"%.*Fe",numdigits,aux4) first.

jodavies commented 3 months ago

I was too hasty there, the issue is in the post-processing code that follows. As I understand it you would like the following:

  1. truncate trailing zeros
  2. don't print "e+00"

Is this correct?

fllor commented 3 weeks ago

I found the bug printing routine. One has to change

https://github.com/vermaseren/form/blob/e99543ad939ef823f5e8db0678aa18028e7de707/sources/float.c#L962-L963 to

while ( n2 < n ) { *s1++ = *s2++; n2++; }
n -= (n2-n1);

This will correctly truncate all trailing zeros, but leave the exponent intact. Removing "e+00" is not part of this routine.

jodavies commented 3 weeks ago

OK, please add the fix in your branch and lets see if the valgrind errors are gone. I can rebase this on top of your changes later.

tueda commented 3 weeks ago

By the way, why is the precision of printed numbers strongly influenced by the maximum weight?

#StartFloat 50,6
L F = 1/3;
tofloat;
P;
.end
   F =
      3.3e-01;
jodavies commented 3 weeks ago

The final digit of pi is also not rounded correctly, is it understood why this is?