Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Division of Bignums again!

144 views
Skip to first unread message

burs...@gmail.com

unread,
Jun 18, 2018, 9:28:14 PM6/18/18
to
Dear All,

I didn't think that I see bignumber division (/)/2 again.
But unexpectedly I made a new discovery. It seems that
there is really more to it.

I was toying around with this limit, which is kind
of a test bed for bignums:

n^1 + n^2 + ... + n^n
lim n->oo ---------------------
1^n + 2^n + ... + n^n

So I computed the quotient as a float for various
values of n, to get an idea what happens:

I found a bug in my system, I guess the zero is
not desired:

Jekejeke Prolog 3, Runtime Library 1.3.0
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

138 0.639632137435151
139 0.6395777614039586
140 0.6395241669738542
141 0.6394713374128419
142 0.6394192564631296
143 0.0
Error: The function is undefined here.
is/2
f/2

SWI-Prolog is safer, it gives up more earlier:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.15)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

138 0.6396321374351509
139 0.6395777614039586
140 0.6395241669738542
141 0.6394713374128419
142 0.6394192564631295
ERROR: Arithmetic: evaluation error: `float_overflow'

But then DOS EClips simple goes on, not affected
by big numberator or denumerator:

ECLiPSe Constraint Logic Programming System [kernel threads]
Kernel and basic libraries copyright Cisco Systems, Inc.

138 0.639632137435151
139 0.639577761403959
140 0.639524166973854
141 0.639471337412842
142 0.639419256463129
143 0.639367908324447
144 0.639317277638064
145 0.639267349471475
146 0.639218109303712
147 0.63916954301127
148 0.639121636854593
Etc...

I wonder whats the correct algorithm. I know that
I couldn't settly an ISO core standard answer so far,
although (/)/2 is defined in the ISO core standard.

Some old discussion is archived here, and maybe
also something old is found on comp.lang.prolog:
https://github.com/SWI-Prolog/swipl-devel/issues/183

Best regards

burs...@gmail.com

unread,
Jun 18, 2018, 10:14:35 PM6/18/18
to
Am Dienstag, 19. Juni 2018 03:28:14 UTC+2 schrieb burs...@gmail.com:
> I was toying around with this limit, which is kind
> of a test bed for bignums:
>
> n^1 + n^2 + ... + n^n
> lim n->oo ---------------------
> 1^n + 2^n + ... + n^n

For the curious, jhere is a exact solution:

blackpenredpen
https://www.youtube.com/watch?v=nPNB26hxLPc

j4n bur53

unread,
Jun 22, 2018, 2:10:04 PM6/22/18
to
This is also a nice one. JavaScript arithmetic
is possibly not ISO core compatible. I don't
know exactly. What would Ulrich Neumerkel say?

I get this with Tau Prolog:

?- X = 0x4000000000000000.
X = 4611686018427388000.

On the otherhand the usual result
(SWI-Prolog for example):

?- X = 0x4000000000000000.
X = 4611686018427387904.

Credits: https://twitter.com/marcan42
19. Juni post

burs...@gmail.com schrieb:

j4n bur53

unread,
Jun 22, 2018, 2:19:34 PM6/22/18
to
Here is my own interpretation. ISO core Prolog
has a bounded flag. If this is false, the range
is Z, the positive and negative integers,

and there can be resource errors. Otherwise the
range is some {-max_int,max_int} and there should
be some out of bound errors?

But we see this not often implemented, for
example GNU Prolog does the range check
in the input:

GNU Prolog input check:

?- X = 0x4000000000000000.
uncaught exception: error(syntax_error('user_input:1
(char:5) integer overflow (exceeds max_integer)'),read_term/3)

But not during computation:

?- X is 0x200000000*0x20000000.
X = 0

The above multiplication is not ISO conformant,
see also 9.1.3 Integer operations and axioms.
I find for example:

mul_I(x,y) = x * y if x * y in I
= int_overflow if x * y not in I

j4n bur53 schrieb:

burs...@gmail.com

unread,
Jun 23, 2018, 12:53:48 PM6/23/18
to
Ken braught to attention, that a float point
unit for Prolog can be quite challenging. If we
really want to have the error bounds from ISO,
this is not delivered by all float point libraries.

Ken delivered this test case:

Here is what Wolfram Alpha computes:

sin(108086391056891904) = -0.388472474882228641529611...

And here is a selection of Prolog systems, what they do:

Ok, GNU Prolog:

GNU Prolog 1.4.4 (64 bits)
Compiled Apr 23 2013, 16:05:07 with cl

?- X is sin(0x100000000000000+0o2000000000000000000).
X = -0.38847247488222864

Ok, Jekejeke Prolog (by way of Java):

Jekejeke Prolog 3, Runtime Library 1.2.7
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

?- X is sin(0x100000000000000+0o2000000000000000000).
X = -0.38847247488222864

Nok, ECLiPSe Prolog, latest on Windows (there
is an additional error in the number scanner
parser, somehow the hex number is not accepted):

ECLiPSe Constraint Logic Programming System [kernel threads]
Version 7.0 #36 (x86_64_nt), Sun Jan 28 10:18 2018

[eclipse 1]: X is sin(0x100000000000000+0o2000000000000000000).
syntax error: postfix/infix operator expected
| X is sin(0x100000000000000+0o2000000000000000000).
| ^ here

[eclipse 1]: X is sin(108086391056891904).

X = -0.38834424806807816
Yes (0.00s cpu)

Nok, SWI-Prolog, latest on Windows:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- X is sin(0x100000000000000+0o2000000000000000000).
X = -0.38834424806807816.

I am not sure whether the ISO core standard has
a flag, that would allow such a divergence. Like
a flag that explains the use precision of the floating
point operations.

The very old Java libraries, the pre-bundled Math
class couldn't do it as well. Its only later that
they provided strict math, which was better. At least
I think it was like this, if I recall correctly.

I wonder what Android does. I guess I should
run a little test.

burs...@gmail.com

unread,
Jun 23, 2018, 12:56:21 PM6/23/18
to

burs...@gmail.com

unread,
Jun 23, 2018, 1:26:21 PM6/23/18
to
But probably any result for a this large argument
is wrong anyway. I get:

Here is what Wolfram Alpha computes:

sin(108086391056891904) = -0.388472474882228641529611...
sin(108086391056891903) = 0.390731128489273755062084...

Now GNU Prolog produces:

| ?- X is sin(108086391056891904).
X = -0.38847247488222864
yes

?- X is sin(108086391056891903).
X = -0.38847247488222864
yes

And then SWI-Prolog:

?- X is sin(108086391056891904).
X = -0.38834424806807816.

?- X is sin(108086391056891903).
X = -0.38834424806807816.

Ha Ha

To see the differences in the floating point unit,
you need lower values, not that large values. Here is
another test case:

GNU-Prolog:

?- between(1,18,N), A is 10^N, X is sin(A), write(sin(A)=X), nl, fail; true.
sin(10)= -0.54402111088936977
sin(100)= -0.50636564110975879
sin(1000)=0.82687954053200252
sin(10000)= -0.30561438888825215
sin(100000)=0.035748797972016508
sin(1000000)= -0.34999350217129294
sin(10000000)=0.4205477931907825
sin(100000000)=0.93163902710972601
sin(1000000000)=0.54584344944869956
sin(10000000000)= -0.48750602508751067
sin(100000000000)=0.92869366049659197
sin(1000000000000)= -0.61123870237688949
sin(10000000000000)= -0.28888529481752512
sin(100000000000000)= -0.20940830749645231
sin(1000000000000000)=0.85827279317023586
sin(10000000000000000)=0.77968800660697879
sin(100000000000000000)= -0.46453010483537271
sin(1000000000000000000)= -0.99296932074040511

SWI-Prolog:

sin(10)= -0.5440211108893698
sin(100)= -0.5063656411097588
sin(1000)=0.8268795405320025
sin(10000)= -0.30561438888825215
sin(100000)=0.03574879797201638
sin(1000000)= -0.34999350217129177
sin(10000000)=0.4205477931907708
sin(100000000)=0.9316390271096793
sin(1000000000)=0.5458434494497783
sin(10000000000)= -0.48750602507627
sin(100000000000)=0.9286936605443354
sin(1000000000000)= -0.6112387013579699
sin(10000000000000)= -0.28888528249228407
sin(100000000000000)= -0.2094084333834997
sin(1000000000000000)=0.8582721324763734
sin(10000000000000000)=0.779679945161067
sin(100000000000000000)= -0.4646441089357643
sin(1000000000000000000)= -0.9928161040530035

Jekejeke Prolog:
sin(10)= -0.5440211108893698
sin(100)= -0.5063656411097588
sin(1000)=0.8268795405320025
sin(10000)= -0.30561438888825215
sin(100000)=0.03574879797201651
sin(1000000)= -0.34999350217129294
sin(10000000)=0.4205477931907825
sin(100000000)=0.931639027109726
sin(1000000000)=0.5458434494486996
sin(10000000000)= -0.4875060250875107
sin(100000000000)=0.928693660496592
sin(1000000000000)= -0.6112387023768895
sin(10000000000000)= -0.2888852948175251
sin(100000000000000)= -0.2094083074964523
sin(1000000000000000)=0.8582727931702359
sin(10000000000000000)=0.7796880066069788
sin(100000000000000000)= -0.4645301048353727
sin(1000000000000000000)= -0.9929693207404051

Am Samstag, 23. Juni 2018 18:53:48 UTC+2 schrieb burs...@gmail.com:

burs...@gmail.com

unread,
Jun 23, 2018, 1:48:31 PM6/23/18
to
Differeing values start with sin(100000), but
lets test one scale after it. Wolfram Alpha gives:

sin( 999999) = -0.97735203153822295...
sin(1000000) = -0.34999350217129295...
sin(1000001) = 0.59914743901419226...

GNU Result:

?- between(999999,1000001,A), X is sin(A), write(sin(A)=X), nl, fail; true.
sin(999999)= -0.97735203153822292
sin(1000000)= -0.34999350217129294
sin(1000001)=0.59914743901419221

SWI-Prolog Result (is also quite good,
compared to Wolfram Alpha, but different
from GNU):

?- between(999999,1000001,A), X is sin(A), write(sin(A)=X), nl, fail; true.
sin(999999)= -0.9773520315382227
sin(1000000)= -0.34999350217129177
sin(1000001)=0.5991474390141933
true.

An here O-Prolog, almost same floating point results as SWI-Prolog,
but there is a problem in the toplevel. The fail; true construct
doesn't work:

?- between(999999,1000001,A), X is sin(A), write(f(A)=X), nl, fail; true.
yes

So since the automatic loop doesn't work, doing it manually:

?- between(999999,1000001,A), X is sin(A), write(f(A)=X), nl.
f(999999)=-0.9773520315382227
A = 999999
X = -0.9773520315382227;
f(1000000)=-0.3499935021712918
A = 1000000
X = -0.3499935021712918;
f(1000001)=0.5991474390141933
A = 1000001
X = 0.5991474390141933;
no

burs...@gmail.com

unread,
Jun 23, 2018, 8:27:25 PM6/23/18
to
Question concerning ECLiPSe Prolog:
Is this still work in progress?

Somehow the ISO core standard sign/1 is missing:

ECLiPSe Constraint Logic Programming System [kernel threads]
Version 7.0 #36 (x86_64_nt), Sun Jan 28 10:18 2018

[eclipse]: X is sign(-5.0).
calling an undefined procedure sign(-5.0, X) in module eclipse
Abort

Importing the ISO library doesn't change the situation.
But what I found is this one:

[eclipse]: X is sgn(-5.0).
X = -1
Yes (0.00s cpu)

Which is an interesting variant, since it doesn't return
float but integer for a float argument.
A more abitious sign/1 is documented here, which would
also cover negative zero and inf.
http://eclipseclp.org/Specs/core_update_float.html

sgn/1 cannot handle negative zero:

[eclipse]: X is sgn(-0.0).
X = 0
Yes (0.00s cpu)

But the ECLiPSe sgn can already handle inf:

[eclipse]: X is 1.0/0.0.
X = 1.0Inf
Yes (0.00s cpu)

[eclipse]: X is sgn(1.0/0.0).
X = 1
Yes (0.00s cpu)

In SWI-Prolog inf cannot be entered this way, but
sign/1 can already handle inf:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- X is 1.0/0.0.
ERROR: Arithmetic: evaluation error: `zero_divisor'
ERROR: In:
ERROR: [8] _4308 is 1.0/0.0
ERROR: [7] <user>

?- X is 1.0Inf.
X = 1.0Inf.

?- X is sign(1.0Inf).
X = 1.0.

ken...@gmail.com

unread,
Jun 23, 2018, 10:19:28 PM6/23/18
to
Hi Burse.

Today I pre-released O-Prolog ver 1.00.
Conformity is still incomplete.
Please test.
http://eisl.kan-be.com/library/oprolog1.html

Kenichi Sasagawa

Joachim Schimpf

unread,
Jun 24, 2018, 5:37:16 AM6/24/18
to
On 24/06/18 01:27, burs...@gmail.com wrote:
> Question concerning ECLiPSe Prolog:
> Is this still work in progress?
>
> Somehow the ISO core standard sign/1 is missing:
>
> ECLiPSe Constraint Logic Programming System [kernel threads]
> Version 7.0 #36 (x86_64_nt), Sun Jan 28 10:18 2018
>
> [eclipse]: X is sign(-5.0).
> calling an undefined procedure sign(-5.0, X) in module eclipse
> Abort
>
> Importing the ISO library doesn't change the situation.

ECLiPSe is a multi-dialect system. If you want to do ISO-related
tests, use the -L iso or -L iso_strict command line option.

$ eclipse -L iso
ECLiPSe Constraint Logic Programming System [kernel threads]
Version 7.0 #42 (x86_64_linux), Fri Mar 30 17:36 2018
[eclipse 1]: X is sign(-5.0).
X = -1.0
Yes (0.00s cpu)



> But what I found is this one:
>
> [eclipse]: X is sgn(-5.0).
> X = -1
> Yes (0.00s cpu)
>
> Which is an interesting variant, since it doesn't return
> float but integer for a float argument.
> A more abitious sign/1 is documented here, which would
> also cover negative zero and inf.
> http://eclipseclp.org/Specs/core_update_float.html
>
> sgn/1 cannot handle negative zero:
>
> [eclipse]: X is sgn(-0.0).
> X = 0
> Yes (0.00s cpu)

This is the intended result (the sgn-function predates ISO).

As discussed in the document you have linked to, there is no really
satisfactory solution for sign(-0.0). ECLiPSe and SWI have therefore
introduced copysign/2, e.g.

[eclipse 3]: X is copysign(3.3,-0.0).
X = -3.3
Yes (0.00s cpu)


Cheers,
Joachim

burs...@gmail.com

unread,
Jun 24, 2018, 6:24:46 AM6/24/18
to
Ok, I didn't try "-L iso", last I tried was:

[eclipse 1]: use_module(library(iso_strict)).
iso_aux.eco loaded in 0.00 seconds
multifile.eco loaded in 0.00 seconds
iso_light.eco loaded in 0.02 seconds
iso_heavy.eco loaded in 0.00 seconds
iso_error.eco loaded in 0.00 seconds
iso_strict.eco loaded in 0.02 seconds

Yes (0.03s cpu)
[eclipse 2]: X is sign(-5.0).
Ambiguous import of is / 2 from [eclipse_language,
iso_strict] in module eclipse
Ambiguous import of is / 2 from [eclipse_language,
iso_strict] in module eclipse
procedure does not exist: is / 2 in eclipse
Abort

I will try to use the "-L iso" option in the
future. Its a little tricky to use on Windows,
in case one wants to modify DosEclipse.lnk:

https://superuser.com/questions/29569/how-to-add-command-line-options-to-shortcut

When I use "-L iso" mode, I still get:

[eclipse 3]: X is 1.0/0.0.
X = 1.0Inf
Yes (0.00s cpu)

SWI-Prolog on the other hand gives me:

