I just noticed that in mpmath, we have
In [260]: mpf('nan') == mpf('nan')
Out[260]: False
This is because of the code (in libmpf.py):
def mpf_eq(s, t):
"""Test equality of two raw mpfs. This is simply tuple comparion
unless either number is nan, in which case the result is False."""
if not s[1] or not t[1]:
if s == fnan or t == fnan:
return False
return s == t
Is this intentional, or just an overlooked side effect of making
nothing compare equal to nan?
This is causing problems in SymPy, where we are having to use a
workaround (testing Float._mpf_ == fnan) to make our infinities play
nicely with the Float wrappers of mpmath infinites. See
https://github.com/sympy/sympy/pull/789.
P.S. there is apparently a typo in the docstring of mpf_eq.
"comparion" should be "comparison".
Aaron Meurer
It's intended for compatibility with floats. I was never a fan of this
convention, but I would rather not change it at this point.
> P.S. there is apparently a typo in the docstring of mpf_eq.
> "comparion" should be "comparison".
Thanks, fixed!
Fredrik
I see. This was actually pointed out to me after I wrote this email.
Any idea why they did that?
So how would you recommend that we do things with Float in SymPy. We
can either keep it like it is, but add some kind of way to tell if
it's nan. Right now, we are testing Float._mpf_ against fnan from
mpmath.libmp.libmpf which is not very stable, and also not very
user-friendly. So we would add some kind of .is_nan property. Or, we
can break this convention, and have Float('nan') == Float('nan') be
True.
There's also the question of how this should behave with SymPy's S.NaN
if we choose the first option. Right now, we have S.NaN == S.NaN is
True (indeed, S.NaN is S.NaN is True, since it's singletonized).
Should we have S.NaN == Float('nan') be True (assuming we choose the
first option; obviously it would be if we choose the second one)? And
how about float('nan') == Float('nan') or float('nan') == S.NaN?
I've also added the SymPy list to this discussion, since this is more
of a problem there than here, though I am interested in your opinion,
as you know more about these floating point things than I do (and
probably most people on the SymPy list).
Aaron Meurer
>
>> P.S. there is apparently a typo in the docstring of mpf_eq.
>> "comparion" should be "comparison".
>
> Thanks, fixed!
>
> Fredrik
>
> --
> You received this message because you are subscribed to the Google Groups "mpmath" group.
> To post to this group, send email to mpm...@googlegroups.com.
> To unsubscribe from this group, send email to mpmath+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mpmath?hl=en.
>