This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients mark.dickinson, rhettinger, serhiy.storchaka, skrah, steven.daprano, tim.peters
Date 2018-06-24.18:48:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1529866082.6.0.56676864532.issue33089@psf.upfronthosting.co.za>
In-reply-to
Content
Would it be reasonable for me to get started with a "mostly good enough" version using scaling and Kahan summation?

from operator import sub
from math import sqrt, fabs

def kahan_summation(seq):
    # https://en.wikipedia.org/wiki/Kahan_summation_algorithm#The_algorithm
    csum = 0
    err = 0
    for x in seq:
        x -= err
        nsum = csum + x
        err = (nsum - csum) - x
        csum = nsum
    return csum

def hypot(*sides):
    scale = max(map(fabs, sides))
    return scale * sqrt(kahan_summation((s / scale)**2 for s in sides))

def dist(p, q):
    return hypot(*map(sub, p, q))

assert all(hypot(*([1]*d)) == sqrt(d) for d in range(1, 10000))
print(dist(p=(11, 4, 10), q=(9, 10, 13.5)))
History
Date User Action Args
2018-06-24 18:48:02rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, steven.daprano, skrah, serhiy.storchaka
2018-06-24 18:48:02rhettingersetmessageid: <1529866082.6.0.56676864532.issue33089@psf.upfronthosting.co.za>
2018-06-24 18:48:02rhettingerlinkissue33089 messages
2018-06-24 18:48:02rhettingercreate