?- X is 1.0/0.0.
ERROR: Arithmetic: evaluation error: `zero_divisor'

So the -L iso flag, is a kind of future ISO
core standard mode?

burs...@gmail.com

unread,
Jun 24, 2018, 6:37:10 AM6/24/18
to
Ok, its documented:

9 Evaluable functors
The 'exceptional values' are realized as follows: 'float_overflow' leads to a floating point infinity result; 'underflow' leads to a floating point denormalized value result; 'zero_divisor' leads to a floating point infinity result in the case of floats, or an evaluation_error(zero_divisor) in the case of integers; 'int_overflow' does not occur and might lead to running out of memory instead.

But on the other hand the ISO Core
Standard still says, this was not yet changed.
But anyway the ECLiPSe redefininition makes
sense, if one wants to support Inf etc..

9.1.2 Exceptional values
An exceptional value is float-Overflow,
underflow, Zero-divisor, or undefined.

NOTE - It is an evaluation-error (E) if the value of an
expression is an exceptional value (see 7.9.2).

7.9.2 Errors
The following errors may occur during the evaluation of
an expression E:

burs...@gmail.com

unread,
Jun 24, 2018, 7:03:24 AM6/24/18
to
I am currently working more closely with ECLiPSe Prolog.
I think they have a very good division. For example I not
only get this result:

Version 7.0 #36 (x86_64_nt), Sun Jan 28 10:18 2018
[eclipse 1]: X is (3*10^500)/(5*10^500).
X = 0.6
Yes (0.00s cpu)

But also this result:

[eclipse 2]: X is 3.0E50/(5*10^500).
X = 0.0
Yes (0.00s cpu)

Just in case, is it possible to file bugs for the new
ECLiPSe Prolog version? This Bugzilla is still active,
right? Looks like last bug was raised 2018-02-09:

http://eclipseclp.org/bugzilla/show_bug.cgi?id=809

burs...@gmail.com

unread,
Jun 24, 2018, 7:15:36 AM6/24/18
to
Thanks for sharing Ken!

Remember the nasty example, with a cut in some
clause. How about the cut on the toplevel?

O-Prolog Ver 1.00(shizuka)

| ?- (X = 1 ; X = 2), (true -> !; fail).
X = 1;
X = 2;
no

On the other hand:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- (X = 1 ; X = 2), (true -> !; fail).
X = 1.

Do you have a BugZilla or something?

Maybe the above is not a that interesting bug. What
I recently is observed is the following. I often use
the patter .... fail; true to write out something in

the toplevel. But this seems also not to work:

O-Prolog Ver 1.00(shizuka)

?- (X = 1 ; X = 2), write(X), nl, fail; true.
_0001
yes

On the other hand, for SWI-Prolog I get:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- (X = 1 ; X = 2), write(X), nl, fail; true.
1
2
true.

So my suspicion is that there is somewhere a bug
with your (;)/2 operator. The problem only disappears if I
don't use the semicolon (;)/2 and make two clauses:

O-Prolog Ver 1.00(shizuka)

| test :- (X = 1 ; X = 2), write(X), nl, fail.
| test :- true.

| ?- test.
1
2
yes

But the problem is still there if I make one
single clause:

O-Prolog Ver 1.00(shizuka)

| test :- (X = 1 ; X = 2), write(X), nl, fail; true.

| ?- test.
v_1
yes

But it should also work for one clause, as
you can easily see here:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- [user].
|: test :- (X = 1 ; X = 2), write(X), nl, fail; true.
|:
% user://1 compiled 0.00 sec, 1 clauses
true.

?- test.
1
2
true.

burs...@gmail.com

unread,
Jun 24, 2018, 7:17:30 AM6/24/18
to
BTW: I don't find any problem with the parsing, this
seems to be Ok:

O-Prolog Ver 1.00(shizuka)
| ?- Clause = ( test :- (X = 1 ; X = 2), write(X), nl, fail; true ), write_canonical(Clause), nl.
test:-';'(','(';'(=(X,1),=(X,2)),','(write(X),','(nl,fail))),true)
Clause = test:-X=1;X=2,(write(X),nl,fail);true

So it must be a problem during interpretation or
compilation of the disjunction (;)/2.

Joachim Schimpf

unread,
Jun 24, 2018, 9:36:24 AM6/24/18
to
On 24/06/18 11:24, burs...@gmail.com wrote:
>
> I will try to use the "-L iso" option in the
> future. Its a little tricky to use on Windows,
> in case one wants to modify DosEclipse.lnk:
>
> https://superuser.com/questions/29569/how-to-add-command-line-options-to-shortcut

Alternatively, you can

- set an environment variable ECLIPSEDEFAULTLANGUAGE to iso or iso_strict

- or make an ECLIPSEDEFAULTLANGUAGE string-valued registry entry under
HKLM/SOFTWARE/IC-Parc/Eclipse/7.0 and set it to iso or iso_strict

- or create a new module that uses the desired language dialect, and
make that the toplevel-module:

?- create_module(iso_test, [], iso).
?- set_flag(toplevel_module, iso_test).

[interactively, or put it into an .eclipserc file under $HOME/$HOMEPATH]


Cheers,
-- Joachim

burs...@gmail.com

unread,
Jun 24, 2018, 10:26:54 AM6/24/18
to
Trying to get to the bones of this big number division,
which has a much large range, namely a better (/)/2, also
better for small and big integer numbers. Now I have

some findings elsewhere. ECLiPSe Prolog probably
implements HALF_EVEN:

ECLiPSe Constraint Logic Programming System [kernel threads]
Version 7.0 #36 (x86_64_nt), Sun Jan 28 10:18 2018

[eclipse 8]: X is float(2^53+3)-float(2^53+2).
X = 2.0
Yes (0.00s cpu)

[eclipse 9]: X is float(2^53+1)-float(2^53).
X = 0.0
Yes (0.00s cpu)

Java does also HALF_EVEN it seems:

Jekejeke Prolog 3, Runtime Library 1.3.0
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

?- X is float(2^53+3)-float(2^53+2).
X = 2.0

?- X is float(2^53+1)-float(2^53).
X = 0.0

SWI-Prolog does something else:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- X is float(2^53+3)-float(2^53+2).
X = 0.0.

?- X is float(2^53+1)-float(2^53).
X = 0.0.

But I guess its implementation defined, what is used.
But I am not sure whether its consistent across
the following:
- Same rounding modes in small and big numbers?
- Some rounding modes in float reading and writing?

So preliminary now finding so far, there must be a lot
of discrepancies lurking:

ECLiPSe Constraint Logic Programming System [kernel threads]
Version 7.0 #36 (x86_64_nt), Sun Jan 28 10:18 2018

[eclipse 10]: X is 7.0E50-float(7*10^50).
X = 8.3076749736557242e+34
Yes (0.00s cpu)

What does Java:

Jekejeke Prolog 3, Runtime Library 1.3.0
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

?- X is 7.0E50-float(7*10^50).
X = 0.0

And SWI-Prolog:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- X is 7.0E50-float(7*10^50).
X = 8.307674973655724e+34.

So I guess the big number integer rounding could be
different than the small number integerr rounding in
ECLiPSe Prolog. But still busy with the better division,
that has a larger range. Just a side finding.

burs...@gmail.com

unread,
Jun 24, 2018, 12:05:39 PM6/24/18
to
What is test16 ?
https://twitter.com/SSukimu/status/1010707429170876416

Am Sonntag, 24. Juni 2018 13:15:36 UTC+2 schrieb burs...@gmail.com:

burs...@gmail.com

unread,
Jun 24, 2018, 2:00:04 PM6/24/18
to
Yes there is not necessarely consistency between
small numbers and big numbers. I find the following:

[eclipse 1]: X is float((2^53+1)*2^100)-float(2^53*2^100).
X = 0.0
Yes (0.00s cpu)

[eclipse 2]: X is float((2^53+3)*2^100)-float((2^53+2)*2^100).
X = 0.0
Yes (0.00s cpu)

[eclipse 3]: X is float(2^53+1)-float(2^53).
X = 0.0
Yes (0.00s cpu)

[eclipse 4]: X is float(2^53+3)-float(2^53+2).
X = 2.0
Yes (0.00s cpu)

So small number uses HALF_EVEN and big number uses
possibly TOWARDS_ZERO. Here is what Java delivers:

?- X is float((2^53+1)*2^100)-float(2^53*2^100).
X = 0.0

?- X is float((2^53+3)*2^100)-float((2^53+2)*2^100).
X = 2.5353012004564588E30

?- X is float(2^53+1)-float(2^53).
X = 0.0

?- X is float(2^53+3)-float(2^53+2).
X = 2.0

j4n bur53

unread,
Jun 24, 2018, 3:00:34 PM6/24/18
to
So whats the scope of all this nitpicking. Basically
better understanding the ISO core standard.

Practically there should be some consistent bounds
somehow, so that one knows what can be expected.

On the other hand that doesn't imply that all systems,
aka Prolog processors, should exactly do the same.

Here a little surprise I just discovered:

On Java:

?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
15-0.0
16-0.0
17-0.0
18-0.0
19-0.0
20-0.0
21-0.0
22-0.0
23-1.6777216E7
24-0.0
25-0.0
26-0.0
27-0.0
28-0.0
29-0.0
30-0.0

On Adroid:

?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
15-0.0
16-0.0
17-0.0
18-0.0
19-0.0
20-0.0
21-0.0
22-0.0
23-0.0
24-0.0
25-0.0
26-0.0
27-0.0
28-0.0
29-1.7592186044416E13
30-0.0

burs...@gmail.com schrieb:

j4n bur53

unread,
Jun 24, 2018, 3:09:10 PM6/24/18
to
More results:

Quite consistent:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
15-0
16-0
17-0
18-0
19-0
20-0
21-0
22-0
23-0
24-0
25-0
26-0
27-0
28-0
29-0
30-0
true.

Less consistent:

YAP 6.3.3 (i686-mingw32): Sun Jan 20 18:27:56 GMTST 2013
?- between(15,30,N), X is 10**N-10^N, write(N-X), nl, fail; true.
15- 0.0
16- 0.0
17- 0.0
18- 0.0
19- 0.0
20- 0.0
21- 0.0
22- 0.0
23- 0.0
24- 0.0
25- 2147483648.0
26- 17179869184.0
27- 137438953472.0
28- 0.0
29- 0.0
30- 140737488355328.0

j4n bur53 schrieb:

ken...@gmail.com

unread,
Jun 24, 2018, 6:47:52 PM6/24/18
to
Hi Burse.

Thanks for the bug report.
There seems to be a problem with disjunction processing.
I will improve.

Kenichi Sasagawa

ken...@gmail.com

unread,
Jun 24, 2018, 6:53:08 PM6/24/18
to
The test16 predicate works 9Queens 16 times in a row.
That image is the execution of that predicate on Raspai3.

Kenichi Sasagawa

burs...@gmail.com

unread,
Jun 24, 2018, 7:50:30 PM6/24/18
to
Ok. BTW: It seems that I can create an endless
stream of nitpicking. But the answer to everything
is 42. Thats why half of it is a good testcase:

O-Prolog Ver 1.00(shizuka)
| ?- X is 2.1/10.
X = 0.21
yes

| ?- X is 2.1/10-0.21.
X = 2.775557561562891e-017
yes

And then:

ECLiPSe Constraint Logic Programming System [kernel threads]
Version 7.0 #36 (x86_64_nt), Sun Jan 28 10:18 2018

?- X is 2.1/10.
X = 0.21000000000000002.

?- X is 2.1/10-0.21.
X = 2.7755575615628914e-17.

Somehow I guess a canonical write would require the
second behaviour. So that you see all the "bits" of
a number, and nothing is hidden.

ken...@gmail.com

unread,
Jun 24, 2018, 10:53:49 PM6/24/18
to
Hi Burse.

I made the following code for floating point number display.

Kenichi Sasagawa

-------------------
case FLTN: x = GET_FLT(addr);
if(x - ceil(x) != 0)
fprintf(GET_PORT(output_stream),"%0.16g", x);
else if(x < 1e16)
fprintf(GET_PORT(output_stream),"%0.1f", x);
else
fprintf(GET_PORT(output_stream),"%0.1e", x);
break;

-------------------

burs...@gmail.com

unread,
Jun 25, 2018, 12:04:02 AM6/25/18
to
0.21000000000000002
12345678901234567

17 digits

burs...@gmail.com

unread,
Jun 25, 2018, 12:06:33 AM6/25/18
to
For g and G specifiers: This is the maximum number
of significant digits to be printed.
https://www.tutorialspoint.com/c_standard_library/c_function_fprintf.htm

burs...@gmail.com

unread,
Jun 25, 2018, 12:07:49 AM6/25/18
to
But I don't know whether it fixes the problem.
If you increase the number of digits shown.

burs...@gmail.com

unread,
Jun 25, 2018, 12:25:32 AM6/25/18
to
Digit Ranges For Round-Trips To and From IEEE Binary Floating-Point
https://www.exploringbinary.com/number-of-digits-required-for-round-trip-conversions/

me Bits Max digits for
decimal-binary-decimal round-trip Min digits for
binary-decimal-binary round-trip
Half 11 3 5
Single 24 6 9
Double 53 15 17
Extended 64 18 21
Quadruple 113 33 36

burs...@gmail.com

unread,
Jun 25, 2018, 12:29:54 AM6/25/18
to
Some examples and further discussion, the fprintf
needs really able to produce a special 17-stand in:

"On the other hand, an arbitrary, arbitrarily
long decimal literal rounded or truncated to
17 digits may not convert to the double-
precision value it’s supposed to. This is
a subtle point, one that has even tripped up
implementers of widely used decimal to floating-
point conversion routines (glibc strtod() and
Visual C++ strtod(), for example)."
https://www.exploringbinary.com/17-digits-gets-you-there-once-youve-found-your-way/

burs...@gmail.com

unread,
Jun 25, 2018, 12:46:17 AM6/25/18
to
Since I already spent the whole weekend with some
BigDecimal stuff, which I couldn't finish because of
some very difficult HALF_EVEN rounding.

I guess I can also spend a little time with
producing these test cases. All the test cases
should give zero in the subtraction, which is not yet

the case for your Prolog system:

O-Prolog Ver 1.00(shizuka)

| ?- X is sqrt(2).
X = 1.414213562373095
yes

| ?- X is sqrt(2)-1.414213562373095.
X = 2.220446049250313e-016
yes

| ?- X is pi/3.
X = 1.047197551196597
yes

| ?- X is pi/3-1.047197551196597.
X = -2.220446049250313e-016
yes

On the otherhand, here it works fine, here I am
subtractiong other values, those that are printed by
the system and that are different:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- X is sqrt(2).
X = 1.4142135623730951.

?- X is sqrt(2)-1.4142135623730951.
X = 0.0.

?- X is pi/3.
X = 1.0471975511965976.

?- X is pi/3-1.0471975511965976.
X = 0.0.

ken...@gmail.com

unread,
Jun 25, 2018, 2:42:12 AM6/25/18
to
Hi burse.

I fixed.
I am glad that a bug was found early.

Kenichi Sasagawa

O-Prolog Ver 1.01(shizuka)
| ?- (X = 1 ; X = 2), write(X), nl, fail; true.
1
2
yes
| test :- (X = 1 ; X = 2), write(X), nl, fail; true.
| ?-test.
1
2
yes
|

ken...@gmail.com

unread,
Jun 25, 2018, 2:54:21 AM6/25/18
to
I fixed.
Thank you.


Kenichi Sasagawa

O-Prolog Ver 1.01(shizuka)
| ?- X is pi/3.
X = 1.0471975511965976
yes
| ?- X is pi/3-1.0471975511965976.
X = 0.0
yes
|

burs...@gmail.com

unread,
Jun 25, 2018, 3:44:12 AM6/25/18
to
Hi Ken,

There is some new challenge. This is a program
that can kill GNU Prolog, I dunno why. My GNU
Prolog simply crashes. What is your error?

O-Prolog Ver 1.00(shizuka)
| ack(0,N,X) :- !, X is N+1.
| ack(M,0,X) :- !, H is M-1, ack(H,1,X).
| ack(M,N,X) :- J is N-1, ack(M,J,Y), H is M-1, ack(H,Y,X).
| ?- ack(3,10,X).
Syntax error eval [yes]

Expected result:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- time(ack(3,10,X)).
% 67,043,401 inferences, 8.313 CPU in 8.404 seconds (99% CPU, 8065372 Lips)
X = 8189.

Unfortunately I am slower:

Jekejeke Prolog 3, Runtime Library 1.3.0
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

?- time(ack(3,10,X)).
% Up 11,297 ms, GC 125 ms, Thread Cpu 11,172 ms (Current 06/25/18 09:38:55)
X = 8189

And here is how scala does it nowdays, but
I wasn't patient enough to try ack(4,1,X) in
Prolog. Maybe during lunch.

Ackermann in Scalaz with Trampoline
https://gist.github.com/folone/6258410

ken...@gmail.com

unread,
Jun 25, 2018, 4:14:01 AM6/25/18
to
Hi Burse

> O-Prolog Ver 1.00(shizuka)
> | ack(0,N,X) :- !, X is N+1.
> | ack(M,0,X) :- !, H is M-1, ack(H,1,X).
> | ack(M,N,X) :- J is N-1, ack(M,J,Y), H is M-1, ack(H,Y,X).
> | ?- ack(3,10,X).
> Syntax error eval [yes]
>

O-Prolog has crashed.
It can not detected a stack overflow.
That strange message is due to a crash.

I think that it can be solved by tail recursive optimization.
The current OPL compiler can only be rudimentarily optimized.
I will make it a future subject.

Kenichi Sasagawa

ken...@gmail.com

unread,
Jun 25, 2018, 5:37:52 AM6/25/18
to
Hi Burse

This is my naive question.

I purchased ISO/IEC 13211-2(module)
I think that this is basically the same as the one described in the 1993 draft.
However, I think that what is adopted in SWI-Prolog is quite different from this one.
I guessed that there was a revision for standards of module.
But there was not such a thing.

Why did SWI-Prolog need to adopt module system different from ISO-Prolog?

burs...@gmail.com

unread,
Jun 25, 2018, 6:03:36 AM6/25/18
to
I dont know anything about the SWI-Prolog system.
You need to ask the makers of SWI-Prolog. But you
can read how the module standard developed here:

Modules for Prolog: Proposal for Part 2 of the Standard
Appeared in volume 8/4, November 1995
Keywords: standard. Jonathan Hodgson
https://dtai.cs.kuleuven.be/projects/ALP/newsletter/archive_93_96/comment/modules.html

I guess I am able to answer question related to the
above text. For example Jekejeke Prolog has thus
far evolved, that I have now even nested modules,
which wasn't perceived in 1995.

Otherwise conceptually much of the things as summarized
in the above report have been realized, whereby
adopting the syntax of SWI-Prolog and not the
syntax from ISO module standard.

So basically:
- Concept yes
- Syntax no

burs...@gmail.com

unread,
Jun 25, 2018, 6:21:20 AM6/25/18
to
My nested modules allow for easy testing
concepts in the toplevel. For example I get:

Variant 1: With begin_module/end_module.

Jekejeke Prolog 2, Runtime Library 1.2.7
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

?- [user].
:- begin_module(database).
likes(anna,hans).
likes(hans,carol).
:- end_module.

?- likes(X,Y).
Error: Undefined or inaccesible predicate likes/2.
likes/2
?- database:likes(X,Y).
X = anna,
Y = hans ;
X = hans,
Y = carol

Variant 2: With qualified clause heads:

Jekejeke Prolog 2, Runtime Library 1.2.7
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

?- [user].
database:likes(anna,hans).
database:likes(hans,carol).

Yes
?- likes(anna,hans).
Error: Undefined or inaccesible predicate likes/2.
likes/2

?- database:likes(X,Y).
X = anna,
Y = hans ;
X = hans,
Y = carol

But if you don't use the toplevel, and put
clauses in files. There are the directives from
SWI-Prolog, to say what is the module name,
to say, what is imported, and to say what is

exported. The term **directive** is to be
understood as in the Prolog core standard.

ken...@gmail.com

unread,
Jun 25, 2018, 6:25:10 AM6/25/18
to
Thank you for your early reply.

I will read the ISO-Prolog module standards carefully.

Kenichi Sasagawa


burs...@gmail.com

unread,
Jun 25, 2018, 6:27:14 AM6/25/18
to
Variant 2 works the same in SWI-Prolog. There is
a small interference by the autocorrect. But it
basically does the same:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.1)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- [user].
database:likes(anna,hans).
|: database:likes(hans,carol).
|:
true.

?- likes(anna,hans).
Correct to: "database:likes(anna,hans)"? no
ERROR: Undefined procedure: likes/2
ERROR: In:
ERROR: [8] likes(anna,hans)
ERROR: [7] <user>
Exception: (8) likes(anna, hans) ? abort
% Execution Aborted
?- database:likes(X,Y).
X = anna,
Y = hans
X = hans,
Y = carol.

burs...@gmail.com

unread,
Jun 25, 2018, 6:57:13 AM6/25/18
to
Tau Prolog has already use_module/1, but I don't
know how far they otherwise implement modules.

There is a complication when one provides a
web sandbox, maybe or maybe not, some features

are not permitted. I don't know, here is a new issue:
https://github.com/jariazavalverde/tau-prolog/issues/27

j4n bur53

unread,
Jun 25, 2018, 7:08:17 AM6/25/18
to
Nested modules also work on the fly:

Variant 2: Qualified (:)/2 Clause Head and Structured (/)/2 Module Name
/* You don't find structured (/) module
name in the ISO module standard */

Jekejeke Prolog 3, Runtime Library 1.3.0
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

?- [user].
galaxy/solarsystem/database:likes(hans,anna).
galaxy/solarsystem/database:likes(anna,fred).

Yes
?- likes(X,Y).
Error: Undefined or inaccesible predicate likes/2.
likes/2

?- database:likes(X,Y).
Error: Undefined or inaccesible predicate database:likes/2.
database:likes/2

?- galaxy/solarsystem/database:likes(X,Y).
X = hans,
Y = anna ;
X = anna,
Y = fred

Variant 1: With begin_module/1 and end_module/0.

Jekejeke Prolog 3, Runtime Library 1.3.0
(c) 1985-2018, XLOG Technologies GmbH, Switzerland

?- [user].
:- begin_module(galaxy).
:- begin_module(solarsystem).
:- begin_module(database).
likes(hans,anna).
likes(anna,fred).
:- end_module.
:- end_module.
:- end_module.

Yes

?- likes(X,Y).
Error: Undefined or inaccesible predicate likes/2.
likes/2

?- database:likes(X,Y).
Error: Undefined or inaccesible predicate database:likes/2.
database:likes/2

?- galaxy/solarsystem/database:likes(X,Y).
X = hans,
Y = anna ;
X = anna,
Y = fred

burs...@gmail.com schrieb:

burs...@gmail.com

unread,
Jun 25, 2018, 2:30:08 PM6/25/18
to
Tabling can make the Ackermann Function much faster.
What is tabling. See for yourself:

7.4 Tabling predicate reference
http://www.swi-prolog.org/pldoc/man?section=tabling-preds

How much faster will it be? Here is the same
ack(3,10,X) example run with tableing. Just a table
directive before the first clause of the program:

Welcome to SWI-Prolog (threaded, 64 bits, version 7.7.16)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.

?- time(ack(3,10,X)).
% 684,209 inferences, 0.125 CPU in 0.125 seconds (100% CPU, 5473672 Lips)
X = 8189.

burs...@gmail.com

unread,
Jun 26, 2018, 10:23:49 AM6/26/18
to
Ha Ha

For years I used to use 1989^1989 as my test
computation when I tried Mathematica on a
new machine. And in 1989 I would usually be
counting the seconds waiting for the computation
to be finished. (1988^1988 was usually too
slow to be useful back in 1988: it could take
minutes to return.) Today, of course, the same
computation is instantaneous. (Actually, a few
years ago, I did the computation again on the
first Raspberry Pi computer—and it again took
several seconds. But that was a $25 computer.
And now even it runs the computation very fast.)
http://blog.wolfram.com/2018/06/21/weve-come-a-long-way-in-30-years-but-you-havent-seen-anything-yet/

Did not yet try it on wolfram alpha, so that I am sure
that it computes 9^(9^9) and nothing else. But I guess
its time to switch to 9^(9^9) as a test case... :-)

BTW: Somebody told me how to do it on yacas, so that it
doesn't show the result. But not yet time to try it,
I on the wrong machine right now.

Even on the slow machine I am on, this is not anything
physiologically noticable anymore:

?- time(_ is 1989^1989).
% 2 inferences, 0.000 CPU in 0.004 seconds (6% CPU, 8696 Lips)
true.

burs...@gmail.com

unread,
Jun 26, 2018, 2:11:37 PM6/26/18
to
Over the last days, I saw some JavaScript bignum
implementations, when I researched 9^(9^9), there
are like 10-20 different implementations around.

Anyway here is competition for Tau Prolog:
http://demos.rlaanemets.com/swi-prolog-wasm/example/

But no bignums yet, :-(, I only get:

between(21,29,X), Y is X^X, write(Y), nl, fail; true.
5.842587018385982e+27
3.4142787736421956e+29
2.088046799984791e+31
1.333735776850284e+33
8.881784197001253e+34
6.156119580207158e+36
4.434264882430377e+38
3.3145523113253375e+40
2.567686153161211e+42
true.


Y is 29^29-2567686153161211134561828214731016126483469.

Y = -3.094850098213451e+26.

https://twitter.com/janburse/status/1011672477687320578

burs...@gmail.com

unread,
Jun 29, 2018, 11:24:57 AM6/29/18
to
How do I use lib(ic) together with -L iso option?
I was trying to redo some benchmarks from the
yesr 2016 which I did wrote for the old ECLiPSe.

With the new ELCiPSe I get the following errors:

Ambiguous import of > / 2 from [iso, ic] in module eclipse
Ambiguous import of > / 2 from [iso, ic] in module eclipse
Ambiguous import of > / 2 from [iso, ic] in module eclipse

[eclipse 2]: suite4, suite4.
procedure does not exist: > / 2 in eclipse
Abort

Am Sonntag, 24. Juni 2018 15:36:24 UTC+2 schrieb Joachim Schimpf:
> On 24/06/18 11:24, burs...@gmail.com wrote:
> >
> > I will try to use the "-L iso" option in the
> > future. Its a little tricky to use on Windows,
> > in case one wants to modify DosEclipse.lnk:
> >
> > https://superuser.com/questions/29569/how-to-add-command-line-options-to-shortcut
>
> Alternatively, you can
>
> - set an environment variable ECLIPSEDEFAULTLANGUAGE to iso or iso_strict
>
> - or make an ECLIPSEDEFAULTLANGUAGE string-valued registry entry under
> HKLM/SOFTWARE/IC-Parc/Eclipse/7.0 and set it to iso or iso_strict
>
> - or create a new module that uses the desired language dialect, and
> make that the toplevel-module:
>
> ?- create_module(iso_test, [], iso).
> ?- set_flag(toplevel_module, iso_test).
>
> [interactively, or put it into an .eclipserc file under $HOME/$HOMEPATH]
>
>
> Cheers,
> -- Joachim

burs...@gmail.com

unread,
Jun 29, 2018, 11:50:36 AM6/29/18
to
Current workaround, run it without "-L iso".

burs...@gmail.com

unread,
Jul 12, 2018, 11:13:07 AM7/12/18
to
Does ECLiPSe Prolog have an epsilon evaluable
functions? Here are some nice test cases:

Did I get the right epsilon?

?- 1+epsilon =:= 1.
false.

?- 1+epsilon/2 =:= 1.
true.

Does my FPU do half even rounding?

?- 1+epsilon+epsilon/2 =:= 1+epsilon.
false.

?- 1+2*epsilon+epsilon/2 =:= 1+2*epsilon.
true.

?- 1+3*epsilon+epsilon/2 =:= 1+3*epsilon.
false.

?- 1+4*epsilon+epsilon/2 =:= 1+4*epsilon.
true.

Its from here:
https://www.complang.tuwien.ac.at/ulrich/iso-prolog/N208

But N208 didn't have test cases... :-( :-)
0 new messages