didoudiaz / gprolog

GNU Prolog
Other
106 stars 13 forks source link

(is)/2 issue hardly worth mentioning #51

Closed flexoron closed 1 year ago

flexoron commented 1 year ago

SWI, ECLiPSe
?- X is -0.0 * -0.0.
X = 0.0.
?- -0.0 is -0.0 * -0.0.
false.

%%%

GNU
| ?- X is -0.0 * -0.0.
X = 0.0
yes
| ?- -0.0 is -0.0 * -0.0.
yes  % I would say no.
didoudiaz commented 1 year ago

What is the result of the unification -0.0 = 0.0 ? true or false ? As you mentioned, In the "false" camp, we find SWI, ECLiPSe but also Ciao. On the "true" camp we find: gprolog, Yap, Trealla, Scryer (both lists are not exhaustvie). So both semantics exist (and I'm sure can be hardly justified). gprolog is based on C's floating-point arithmetic, which evaluates -0.0 == 0.0 to true (-0.0 * -0.0 == 0.0 is true also).

flexoron commented 1 year ago
The "false" camp is not that good for calculating results, too.
?- -0.0 =:= -0.0 * -0.0.
true. % ???

Arithmetic first:
Both cases, (is)/2 and (=:=)/2, should not miscalculate indicators of numbers
and if a system allows these numbers (-0.0, 0.0, +0.0) then calculation rules are relevant.

(is)/2 calculates and then unifies but why unification?
I thought that (is)/2 is a kind of assignment introduced for executing arithmetic (machine-oriented ops) only.
Looking at (=:=)/2 I get:

SWI, ECLiPSe
?- sort([+0.0, 0.0, -0.0],S).
S = [-0.0, 0.0].

GNU
| ?- sort([+0.0, 0.0, -0.0],S).   
S = [0.0,+0.0]

Result:
?- [-0.0, 0.0] = [0.0,+0.0].
defect.

And if you do ignore -0
| ?- sort([-0,0],S).
S = [0]
then +1 should be ignored as well
| ?- sort([+1,1],S).
S = [1,+1] % unexpected, expecting [1].
didoudiaz commented 1 year ago

(is)/2 calculates and then unifies but why unification? I thought that (is)/2 is a kind of assignment introduced for executing arithmetic (machine-oriented ops) only.

is/2 is not an assignment (as in imperative languages). It simply evaluates its right-expression and unifies it with its left-term (this is similar to >/2 which evaluates both expressions and then compares their result).

While -123 is a negative number, +123 is not a positive number, it is a compound term whose principal functor is +/1. There is a misunderstanding with + followed by a number. This is not a number but a compound term. +1 and whose argument is 123. Try:

| ?- number(-123).
yes
| ?- number(+123).
no
| ?- +123 = +(X).
X = 123
yes

In the standard ordering of terms, atomic terms (numbers are atomic) come before compound terms. Hence the results of your experiments with sort/2.

flexoron commented 1 year ago

Yes, I know. I'm just wondering why +1 is not a number (and is a number).

SWI, ECLiPSe:

?- number(+1).
true.

Ok then. Thanks for telling me your way of looking at arithmetic, numbers, algebraic signs. (Note: I didn't say that is/2 is an assignment but a kind of assignment(an androgyne so to speak).

didoudiaz commented 1 year ago

SWI Prolog follows ISO on this (tested under version 9.1.11):

?- number(+1).
false.
flexoron commented 1 year ago

Ah ok, thanks, sorry, have v8.4.0 only and from now on I do not use SWI (for comparsion) again.