scryer-prolog
scryer-prolog copied to clipboard
The irrational number e is not always understood
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.
?-
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
I think this is even shorter:
?- [X] = "e", _ is X.
Surprisingly it works for pi:
?- [X] = [pi], _ is X.
It looks suspiciously like yet another issue due to the currently only partially finished partial string representation (#24).
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.
The case is now moved to https://github.com/eyereasoner/euler/blob/main/cases/complex.pl
The problem got worse with rebis-dev:
?- _ is e. error(type_error(evaluable,e),(is)/2), unexpected. true. % expected; works in master
Update: e is in fact not a standard arithmetic function, so this works as expected.
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.
Thanks @triska and this now works fine in https://github.com/eyereasoner/euler/blob/574fcec024bfd86e0c035de1210a891ed390dc66/cases/complex.pl
I stumbled on a similar problem recently when dealing with module qualifications. If it's the same thing, the problem here isn't partial strings exactly, it's the Char heap cell variant. It should be interpreted the same as an Atom, but for some reason it isn't in some places in the code.
e is not an arithmetic functor in the standard. It can be considered as an extension (5.5.10) only. exp(1) is working in any conforming system.
?- X is exp(1).
X = 2.718281828459045.
?- X is log(exp(1)).
X = 1.0.
?- X is exp(1)-e.
X = 0.0, unexpected. % in strictly conforming mode (5.1e)
type_error(evaluable,e/0).
With the latest rebis-dev, we get:
?- [X,Y] = [e,f], Z is X. X = e, Y = f, Z = 2.718281828459045, unexpected. error(type_error(evaluable,e/0),(is)/2). % expected
So, we no longer have the problem with quoting/unquoting. The remaining issue that e is not an evaluable functor yet X is e unexpectedly succeeds remains.
Same for Trealla it seems
$ tpl
?- [X,Y] = [e,f], Z is X.
X = e, Y = f, Z = 2.718281828459045.
?-