Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rounding glitch from bigint to float #63

Closed
Jean-Luc-Picard-2021 opened this issue Oct 19, 2022 · 10 comments
Closed

Rounding glitch from bigint to float #63

Jean-Luc-Picard-2021 opened this issue Oct 19, 2022 · 10 comments

Comments

@Jean-Luc-Picard-2021
Copy link

Jean-Luc-Picard-2021 commented Oct 19, 2022

Hi,

Did some regression testing:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Trealla Prolog 2.4.3

% ?- trealla.
% case, trealla: 0
% case2, trealla: 0
% case3, trealla: 0
% case4, trealla: 0
% case5, trealla: 0
% case6, trealla: 0

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Trealla Prolog 2.4.23

% ?- trealla.
% case, trealla: 0
% case2, trealla: 0
% case3, trealla: 0
% case4, trealla: 0
% case5, trealla: 0
% case6, trealla: 16

Is this to be expected? Test cases here:

Compliance Dogelog Spieler novacore/arithmetic
http://pages.xlog.ch/littab/doclet/docs/10_samples/04_doge_comply/novacore/arithmetic/package.jsp

Maybe this was done in favor of some performance?

@Jean-Luc-Picard-2021 Jean-Luc-Picard-2021 changed the title Regression Testing (**)/2 Regression Testing (**)/2 release 2.4.3 --> 2.4.23 Oct 19, 2022
@infradig
Copy link
Contributor

infradig commented Oct 19, 2022 via email

@Jean-Luc-Picard-2021
Copy link
Author

Ok

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Oct 21, 2022

My bad, was using wrong test cases. But when I use
the most recent ones, I get these results:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Trealla Prolog 2.4.23

case3, trealla: 5
case4, trealla: 0
case5, trealla: 0
case6, trealla: 0

The five failing test cases are among the same problems
as here for Ciao Prolog:

ciao-lang/ciao#77

For example this Trealla Prolog result is a litle too low
for HALF_EVEN. But I don't know whether it is the result

/* SWI-Prolog 8.5.20 Ok */
?- X is float(166153499473114502559719956244594689).
X = 1.6615349947311452e+35.

/* Trealla Prolog 2.4.23 Nok */
?- X is float(166153499473114502559719956244594689).
   X = 1.66153499473114e+35.

of a similar routine used by Trealla Prolog as in Ciao Prolog,
I didn't check what is used to realize float/1 in Trealla Prolog.

@Jean-Luc-Picard-2021 Jean-Luc-Picard-2021 changed the title Regression Testing (**)/2 release 2.4.3 --> 2.4.23 Rounding glitch from bigint to float Oct 21, 2022
@infradig
Copy link
Contributor

infradig commented Oct 21, 2022 via email

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Oct 21, 2022

Hi, I have streamline the test suite a little bit.
Its now only 3-sets testing float/1, (/)/2 and (**)/2.
After git pull I get for your Prolog system:

$ ./tpl -v
Trealla Prolog (c) Infradig 2020-2022, v2.4.26
$ ./tpl
?- ['trealla.p'].
   true.
?- trealla.
case3, trealla: 5
case4, trealla: 0
case6, trealla: 0
   true.

You should get the test cases and a lot of other stuff, via the following,
in the folder samples/dogelog_comply/novacore/arithmetic:

git clone http://www.antwort42.ch/dogelog/.git

And then updates of the test cases.

cd dogelog
git pull

But I hope I am now finished with updating them, except
for regular regression testing in the future, which I expect
to be in intervals of some months, and not daily as of now.

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Oct 21, 2022

As of now I have float/1 conversion in the test case:

?- case3(_, X, Y), Y =\= float(X).

Do you say I can remove it now? And query:

?- case3(_, X, Y), Y =\= X.

I am testing the other Prolog systems without float/1.

This would be another ticket here:

#64

@Jean-Luc-Picard-2021
Copy link
Author

Ok, float/1 can be removed.
Closing the other ticket.

@infradig
Copy link
Contributor

I don't know what the status of this is.

@Jean-Luc-Picard-2021
Copy link
Author

Jean-Luc-Picard-2021 commented Jan 4, 2023

The new version of Trealla Prolog returns another value:

/* Trealla Prolog 2.4.23 Nok */
?- X is float(166153499473114502559719956244594689).
   X = 1.66153499473114e+35.

/* Trealla Prolog 2.7.15 Nok */
?- X is float(166153499473114502559719956244594689).
   X = 1.6615349947311448e+35.

?- 1.66153499473114e+35 =:= 1.6615349947311448e+35.
   false.

But since this is an extremly nasty test case, the rounding
happens based on bits outside of the 53 bit mantissa, so
you need a bigint to float routine that checks the LSB,

least significant bit, of the given bigint as well.
Just check out the binary representation of the bigint:

?- atom_integer(X, 2, 166153499473114502559719956244594689).
X = '1000000000000000000000000000000000000000
000000000000010000000000000000000000000000000
000000000000000000000000000000001'.

Hence the result is not yet correct. One can compare:

/* SWI-Prolog 9.1.0 Ok */
?- X is float(166153499473114502559719956244594689).
X = 1.6615349947311452e+35.

?- 1.6615349947311452e+35 =:= 1.6615349947311448e+35.
false.

/* Trealla Prolog 2.7.15 Nok */
?- X is float(166153499473114502559719956244594689), 
   X =:= 1.6615349947311452e+35.
false

So cannot yet close this ticket.

@Jean-Luc-Picard-2021
Copy link
Author

Scryer Prolog has the same bug:

$ target/release/scryer-prolog -v
"v0.9.1-151-g17450520"
$ target/release/scryer-prolog
?- X is float(166153499473114502559719956244594689).
   X = 1.661534994731145e35.
?- Y = 1.6615349947311452e+35.
   Y = 1.6615349947311452e35.
?- X is float(166153499473114502559719956244594689)-1.6615349947311452e+35.
   X = -3.6893488147419103e19.
?-

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants