[comp.lang.prolog] Sicstus Prolog Questions

ranga@uceng.UC.EDU (Dr. Ranga R. Vemuri) (07/22/90)

(1)
I am using Sicstus0.6 prolog to write a program with a LOT of
floating-point operations.  I am having problems in getting
the program perform these floating point operations correctly.
It seems that, after performing a few thousand operations,
the floating point results start overflowing or underflowing.

For example,  here is a simple psuedo random number generator.
IX is the seed.  This produced about 700 to 800 random numbers correctly 
(I checked them through other means) and then started giving out 0's;
The reason, I found through tracing, invariably was an underflow/overlow.
At that point, the prolog system wouldn't do even simple arithmetic 
properly: for eg, `A is 1/6' produces `A = 4.32583271660369e-308' !!!


random(IX, NewIX, Rand):-
        A     is   16807,
        B15   is   32768,
        B16   is   65536,
        P     is   2147483647,
        XHI is IX//B16,
        XALO is (IX-(XHI*B16))*A,
        LEFTLO is XALO//B16,
        FHI is (XHI*A) + LEFTLO,
        K is FHI//B15,
        ModifiedIX is ( ((XALO-(LEFTLO*B16))-P) + (FHI-(K*B15))*B16) + K,
        ((ModifiedIX < 0, NewIX is ModifiedIX + P); NewIX is ModifiedIX),
        Rand is NewIX*4.656612875e-10.


Any suggestions on how I can try and get of out this problem will be
greatly appreciated.

(2)
As one way of avoiding the above problem, I have tried to implementing
my floating point routines in C and tried to interface them using
the foreign language interface feature of Sisctus.  I couldn't get
that working either.  'load_foreign_files' gives me either
an 'illegal usage' message or says 'myCfile.o undefined'.
'foreign' and 'foreign_file' also give 'illegal usage' messages.
The Sictus0.6 documet I have seems to imply, however, that this feature is
fully implemented....

Any help here is appreciated too......

(3)
Is there a free-of-charge (ftp'able ??) or commercial prolog
which is known to be good in handling both floating point arithmetic 
and foreign function interface ??


Thanks.

- Ranga
  ranga@uceng.uc.edu
_________
Ranga Vemuri                                     ranga@uceng.uc.edu
Laboratory for Digital Design Environments           (513)-556-4784
M.L. 30, Dept. Electrical & Computer Engineering     (513)-556-4769  
University of Cincinnati, Cincinnati, OH 45221, USA
 

roland@sics.se (Roland Karlsson) (07/24/90)

> For example,  here is a simple psuedo random number generator.
> IX is the seed.  This produced about 700 to 800 random numbers correctly 
> (I checked them through other means) and then started giving out 0's;
> The reason, I found through tracing, invariably was an underflow/overlow.
> At that point, the prolog system wouldn't do even simple arithmetic 
> properly: for eg, `A is 1/6' produces `A = 4.32583271660369e-308' !!!

Yes there have been some bugs in previous versions of number crunching.
This bug is no more.  By the way, SICStus no longer use table lookup
for numbers.  Numbers are stored on the heap.

> As one way of avoiding the above problem, I have tried to implementing
> my floating point routines in C and tried to interface them using
> the foreign language interface feature of Sisctus.  I couldn't get
> that working either.  'load_foreign_files' gives me either
> an 'illegal usage' message or says 'myCfile.o undefined'.
> 'foreign' and 'foreign_file' also give 'illegal usage' messages.

As I not have seen your code it is impossible to tell why the
foreign_interface do not work.  It works for me.  Maybe you have an old
version of SICStus or maybe you are doing something wrong.

Current version is:
SICStus 0.6 #18: Wed Jul 11 20:00:53 MET DST 1990


Roland Karlsson

PS. The best way to get answers concerning SICStus Prolog is to write
    to matsc@sics.se (Mats Carlsson).  He is on vacation but will be back
    in a couple of weeks.  He always answers promptly and is more than
    glad to know about bugs (:-).
DS.
--
Roland Karlsson
SICS, PO Box 1263, S-164 28 KISTA, SWEDEN	Internet: roland@sics.se
Tel: +46 8 752 15 40	Ttx: 812 61 54 SICS S	Fax: +46 8 751 72 30