Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.032 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'example:': 0.03; 'problem:': 0.07; 'suppose': 0.07; 'string': 0.09; 'here?': 0.09; 'implemented.': 0.09; 'logic': 0.09; '(absolute': 0.16; 'ed.': 0.16; 'isbn': 0.16; 'operation.': 0.16; 'received:65.55.116.7': 0.16; 'reminded': 0.16; 'stuff!': 0.16; 'essential': 0.16; 'wrote:': 0.18; 'discussion': 0.18; 'normally': 0.19; 'thu,': 0.19; '>>>': 0.22; '+0000': 0.22; 'to:name:python- list@python.org': 0.22; 'error': 0.23; 'case.': 0.24; 'received:65.55.116': 0.24; 'compare': 0.26; 'equivalent': 0.26; 'law.': 0.26; 'url:edu': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'correct': 0.29; 'skip:- 40': 0.29; 'chris': 0.29; '[1]': 0.29; 'absolute': 0.30; 'programming.': 0.30; 'said,': 0.30; 'url:mailman': 0.30; 'usually': 0.31; '(although': 0.31; 'comparison': 0.31; 'division': 0.31; 'equality': 0.31; 'operators': 0.31; 'steven': 0.31; 'another': 0.32; 'url:python': 0.33; 'fri,': 0.33; 'totally': 0.33; 'date:': 0.34; "can't": 0.35; 'equal': 0.35; 'operations': 0.35; 'but': 0.35; 'url:listinfo': 0.36; "i'll": 0.36; 'url:org': 0.36; 'wrong': 0.37; 'email addr:python.org': 0.37; 'starting': 0.37; 'law,': 0.38; 'to:addr :python-list': 0.38; 'previous': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; '2nd': 0.60; 'most': 0.60; 'break': 0.61; 'full': 0.61; 'numbers': 0.61; 'simple': 0.61; 're:': 0.63; 'real': 0.63; 'visit': 0.64; 'email name:python-list': 0.65; 'it!': 0.67; 'avoids': 0.84; 'functions:': 0.84; 'irrelevant': 0.84; 'shoes,': 0.84; 'url:stanford': 0.84; 'wrong!': 0.84; 'carlos': 0.91; 'world:': 0.91; 'hand,': 0.93; '2013': 0.98 X-TMN: [7l3rIe/DCEqiZn2tzNMyjA4zmSrYDVHW] X-Originating-Email: [carlosnepomuceno@outlook.com] From: Carlos Nepomuceno To: "python-list@python.org" Subject: RE: Short-circuit Logic Date: Fri, 31 May 2013 09:42:38 +0300 Importance: Normal In-Reply-To: <51a8318e$0$29966$c3e8da3$5496439d@news.astraweb.com> References: <5f101d70-e51f-4531-9153-c92ee2486fd9@googlegroups.com>, <51a1fc7b$0$30002$c3e8da3$5496439d@news.astraweb.com>, <2abf4e9c-8c3b-4e2f-80c9-50c1f1d75c9d@googlegroups.com>, <51a4b5a1$0$29966$c3e8da3$5496439d@news.astraweb.com>, <04b90c02-833a-4bad-88ad-ab71178b8f79@googlegroups.com>, <48519aa0-d0cd-4ffc-a2f5-2107465321d8@qn4g2000pbc.googlegroups.com>, , <51a6b969$0$29966$c3e8da3$5496439d@news.astraweb.com>, , <51a6e6b8$0$11118$c3e8da3@news.astraweb.com>, , <51a8318e$0$29966$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 31 May 2013 06:42:38.0525 (UTC) FILETIME=[0ABCDED0:01CE5DCA] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 98 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369982567 news.xs4all.nl 15891 [2001:888:2000:d::a6]:55608 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46576 ----------------------------------------=0A= > From: steve+comp.lang.python@pearwood.info=0A= > Subject: Re: Short-circuit Logic=0A= > Date: Fri=2C 31 May 2013 05:13:51 +0000=0A= > To: python-list@python.org=0A= >=0A= > On Fri=2C 31 May 2013 00:03:13 +0300=2C Carlos Nepomuceno wrote:=0A= >=0A= >> ----------------------------------------=0A= >>> From: steve+comp.lang.python@pearwood.info Subject: Re: Short-circuit= =0A= >>> Logic=0A= >>> Date: Thu=2C 30 May 2013 05:42:17 +0000 To: python-list@python.org=0A= >> [...]=0A= >>> Here's another way=2C mathematically equivalent (although not necessari= ly=0A= >>> equivalent using floating point computations!) which avoids the=0A= >>> divide-by- zero problem:=0A= >>>=0A= >>> abs(a - b) < epsilon*a=0A= >>=0A= >> That's wrong! If abs(a) < abs(a-b)/epsilon you will break the=0A= >> commutative law. For example:=0A= >=0A= > What makes you think that the commutative law is relevant here?=0A= =0A= How can't you see?=0A= =0A= I'll requote a previous message:=0A= =0A= }On Thu=2C 30 May 2013 13:45:13 +1000=2C Chris Angelico wrote:=0A= } =0A= }> Let's suppose someone is told to compare floating point numbers by=0A= }> seeing if the absolute value of the difference is less than some=0A= }> epsilon. =0A= } =0A= }Which is usually the wrong way to do it! Normally one would prefer =0A= }*relative* error=2C not absolute:=0A= =A0=0A= Since we are considering Chris's supposition ("to compare floating point nu= mbers") it's totally relevant to understand how that operation can be corre= ctly implemented.=0A= =0A= =0A= > Many things break the commutative law=2C starting with division and=0A= > subtraction:=0A= >=0A= > 20 - 10 !=3D 10 - 20=0A= >=0A= > 1/2 !=3D 2/1=0A= >=0A= > Most comparison operators other than equality and inequality:=0A= >=0A= > (23 < 42) !=3D (42 < 23)=0A= >=0A= > String concatenation:=0A= >=0A= > "Hello" + "World" !=3D "World" + "Hello"=0A= >=0A= > Many operations in the real world:=0A= >=0A= > put on socks=2C then shoes !=3D put on shoes=2C then socks.=0A= >=0A= =0A= That's is totally irrelevant in this case. The commutative law is essential= to the equality operation.=0A= =0A= > But you are correct that approximately-equal using *relative* error is=0A= > not commutative. (Absolute error=2C on the other hand=2C is commutative.)= As=0A= > I said=2C any form of "approximate equality" has gotchas. But this gotcha= =0A= > is simple to overcome:=0A= >=0A= > abs(a -b) < eps*max(abs(a)=2C abs(b))=0A= >=0A= > (Knuth's "approximately equal to" which you give.)=0A= >=0A= >=0A= >> This discussion reminded me of TAOCP and I paid a visit and bring the=0A= >> following functions:=0A= >=0A= > "TAOCP"?=0A= =0A= The Art of Computer Programming[1]! An old book full of excellent stuff! A = MUST READ!!!! =3B)=0A= =0A= http://www-cs-faculty.stanford.edu/~uno/taocp.html=0A= =0A= [1] Knuth=2C Donald (1981). The Art of Computer Programming. 2nd ed. Vol. 2= . p. 218. Addison-Wesley. ISBN 0-201-03822-6.=0A= =0A= >=0A= >=0A= > --=0A= > Steven=0A= > --=0A= > http://mail.python.org/mailman/listinfo/python-list =