On Thu, Mar 19, 2015 at 9:40 AM, Marc Mezzarobba <[email protected]> wrote: > William Stein wrote: >> sage: a = RIF(1/5) >> sage: a == a >> False >> sage: a is a >> True > > That's how interval arithmetic usually works! Quoting from the > documentation of real_mpfi: > > | Comparison operations (``==``, ``!=``, ``<``, ``<=``, ``>``, ``>=``) > | return ``True`` if every value in the first interval has the given > | relation to every value in the second interval. > | [...] > | This convention for comparison operators has good and bad points. > | [...]
OK, fair point. I guess the idea is that one thinks of an element of RIF not as an interval, but as "some unspecified element of an interval". It should be called "unspecified element of an interval arithmetic"... It says:'Comparison operations (``==``, ``!=``, ``<``, ``<=``, ``>``, ``>=``) return ``True`` if every value in the first interval has the given relation to every value in the second interval. The ``cmp(a, b)`` function works differently; it compares two intervals lexicographically. (However, the behavior is not specified if given a non-interval and an interval.)' Is there a proposal to leverage the remark " (However, the behavior is not specified if given a non-interval and an interval.)", and change the behavior of sage: RIF(1/5) == 1/5 Right now I'm guessing the above comparison is done by first coercing 1/5 to RIF, then comparing, which is False. Anyway, you've convinced me that "1/5 in RIF" shouldn't be true, since there is no element of RIF that is equal to 1/5. Due to things being base 2 in computers, there's a funny thing in RIF that is a little interval around 1/5. But it's definitely not equal to 1/5. In contrast, 1/2 is in RIF, since it can be represented exactly there. In any case, I am against "a in X" being true if there is no element b of X such that a==b is true. One motivation for this the Python reference manual which says that the fallback for __contains__ is: "For user-defined classes which do not define __contains__() but do define __iter__(), x in y is true if some value z with x == z is produced while iterating over y. If an exception is raised during the iteration, it is as if in raised that exception." [1] [1] https://docs.python.org/2/reference/expressions.html#membership-test-details William > >> However, >> >> sage: a.lower() == a.lower() >> True >> sage: a.upper() == a.upper() >> True >> >> The code to compare intervals is here: >> >> > https://github.com/sagemath/sage/blob/master/src/sage/rings/real_mpfi.pyx#L3517 >> >> It looks like it just compares the endpoints, so I don't understand >> why a == a is false... > > That's because you are looking at the wrong function; intervals also > implement richcmp. > > -- > Marc > > -- > You received this message because you are subscribed to the Google Groups > "sage-devel" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sage-devel. > For more options, visit https://groups.google.com/d/optout. -- William (http://wstein.org) -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
