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 mark.dickinson
Recipients docs@python, mark.dickinson, rhettinger, tim.peters
Date 2019-07-01.07:18:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1561965535.33.0.4802873053.issue37454@roundup.psfhosted.org>
In-reply-to
Content
Ah, now I've looked at the script. There's an issue with using `random.random()` to create "small" values for testing, since its result is always an integer multiple of 2**-53. That means in particular that if x = random.random(), then 1 - x is always *exactly* representable (and 1 + x is also exactly representable approximately half of the time), so there's no loss of accuracy in the intermediate step of computing log(1 + x) if x = -random.random().

Here's what I get if I run your script exactly as it stands (Python 3.7.3, macOS 10.14.5)

    mirzakhani:Desktop mdickinson$ python test.py
    Counter({'equal': 51839, 'offset_log': 41988, 'regular_log': 6173})
    Counter({'equal': 93727, 'regular_log': 6273})

But if I replace each `random.random()` call with `1e-3 * random.random()`, in order to test small values of `x`, here's what I get:

    mirzakhani:Desktop mdickinson$ python test.py
    Counter({'offset_log': 99945, 'equal': 55})
    Counter({'offset_log': 99893, 'equal': 107})
History
Date User Action Args
2019-07-01 07:18:55mark.dickinsonsetrecipients: + mark.dickinson, tim.peters, rhettinger, docs@python
2019-07-01 07:18:55mark.dickinsonsetmessageid: <1561965535.33.0.4802873053.issue37454@roundup.psfhosted.org>
2019-07-01 07:18:55mark.dickinsonlinkissue37454 messages
2019-07-01 07:18:54mark.dickinsoncreate