AltME: REBOL3

Messages

Ladislav
Hi all! I wrote a https://github.com/rebol/rebol-issues/issues/2259 ticket explaining why EQUAL? should be transitive. I always thought that EQUAL? should be transitive, but these arguments may convince people who did not know them until now. Anybody wanting to discuss it?
The essence is as follows: ordering has to be transitive, otherwise you cannot obtain reasonable sorting results. Moreover, EQUAL? has to be a conjunction of two orderings: LESSER-OR-EQUAL? and GREATER-OR-EQUAL?, which, since both must be transitive, yields that EQUAL? must be transitive too.
Gregg
Your examples are clear and compelling Ladislav. Not sure how I'd argue with them, so I won't. :-)

Ladislav
So, do you think that the reasons to make EQUAL? transitive are compelling?
Gregg
Yes.
Robert
+1

Endo
+1
PeterWood
The arguments for making Equal? transitive are compelling Ladislav. Would there be any noticeable change from the current Equal? behaviour if it was implemented?
Perhaps it would be better to ask, what (if any) change would there be in the behaviour in Equal? if a transitive version was implemented?
Ladislav
Yes, that is a perfect question.
DideC
I see the point is about decimals, but other bugs relate to word! comparison.
Does this 2 points must be threaded separatly or not ?
Ladislav
To answer Peter's question: Currently, EQUAL? is not only nontransitive for decimals, it is also "approximate" in that different numbers (differing by 10 ULP or less) are considered equal. For example, 0.1 + 0.1 + 0.1 (to binary! 0.1 + 0.1 + 0.1; == #{3FD3333333333334}) differs from 0.3 (to binary! 0.3 ; == #{3FD3333333333333}) by exactly 1 ULP (unit in in the last place), as can be seen from the binary representation.
EQUAL? 0.1 + 0.1 + 0.1 0.3 yields TRUE
Ladislav
..., while the number representing 0.1 + 0.1 + 0.1 is exactly by 1 ULP greater than the number representing 0.3, and greater-or-equal? 0.1 + 0.1 + 0.1 yields TRUE, while lesser-or-equal? 0.1 + 0.1 + 0.1 0.3 yields FALSE
If we defined EQUAL? to be equivalent to the conjunction of LESSER-OR-EQUAL? and GREATER-OR-EQUAL? (which we should to be consistent), while retatining both the definition of LESSER-OR-EQUAL? and GREATER-OR-EQUAL? we would obtain that 0.1 + 0.1 + 0.1 has to be unequal to 0.3 (actually greater than 0.3).
DideC - no, I used word comparison only as an illustration why nontransitive relations cannot be used as orders for sorting. Otherwise, word! is a separate datatype, and the issue with word ordering should be resolved separately.
Ladislav
Using present definitions of LESSER-OR-EQUAL? and GREATER-OR-EQUAL? for decimals, and defining EQUAL? as their conjuction, we would obtain a transitive equality, but it would not be approximate.
It turns out that we *can* define a transitive approximate equality, but we cannot do it so that it will be always "tolerant".
The way how to do it is to define some subset of decimals and some rounding, and say that two decimals are approximately equal if they round to the same value. This is guaranteed to be both approximate as well as transitive.
Ladislav
The only problem is that it is not always "tolerant" in the sense that can be illustrated by an example: let's use rounding to the nearest integer, then the numbers greater than 0.0 and smaller than 0.5 round to 0.0, while numbers greater or equal to 0.5 and smaller than 1.5 round to 1.0. This is a transitive relation that is quite tolerant, but it is not always tolerant, since the numbers 0.49999999999999994 and 0.5 round to 0.0 and 1.0 respectively, and are not nearly equal, although they differ only by one ULP.
Ladislav
Our consolation is that this happens only exceptionally, on the "boundary" between successive rounding areas.

Last message posted 164 weeks ago.