Message from discussion
checking for identity before comparing built-in objects
Received: by 10.181.11.234 with SMTP id el10mr123929wid.2.1349756228279;
Mon, 08 Oct 2012 21:17:08 -0700 (PDT)
X-BeenThere: python-ideas@googlegroups.com
Received: by 10.181.12.12 with SMTP id em12ls8789639wid.2.gmail; Mon, 08 Oct
2012 21:17:08 -0700 (PDT)
Received: by 10.216.211.101 with SMTP id v79mr533043weo.9.1349756228233;
Mon, 08 Oct 2012 21:17:08 -0700 (PDT)
Received: by 10.216.211.101 with SMTP id v79mr533042weo.9.1349756228209;
Mon, 08 Oct 2012 21:17:08 -0700 (PDT)
Return-Path: <python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org>
Received: from mail.python.org (mail.python.org. [2001:888:2000:d::a6])
by gmr-mx.google.com with ESMTPS id e5si1167849wiw.0.2012.10.08.21.17.08
(version=TLSv1/SSLv3 cipher=OTHER);
Mon, 08 Oct 2012 21:17:08 -0700 (PDT)
Received-SPF: pass (google.com: domain of python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org designates 2001:888:2000:d::a6 as permitted sender) client-ip=2001:888:2000:d::a6;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org designates 2001:888:2000:d::a6 as permitted sender) smtp.mail=python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org; dkim=pass header...@python.org
Received: from albatross.python.org (localhost [127.0.0.1])
by mail.python.org (Postfix) with ESMTP id 3XbQBW6m3SzQtp
for <python-ideas-garchive-35620@googlegroups.com>; Tue, 9 Oct 2012 06:17:07 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901;
t=1349756227; bh=Qp5mKTvJrri6D7n4SMtZVP9OFi9fgEAdbBUWwKycSuA=;
h=Date:From:To:Message-ID:References:Mime-Version:In-Reply-To:
Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:
List-Subscribe:Content-Type:Content-Transfer-Encoding:Sender;
b=RB3IlxPDDpDJ/kb0LhMr61lRX/c6C6djuE9xcWVM8BsolK4x7KjRKV2em0osuFVIY
JGsTFyKytY2v/mid52H7UQnMCScG1rX/Qdlr0uViaFfsGE+G8iIvP17YpNXu6yP5S6
7qgZUkYx2L0zhSdHwNPSeMEdeN6FVBfGVdRUckyY=
X-Original-To: python-id...@python.org
Delivered-To: python-id...@mail.python.org
Received: from albatross.python.org (localhost [127.0.0.1])
by mail.python.org (Postfix) with ESMTP id 3XbQ9g2WG1zP5R
for <python-id...@python.org>; Tue, 9 Oct 2012 06:16:23 +0200 (CEST)
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03;
'value,': 0.03; 'patterns': 0.04; 'subject:Python': 0.05;
'result,': 0.05; '-1,': 0.09; '754': 0.09; 'collections': 0.09;
'finite': 0.09; 'sentence': 0.09; 'subclass': 0.09; 'tuple': 0.09;
':-)': 0.13; 'represents': 0.15; '"unknown': 0.16; '"well,': 0.16;
'did,': 0.16; 'equal.': 0.16; 'fine.': 0.16; 'from:addr:steve':
0.16; 'language:': 0.16; 'nan': 0.16; 'nans': 0.16; 'oct': 0.16;
'presume': 0.16; 'received:adl2.internode.on.net': 0.16;
'received:internode.on.net': 0.16;
'received:lns20.mel4.internode.on.net': 0.16;
'received:mel4.internode.on.net': 0.16; 'received:on.net': 0.16;
'result"': 0.16; 'subject:ideas': 0.16; 'url:drdobbs': 0.16;
'wrote:': 0.17; 'certainly': 0.17; 'mathematical': 0.17;
"shouldn't": 0.17; 'tests': 0.18; 'subject:] ': 0.19; '(not':
0.20; 'bit': 0.21; 'all:': 0.22; 'help.': 0.22; "i've": 0.23;
'idea': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1':
0.26; 'guess': 0.27; "doesn't": 0.28; 'represent': 0.28; '"in':
0.29; '"no': 0.29; 'accordance': 0.29; 'behaviour': 0.29;
'equality': 0.29; 'steven': 0.29; 'probably': 0.29; "we're": 0.30;
'expect': 0.31; 'could': 0.32; 'anywhere': 0.33; 'equal': 0.33;
'another': 0.33; "can't": 0.34; 'awesome': 0.35; 'exist': 0.35;
'identity': 0.35; 'something': 0.35; 'there': 0.35; 'but': 0.36;
'charset:us-ascii': 0.36; 'enough': 0.36; 'two': 0.37; 'quite':
0.37; 'mean': 0.38; 'object': 0.38; 'speak': 0.38;
'to:addr:python.org': 0.39; 'called': 0.39; 'subject:-': 0.40;
'think': 0.40; 'content-disposition:inline': 0.60; 'safe': 0.63;
'different': 0.63; 'great': 0.64; 'choose': 0.65; 'talking': 0.66;
'to:addr:python-ideas': 0.69; 'stated': 0.69; 'square': 0.75;
'5.4': 0.84; 'batchelder': 0.84; 'respect.': 0.84;
'subject:before': 0.84; 'received:118': 0.93
Received: from localhost (HELO mail.python.org) (127.0.0.1)
by albatross.python.org with SMTP; 09 Oct 2012 06:16:23 +0200
Received: from ipmail07.adl2.internode.on.net (ipmail07.adl2.internode.on.net
[IPv6:2001:44b8:8060:ff02:300:1:2:7])
by mail.python.org (Postfix) with ESMTP
for <python-id...@python.org>; Tue, 9 Oct 2012 06:16:21 +0200 (CEST)
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: AtlLALSjc1B20Vii/2dsb2JhbAA8CYUoq0OIVIV0gQmCIAEBBAE6HCgLCzQSFBgNiDYFDKo3gnCNOYtHEYJhgyEDjT+IK4VXiliDAQ
Received: from ppp118-209-88-162.lns20.mel4.internode.on.net (HELO
pearwood.info) ([118.209.88.162])
by ipmail07.adl2.internode.on.net with ESMTP; 09 Oct 2012 14:46:20 +1030
Received: by pearwood.info (Postfix, from userid 1000)
id 1760112071F; Tue, 9 Oct 2012 15:16:16 +1100 (EST)
Date: Tue, 9 Oct 2012 15:16:16 +1100
From: Steven D'Aprano <st...@pearwood.info>
To: python-id...@python.org
Message-ID: <20121009041613.GG27445@ando>
References: <CAOVPiMhnBezrw3gusD1QmW8MawV1HDCQHiTbd2Z0_T1TLDa...@mail.gmail.com>
<506D94EE.30...@pearwood.info>
<CAP7h-xZBg-MbWtmWFSQ4HmSPjCO_+Av_f-ip6hrH8WBSPJv...@mail.gmail.com>
<CAPTjJmrRENuYXMOjPzobY1Hjkr+Vmqq04Z4_JOr6=DCdP4-...@mail.gmail.com>
<CAP7h-xb4WvNuDGayqe60GRGmV4Nk-nzcN1d=HLahHw-hkG7...@mail.gmail.com>
<CAP7+vJ+G-0WXZRTgr5Y=T+OdaMWmGzgk1--UH8=zoBGLsia...@mail.gmail.com>
<CAP7h-xaV3RaA2EW4+vWuU=L=2JjhnKBGqhHPhgnmf4VbgGm...@mail.gmail.com>
<CAP7+vJLt_WNzS75S25kMgPjFMiKz5DFCj5V69ZeyiWsYs5A...@mail.gmail.com>
<50723BE5.3060...@nedbatchelder.com>
Mime-Version: 1.0
Content-Disposition: inline
In-Reply-To: <50723BE5.3060...@nedbatchelder.com>
User-Agent: Mutt/1.4.2.2i
Subject: Re: [Python-ideas] checking for identity before comparing built-in
objects
X-BeenThere: python-id...@python.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: Discussions of speculative Python language ideas
<python-ideas.python.org>
List-Unsubscribe: <http://mail.python.org/mailman/options/python-ideas>,
<mailto:python-ideas-requ...@python.org?subject=unsubscribe>
List-Archive: <http://mail.python.org/pipermail/python-ideas/>
List-Post: <mailto:python-id...@python.org>
List-Help: <mailto:python-ideas-requ...@python.org?subject=help>
List-Subscribe: <http://mail.python.org/mailman/listinfo/python-ideas>,
<mailto:python-ideas-requ...@python.org?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org
Sender: "Python-ideas"
<python-ideas-bounces+python-ideas-garchive-35620=googlegroups....@python.org>
On Sun, Oct 07, 2012 at 10:35:17PM -0400, Ned Batchelder wrote:
> A sentence in section 5.4 (Numeric Types) would help. Something like,
> "In accordance with the IEEE 754 standard, NaN's are not equal to any
> value, even another NaN. This is because NaN doesn't represent a
> particular number, it represents an unknown result, and there is no way
> to know if one unknown result is equal to another unknown result."
NANs don't quite mean "unknown result". If they did they would probably
be called "MISSING" or "UNKNOWN" or "NA" (Not Available).
NANs represent a calculation result which is Not A Number. Hence the
name :-) Since we're talking about the mathematical domain here, a
numeric calculation that doesn't return a numeric result could be said
to have no result at all: there is no real-valued x for which x**2 ==
-1, hence sqrt(-1) can return a NAN.
It certainly doesn't mean "well, there is an answer, but I don't know
what it is". It means "I know that there is no answer".
Since neither sqrt(-1) nor sqrt(-2) exist in the reals, we cannot say
that they are equal. If we did, we could prove anything:
sqrt(-1) = sqrt(-2)
Square both sides:
-1 = -2
I was not on the IEEE committee, so I can't speak for them, but my guess
is that they reasoned that since there are an infinite number of "no
result" not-a-number calculations, but only a finite number of NAN bit
patterns available to be used for them, it isn't even safe to presume
that two NANs with the same bit pattern are equal since they may have
come from completely different calculations.
Of course this was before object identity was a relevant factor. As I've
stated before, I think that having collections choose to optimize away
equality tests using object identity is fine. If I need a tuple that
honours NAN semantics, I can subclass tuple to get one. I shouldn't
expect the default tuple behaviour to carry that cost.
By the way, NANs are awesome and don't get anywhere near enough respect.
Here's a great idea from the D language:
http://www.drdobbs.com/cpp/nans-just-dont-get-no-respect/240005723
--
Steven
_______________________________________________
Python-ideas mailing list
Python-id...@python.org
http://mail.python.org/mailman/listinfo/python-ideas