
I think it's time to accept PEP 485. I've re-read it once more, and it looks like the text is in great shape. (My only recommendation would be to update the Abstract to state that we're specifically adding math.isclose().) A wording question: "This implementation has a flag that lets the user select which relative tolerance test to apply -- this PEP does not suggest that that be retained, but rather than the weak test be selected." -- I think this was meant to say "... rather *that* the weak test be selected", right? (It would be nice if the sample implementation defaulted to the choice in the PEP.) However, those are just minor edits, and I hereby approve the PEP. Thanks Chris and everyone else for the fruitful discussion (and thanks especially to Chris for eventually ending the bikeshedding and writing a PEP that explains each of the choices). Congrats! -- --Guido van Rossum (python.org/~guido)

Thank you Guido. It'll be nice to see this all come to something. Thanks to all who contributed to the discussion -- despite this being a pretty simple function, I learned a lot and far more fully appreciate the nuance of all of this. I'll edit the text as you suggest, and then work on a patch -- I'm sure I'll have questions for Python-dev when I actually do that, but I'll get started on my own and see how far I get. -Chris On Fri, Feb 27, 2015 at 11:38 AM, Guido van Rossum <guido@python.org> wrote:
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

On 02/27/2015 12:07 PM, Chris Barker wrote:
There's another typo: The "Large tolerances" section, references a "string test". Perhaps that should be "strong test", but that would seem to contradict the sentence which follows. -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418

On 28 Feb 2015 06:16, "Chris Barker" <chris.barker@noaa.gov> wrote:
pretty simple function, I learned a lot and far more fully appreciate the nuance of all of this. The simple enhancements are often the hardest to get consensus on, but also often the most beneficial in the long run. Thanks for pushing this one through to completion! Regards, Nick.

On Fri, Feb 27, 2015 at 12:07 PM, Chris Barker <chris.barker@noaa.gov> wrote:
I'll edit the text as you suggest,
Done.
OK -- big question 1: As far as I can tell, the math module is entirely a C extension. So I can: 1) write isclose() in C -- I could probably do that (It's been a while -- I'm a big Cython fan these days...) and I'd probably punt on having it work with anything other than floats if I did that -- which would fit how most of the match module works anyway. 2) Write it in Python, and monkey-patch it in to the math module -- I honestly have no idea how to do that, but as I can add a new name to the math module after importing it, it should be doable --but I have no idea where the code would go. Suggestions?? Thanks, -Chris
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

It should be written in C. I thought you knew. :-) I guess it's okay to drop Decimal support (*). Complex support probably should be in cmath. But this is an amendmend to the PEP as accepted. If anyone cares about these changes they should speak up, otherwise the PEP should be updated. (*) Adding it to the decimal module would require a discussion with Raymond Hettinger, but Decimal users can probably copy and paste the formula from the PEP. On Monday, March 2, 2015, Chris Barker <chris.barker@noaa.gov> wrote:
-- --Guido van Rossum (on iPad)

On Mon, Mar 2, 2015 at 10:39 PM, Guido van Rossum <guido@python.org> wrote:
It should be written in C. I thought you knew. :-)
It crossed my mind when we talked about the math module -- but I didn't really think about it... I guess it's okay to drop Decimal support (*). Complex support probably
should be in cmath.
fair enough -- and easy enough to do if we do float-only in math, and complex-only in cmath. But this is an amendmend to the PEP as accepted. If anyone cares about
these changes they should speak up, otherwise the PEP should be updated.
will do.
yup -- but maybe worth putting in there while we're at it. though as Decimal is arbitrary precision, maybe it's not needed.... -Chris
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

On Mon, Mar 2, 2015 at 10:48 PM, Chris Barker <chris.barker@noaa.gov> wrote:
It's not really arbitrary precision, it's decimal *floating* point with a large but finite precision, so all the same arguments apply. But my reasoning was more that (at least when I was last involved in the project) the decimal module tries to stick pretty close to the IEEE 754 standard (maybe nowadays a later version?) and random Python-only additions are controversial. -- --Guido van Rossum (python.org/~guido)

2015-03-03 6:25 GMT+01:00 Chris Barker <chris.barker@noaa.gov>:
Maybe it's time to rename the math module to _math and create a math.py module, like _decimal/decimal? math.py should end with "from _math import *". It may be interesting to have Python implementation of math.fsum(), math.factorial(), math.degrees() and math.radians(). Extract of fsum() comment: Full precision summation of a sequence of floats. def msum(iterable): partials = [] # sorted, non-overlapping partial sums for x in iterable: i = 0 for y in partials: if abs(x) < abs(y): x, y = y, x hi = x + y lo = y - (hi - x) if lo: partials[i] = lo i += 1 x = hi partials[i:] = [x] return sum_exact(partials) The C implementation of factorial is not naive: "Divide-and-conquer factorial algorithm" (see the C code). Obvisouly, a expect lower performances from Python code manipulating numbers (because of the cost of boxing-unboxing, cost of functions calls, etc.). But it might help other Python implementations to implement the math module. Victor

On Tue, Mar 3, 2015 at 8:43 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
On 03/03/2015 01:17 AM, Victor Stinner wrote:
What do folks think? If we're going to do this, I'll write isclose() in python. And I could do the work to split it out, too, I suppose. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

In this case I disagree. The math module mostly wraps the C math library and the bar should remain high for things to be added to it. Let this be someone's opportunity to learn C (I guess not Chris's :-). On Wed, Mar 4, 2015 at 12:23 PM, Brett Cannon <brett@python.org> wrote:
-- --Guido van Rossum (python.org/~guido)

On Wed, Mar 4, 2015 at 12:33 PM, Guido van Rossum <guido@python.org> wrote:
As it happens, the first C code I ever wrote, beyond toy examples, was python extensions. I dropped that for Cython a good while ago, but I can remember enough for this simple function ;-) I agree that it's not worth going to python for the math module for just this -- but others were proposing other reasons to do it. Back to look at K&R ;-) -Chris
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

2015-03-03 10:17 GMT+01:00 Victor Stinner <victor.stinner@gmail.com>:
Since the idea looks to be well accepted, I proposed a patch to implement it: http://bugs.python.org/issue23595? math.py contains 4 constants (e, pi, inf, nan; nan is optionnal) and 4 functions: degrees(), radians(), factorial(), fsum(). See the issue for details. Victor

Thank you Guido. It'll be nice to see this all come to something. Thanks to all who contributed to the discussion -- despite this being a pretty simple function, I learned a lot and far more fully appreciate the nuance of all of this. I'll edit the text as you suggest, and then work on a patch -- I'm sure I'll have questions for Python-dev when I actually do that, but I'll get started on my own and see how far I get. -Chris On Fri, Feb 27, 2015 at 11:38 AM, Guido van Rossum <guido@python.org> wrote:
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

On 02/27/2015 12:07 PM, Chris Barker wrote:
There's another typo: The "Large tolerances" section, references a "string test". Perhaps that should be "strong test", but that would seem to contradict the sentence which follows. -- Dr. Gary Herron Department of Computer Science DigiPen Institute of Technology (425) 895-4418

On 28 Feb 2015 06:16, "Chris Barker" <chris.barker@noaa.gov> wrote:
pretty simple function, I learned a lot and far more fully appreciate the nuance of all of this. The simple enhancements are often the hardest to get consensus on, but also often the most beneficial in the long run. Thanks for pushing this one through to completion! Regards, Nick.

On Fri, Feb 27, 2015 at 12:07 PM, Chris Barker <chris.barker@noaa.gov> wrote:
I'll edit the text as you suggest,
Done.
OK -- big question 1: As far as I can tell, the math module is entirely a C extension. So I can: 1) write isclose() in C -- I could probably do that (It's been a while -- I'm a big Cython fan these days...) and I'd probably punt on having it work with anything other than floats if I did that -- which would fit how most of the match module works anyway. 2) Write it in Python, and monkey-patch it in to the math module -- I honestly have no idea how to do that, but as I can add a new name to the math module after importing it, it should be doable --but I have no idea where the code would go. Suggestions?? Thanks, -Chris
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

