mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.06k stars 123 forks source link

The irrational number e is not always understood #2455

Open josd opened 4 months ago

josd commented 4 months ago

The following case https://github.com/eyereasoner/eye/blob/1ea6435149beb4d4a483ddb761eae85def65db16/see/temp/complex.pl gives

$ scryer-prolog -g test complex.pl
'https://josd.github.io/cigol#exp'([-1,0],[0.5,0],[6.123233995736766e-17,1.0]).
run,halt causes: error(type_error(evaluable,e),(is)/2)
?-

whereas we expect

$ tpl -g test complex.pl
'https://josd.github.io/cigol#exp'([-1,0],[0.5,0],[6.123233995736766e-17,1.0]).
'https://josd.github.io/cigol#exp'([e,0],[0,pi],[-1.0,1.2246467991473532e-16]).
'https://josd.github.io/cigol#log'([e,0],[-1,0],[0.0,3.141592653589793]).
'https://josd.github.io/cigol#log'([0,1],[0,1],[1.0,0.0]).
'https://josd.github.io/cigol#sin'([1.5707963267949,1.316957896924817],[2.0,-6.6312755068093511e-16]).
'https://josd.github.io/cigol#cos'([0,-1.316957896924817],[2.0,0.0]).
'https://josd.github.io/cigol#tan'([1.338972522294493,0.402359478108525],[1.0,2.0]).
'https://josd.github.io/cigol#asin'([2,0],[1.5707963267949,1.31695789692482]).
'https://josd.github.io/cigol#acos'([2,0],[0.0,-1.31695789692482]).
'https://josd.github.io/cigol#atan'([1,2],[1.33897252229449,0.402359478108525]).

The irrational number pi seems to be understood correctly. This is also fine

$ scryer-prolog
?- X is e^pi.
   X = 23.140692632779263.
?- X is pi^e.
   X = 22.45915771836104.
?-
triska commented 4 months ago

Excellent catch!

I have reduced this to the following test case:

:- use_module(library(debug)).

p([X], Y) :-
        $Y is X.

Yielding:

?- p("e", R).
call:(A is e).
exception:error(type_error(evaluable,e),(is)/2):(A is e).
   error(type_error(evaluable,e),(is)/2), unexpected.

On the other hand, querying the traced goal in isolation works as expected:

?- A is e.
   A = 2.718281828459045. % expected
hurufu commented 4 months ago

I think this is even shorter:

?- [X] = "e", _ is X.

Surprisingly it works for pi:

?- [X] = [pi], _ is X.
triska commented 4 months ago

It looks suspiciously like yet another issue due to the currently only partially finished partial string representation (#24).

josd commented 4 months ago

Makes sense, also this

?- [X,Y] = [e,foo], Z is X.
   X = e, Y = foo, Z = 2.718281828459045.

works fine whereas this

?- [X,Y] = [e,f], Z is X.
   error(type_error(evaluable,e),(is)/2).

is not working fine.

josd commented 3 months ago

The case is now moved to https://github.com/eyereasoner/euler/blob/main/cases/complex.pl

triska commented 1 month ago

The problem got worse with rebis-dev:

?- _ is e.
   error(type_error(evaluable,e),(is)/2), unexpected.
   true. % expected; works in master
triska commented 3 weeks ago

I found a workaround so that you can at least continue for the time being if you want to use it:

?- X is 0 + e.
   X = 2.718281828459045.
josd commented 3 weeks ago

Thanks @triska and this now works fine in https://github.com/eyereasoner/euler/blob/574fcec024bfd86e0c035de1210a891ed390dc66/cases/complex.pl