Hi guys! This is my first post to this list.
I'm not really learning Prolog at the moment but I started to compare how
different programming languages treat the following floating point comparison
case:
a=1
b=1/(1-epsilon)
(a==b) == (b==a)
That's basic a test to check if the equality operator ('==') is commutative.
I found it really hard to implement that simple test in Prolog. I've read a lot
of stuff and the only thing I've found to work (AFAIK) was the following:
%works in GNU Prolog 1.4.0
(http://www.compileonline.com/execute_prolog_online.php)
:- initialization(main).
equal(X,Y,Z) :- (X=:=Y -> Z=true; Z=false).
commutative(X,Y,Z) :- ((equal(X,Y,W), equal(Y,X,W)) -> Z=true; Z=false).
main :- A = 1,
B = 1/(1-2.220446049250313e-16),
commutative(A,B,T),
write(T).
%output: true
That seems to be very verbose and inefficient solution.
How can I do it simpler? Is it possible to make it faster?
_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog