Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91230

Re: a more precise distance algorithm

Date 2015-05-25 22:09 -0700
From Gary Herron <gherron@digipen.edu>
Subject Re: a more precise distance algorithm
References <b2e66a94-7a89-4be9-bbf7-9434396cc178@googlegroups.com> <5563e453$0$12990$c3e8da3$5496439d@news.astraweb.com> <f7bd33f0-f6e0-48cd-a8ea-bdd05fcced2a@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.49.1432617306.5151.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 12:21 -0700
  Re: a more precise distance algorithm felix <felix@epepm.cupet.cu> - 2015-05-25 16:06 -0400
  Re: a more precise distance algorithm Christian Gollwitzer <auriocus@gmx.de> - 2015-05-25 22:27 +0200
    Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 14:03 -0700
  Re: a more precise distance algorithm Gary Herron <gary.herron@islandtraining.com> - 2015-05-25 13:20 -0700
    Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 14:05 -0700
  Re: a more precise distance algorithm Steven D'Aprano <steve@pearwood.info> - 2015-05-26 13:11 +1000
    Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 21:13 -0700
      Re: a more precise distance algorithm Gary Herron <gherron@digipen.edu> - 2015-05-25 22:09 -0700
        Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 22:49 -0700
    Re: a more precise distance algorithm Christian Gollwitzer <auriocus@gmx.de> - 2015-05-26 07:33 +0200
    Re: a more precise distance algorithm Brian Blais <bblais@gmail.com> - 2015-05-27 14:00 -0400
    Re: a more precise distance algorithm Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-05-27 23:03 +0100
    Re: a more precise distance algorithm Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-27 23:04 -0400
  Re: a more precise distance algorithm Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-25 22:42 -0600
    Re: a more precise distance algorithm ravas <ravas@outlook.com> - 2015-05-25 21:59 -0700
  Re: a more precise distance algorithm random832@fastmail.us - 2015-05-26 09:40 -0400
  Re: a more precise distance algorithm random832@fastmail.us - 2015-05-26 09:51 -0400
  Re: a more precise distance algorithm Robin Becker <robin@reportlab.com> - 2015-05-27 14:02 +0100

csiph-web