Integer/floating point type conversion in Prolog
Author Message
Integer/floating point type conversion in Prolog

[]
In your opinion, what is the proper behavior of the following code fragments?

% Is type conversion is done before test?
main1 :- a(1.0, 1).
a(X, Y) :- X == Y, write(a), fail.
a(X, Y) :- X = Y, write(b), fail.
a(X, Y) :- X =:= Y, write(c), fail.

main2 :- X is (2.0/7.0)*7.0, Z is X - 2.0, write(Z), b(X, 2.0).
b(X, Y) :- X == Y, write(a), fail.
b(X, Y) :- X = Y, write(b), fail.
b(X, Y) :- X =:= Y, write(c), fail.

To save you the work, here are the results for prologs we use:

C-Prolog (version 1.5)
main1:  abc
main2:  0abc
Quintus (VAX version 1.6 interpreted):
main1:  c
main2:  -1.9073e-06
Quintus (VAX version 1.6 compiled):
main1:  c
main2:  0.0abc
SB-Prolog (version 2.2 compiled)
main1:  bc
main2:  -0.000000b

As you can see, no one can agree on what the correct answers are!

So should type conversion be done before =/2 or ==/2?
Quintus says no, C-Prolog says yes, and SB-Prolog is in between.

Concerning round-off errors, Quintus compiled code probably
computes multi-operation expressions with full precision (and rounds
the answer), whereas execution time floating point is 29-bit for all
operations.  My opinion is that a program should produce identical
results, regardless of whether it is interpreted or compiled.
SB-Prolog uses an 'EPSILON' during unification to do a 'prettymuch_equal',
but I would think that anything that is '=/2' should also be '=:=/2'.

Bruce

Mon, 19 Apr 1993 21:43:00 GMT
Integer/floating point type conversion in Prolog
We are developing a quasi expert system to make a conceptual design
of a spacecraft. This involves a lot of data and rules at the
spacecraft mission level and at the subsystem(acs,power,comm,etc.)
level. We will also be keeping track of 'historical' info on spacecraft

The system is being written in Quintus Prolog, which is relatively new to
me. Is there some way to segment the data bases so that there are fewer
facts for the 'matcher' to plough through till it finds the appropriate
data?  I have been considering separating the data into different files
and only loading in what is needed to do the inferencing & calculations,
& then deleting it -- if I can figure out when to do that & hope the
overhead is less than the search time when all that info is in the
database at once.

I've implemented Sterling & Shapiro's symbolic equation solver with some
enhancements, but it is fairly slow on the substitution part. (By the way,
I recommend The Art of Prolog. It's been very useful.) I'm assuming that
is because there's so much data associated with each spacecraft, and for
simplicities sake I'm using the same format for most of the data. This
allows many routines to be used in many different situations, but there is
all that data!

Thanks for any help on this.

April Gillam

Aerospace Corp.

Mon, 19 Apr 1993 09:44:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages