Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed4a.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.186 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.63; '*S*': 0.01; 'root': 0.04; 'method.': 0.05; 'squares': 0.07; 'causing': 0.13; 'instead.': 0.15; 'producing': 0.15; 'precision.': 0.16; 'subject:distance': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'compare': 0.20; '2015': 0.23; 'errors': 0.23; 'seems': 0.24; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'error': 0.27; "i'm": 0.29; 'methods.': 0.29; 'function': 0.30; 'values': 0.30; 'probably': 0.32; 'point': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'gives': 0.35; 'to:addr:python-list': 0.35; 'but': 0.36; 'being': 0.36; "let's": 0.36; 'monday,': 0.36; 'two': 0.37; 'should': 0.37; 'subject:: ': 0.37; '(2)': 0.37; '(1)': 0.38; 'thank': 0.39; 'pm,': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'addition': 0.60; 'even': 0.61; 'subject:more': 0.61; 'more': 0.62; 'different': 0.64; 'charset:windows-1252': 0.65; 'here': 0.66; 'dr.': 0.69; 'obvious': 0.72; 'received:204': 0.75; 'square': 0.76; 'institute': 0.77; '(425)': 0.84; '895-4418': 0.84; 'digipen': 0.84; 'herron': 0.84; 'loses': 0.84; 'utc-7,': 0.84; 'you;': 0.84; 'prone': 0.91 Date: Mon, 25 May 2015 22:09:53 -0700 From: Gary Herron User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: a more precise distance algorithm References: <5563e453$0$12990$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432617306 news.xs4all.nl 2936 [2001:888:2000:d::a6]:44128 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91230 On 05/25/2015 09:13 PM, ravas wrote: > On Monday, May 25, 2015 at 8:11:25 PM UTC-7, Steven D'Aprano wrote: >> Let's compare three methods. >> ... >> which shows that: >> >> (1) It's not hard to find mismatches; >> (2) It's not obvious which of the three methods is more accurate. > Thank you; that is very helpful! > > I'm curious: what about the sqrt() function being last is detrimental? > From a point of ignorance it seems like we are just producing errors sooner, > and then multiplying them, with this alternative method. It's probably not the square root that's causing the inaccuracies. In many other cases, and probably here also, it's the summing of two numbers that have vastly different values that loses precision. A demonstration: >>> big = 100000000.0 >>> small = 0.000000001 >>> (big+small)-big # Should produce a value =small, but gives an exact zero instead. 0.0 The squaring of the two values in x*x+y*y just makes the addition even more error prone since the squares make large values even larger and small values even smaller. Gary Herron. -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418