[comp.lang.prolog] Integer/floating point type conversion in Prolog

holmer@ji.Berkeley.EDU (Bruce K. Holmer) (11/17/87)

[]
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.

	% What about round-off errors?
	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'.

Thanks for your comments,
Bruce