[issue37454] Clarify docs for math.log1p()

2019-08-23 Thread Tim Peters


Tim Peters  added the comment:

> Sometimes you guys make me feel dumb as a rock.

I expect we all do that favor for each other at times ;-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37454] Clarify docs for math.log1p()

2019-08-22 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Sometimes you guys make me feel dumb as a rock.  Sorry for the distraction.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37454] Clarify docs for math.log1p()

2019-07-01 Thread Tim Peters


Tim Peters  added the comment:

Mark's analysis is spot-on - good eye :-)

Here under 3.7.3 [MSC v.1916 64 bit (AMD64)] on win32, in the original script 
it makes no difference at all for negative "small x" (where, as Mark said, `1 - 
random.random()` is exactly representable):

Counter({'equal': 50058, 'offset_log': 41936, 'regular_log': 8006})
Counter({'equal': 10})

Changing to Mark's 1e-3 * random.random():

Counter({'offset_log': 99958, 'equal': 42})
Counter({'offset_log': 99884, 'equal': 116})

And going on to use 1e-6 instead:

Counter({'offset_log': 10})
Counter({'offset_log': 10})

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37454] Clarify docs for math.log1p()

2019-07-01 Thread Steven D'Aprano


Change by Steven D'Aprano :


--
nosy: +steven.daprano

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37454] Clarify docs for math.log1p()

2019-07-01 Thread Mark Dickinson


Mark Dickinson  added the comment:

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})

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37454] Clarify docs for math.log1p()

2019-07-01 Thread Mark Dickinson


Mark Dickinson  added the comment:

> however, for x < 0.0 it is always worse

That's quite surprising. Which platform? And can you give some example inputs 
and outputs? With a good math library, I'd expect `log1p(x)` to almost always 
be at least as accurate as `log(1 + x)`, and substantially _more_ accurate for 
small x (say abs(x) < 1e-5). If that's not happening, we may want to substitute 
our own implementation for the system implementation on some platforms (in the 
same was as we did for lgamma, erf, and friends).

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37454] Clarify docs for math.log1p()

2019-06-30 Thread Raymond Hettinger


New submission from Raymond Hettinger :

Currently the docs say, "The result is calculated in a way which is accurate 
for x near zero."

That is somewhat vague.  Some quick tests show that it is often more accurate 
than log() for the whole range of 0.0 < x < 1.0; however, for x < 0.0 it is 
always worse.

Since the function is just a pass-through to the C library, we probably can't 
make any guarantees.  On the other hand, it is hard to know when this function 
is preferred without some guidance.

--
assignee: docs@python
components: Documentation
files: study_log1p.py
messages: 346942
nosy: docs@python, mark.dickinson, rhettinger, tim.peters
priority: low
severity: normal
status: open
title: Clarify docs for math.log1p()
versions: Python 3.8, Python 3.9
Added file: https://bugs.python.org/file48448/study_log1p.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com