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 tim.peters
Recipients mark.dickinson, oscarbenjamin, rhettinger, tim.peters
Date 2020-07-17.02:40:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1594953606.32.0.00498944659218.issue41311@roundup.psfhosted.org>
In-reply-to
Content
Thanks! That explanation really helps explain where "geometric distribution" comes from. Although why it keeps taking k'th roots remains a mystery to me ;-)

Speaking of which, the two instances of

exp(log(random())/k)

are numerically suspect. Better written as

random()**(1/k)

The underlying `pow()` implementation will, in effect, compute log(random()) with extra bits of precision for internal use. Doing log(random()) forces it to use a 53-bit approximation. Not to mention that it's more _obvious_ to write a k'th root as a k'th root.  Note: then the 1/k can be computed once outside the loop.

Perhaps worse is

log(1-W)

which should be written

log1p(-W)

instead.  W is between 0 and 1, and the closer it is to 0 the more its trailing bits are entirely lost in computing 1-W. It's the purpose of log1p to combat this very problem.
History
Date User Action Args
2020-07-17 02:40:06tim.peterssetrecipients: + tim.peters, rhettinger, mark.dickinson, oscarbenjamin
2020-07-17 02:40:06tim.peterssetmessageid: <1594953606.32.0.00498944659218.issue41311@roundup.psfhosted.org>
2020-07-17 02:40:06tim.peterslinkissue41311 messages
2020-07-17 02:40:05tim.peterscreate