Deep comparison of dicts - cmp() versus ==?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Fri Mar 20 02:35:42 EDT 2015
On Friday 20 March 2015 14:47, Rustom Mody wrote:
> On Friday, March 20, 2015 at 9:05:19 AM UTC+5:30, Chris Angelico wrote:
>> On Fri, Mar 20, 2015 at 2:27 PM, Rustom Mody wrote:
>> > Numbers (not complex) satisfy the trichotomy law: ie for any 2 numbers
>> > x,y: x < y or x > y o x = y
>>
>> Real numbers, yes, and integers in most computer representations, but
>> not IEEE floating point. Be careful of that distinction; we're talking
>> about computers here, not mythical numbers.
>
> A putative set that claims to be some-kind-of-numbers and has an element
> that is Not-A-Number looks more mythical/mystical/Zen-ish than classical
> math numbers.
Forget NANs. The trichotomy of floating point values was violated before the
IEEE-754 standard was invented. In fact, IEEE-754 was invented in order to
bring some semblance of order to the unspeakable mess of floating point
arithmetic prior to that. With IEEE-754 floats, at least you can guarantee
that the trichotomy applies to all values apart from NANs.
I cannot remember the details, and I don't have my copy of the Apple
Standard Numerics manual here to look it up, but in the 1970s there was
hardware where the following could fail with Divide By Zero error for
certain values of x:
if x > 0.0:
print 1/x # Divide By Zero here
If you find that hard to believe, it's because you're spoiled by the
astonishing success of IEEE-754 floating point arithmetic.
> IOW: float is a poor approximation to ℝ.
True, but not because of NANs.
Even *finite* floats violate some of the usual properties of Real numbers:
# Associativity
py> 0.1 + (0.2 + 0.3) == (0.1 + 0.2) + 0.3
False
# Distributivity
py> 1.3*(0.3+0.4) == 1.3*0.3 + 1.3*0.4
False
[Aside: why is my spell checker flagging plus signs as misspelled words?]
And then there's the whole thing where there is an uncountable infinity[1]
of Real numbers, and only a finite number of floats.
> Not too many people are interested in float independent of ℝ except
> perhaps hardware designers who need to design respecting the IEEE
> standard.
I don't understand what you are trying to say here.
[1] Uncountable infinity doesn't just mean that you cannot count them all
because there's an infinite number of them. It means that you cannot
enumerate them all, even in an infinite amount of time.
http://en.wikipedia.org/wiki/Cantor%27s_diagonal_argument
--
Steve
More information about the Python-list
mailing list