It should be written in C. I thought you knew. :-) I guess it's okay to drop Decimal support (*). Complex support probably should be in cmath. But this is an amendmend to the PEP as accepted. If anyone cares about these changes they should speak up, otherwise the PEP should be updated. (*) Adding it to the decimal module would require a discussion with Raymond Hettinger, but Decimal users can probably copy and paste the formula from the PEP. On Monday, March 2, 2015, Chris Barker <chris.barker@noaa.gov> wrote:
-- --Guido van Rossum (on iPad)

On Mon, Mar 2, 2015 at 10:39 PM, Guido van Rossum <guido@python.org> wrote:
It should be written in C. I thought you knew. :-)
It crossed my mind when we talked about the math module -- but I didn't really think about it... I guess it's okay to drop Decimal support (*). Complex support probably
should be in cmath.
fair enough -- and easy enough to do if we do float-only in math, and complex-only in cmath. But this is an amendmend to the PEP as accepted. If anyone cares about
these changes they should speak up, otherwise the PEP should be updated.
will do.
yup -- but maybe worth putting in there while we're at it. though as Decimal is arbitrary precision, maybe it's not needed.... -Chris
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

On Mon, Mar 2, 2015 at 10:48 PM, Chris Barker <chris.barker@noaa.gov> wrote:
It's not really arbitrary precision, it's decimal *floating* point with a large but finite precision, so all the same arguments apply. But my reasoning was more that (at least when I was last involved in the project) the decimal module tries to stick pretty close to the IEEE 754 standard (maybe nowadays a later version?) and random Python-only additions are controversial. -- --Guido van Rossum (python.org/~guido)

2015-03-03 6:25 GMT+01:00 Chris Barker <chris.barker@noaa.gov>:
Maybe it's time to rename the math module to _math and create a math.py module, like _decimal/decimal? math.py should end with "from _math import *". It may be interesting to have Python implementation of math.fsum(), math.factorial(), math.degrees() and math.radians(). Extract of fsum() comment: Full precision summation of a sequence of floats. def msum(iterable): partials = [] # sorted, non-overlapping partial sums for x in iterable: i = 0 for y in partials: if abs(x) < abs(y): x, y = y, x hi = x + y lo = y - (hi - x) if lo: partials[i] = lo i += 1 x = hi partials[i:] = [x] return sum_exact(partials) The C implementation of factorial is not naive: "Divide-and-conquer factorial algorithm" (see the C code). Obvisouly, a expect lower performances from Python code manipulating numbers (because of the cost of boxing-unboxing, cost of functions calls, etc.). But it might help other Python implementations to implement the math module. Victor

On Tue, Mar 3, 2015 at 8:43 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
On 03/03/2015 01:17 AM, Victor Stinner wrote:
What do folks think? If we're going to do this, I'll write isclose() in python. And I could do the work to split it out, too, I suppose. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

In this case I disagree. The math module mostly wraps the C math library and the bar should remain high for things to be added to it. Let this be someone's opportunity to learn C (I guess not Chris's :-). On Wed, Mar 4, 2015 at 12:23 PM, Brett Cannon <brett@python.org> wrote:
-- --Guido van Rossum (python.org/~guido)

On Wed, Mar 4, 2015 at 12:33 PM, Guido van Rossum <guido@python.org> wrote:
As it happens, the first C code I ever wrote, beyond toy examples, was python extensions. I dropped that for Cython a good while ago, but I can remember enough for this simple function ;-) I agree that it's not worth going to python for the math module for just this -- but others were proposing other reasons to do it. Back to look at K&R ;-) -Chris
-- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov

2015-03-03 10:17 GMT+01:00 Victor Stinner <victor.stinner@gmail.com>:
Since the idea looks to be well accepted, I proposed a patch to implement it: http://bugs.python.org/issue23595? math.py contains 4 constants (e, pi, inf, nan; nan is optionnal) and 4 functions: degrees(), radians(), factorial(), fsum(). See the issue for details. Victor
participants (7)
-
Brett Cannon
-
Chris Barker
-
Ethan Furman
-
Gary Herron
-
Guido van Rossum
-
Nick Coghlan
-
Victor Stinner