[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Tim Peters
Tim Peters added the comment: I don't have a problem with the trivial ring - I wasn't being that high-minded ;-) I was testing a different inverse algorithm, and in the absence of errors checked that minv(a, m) * a % m == 1 for various a and m >= 0. Of course that failed using pow(a,

[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Mark Dickinson
Mark Dickinson added the comment: > I guess I'm just not used to 0 being a multiplicative identity. Yes, there's a whole generation of mathematicians who believe (wrongly) that "0 != 1" is one of the ring axioms. But it turns out that excluding the zero ring from the category of

[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Tim Peters
Tim Peters added the comment: Mark, to save you the hassle, I'm closing this myself now. Thanks for the feedback! -- assignee: -> tim.peters resolution: -> not a bug stage: patch review -> resolved status: open -> closed ___ Python tracker

[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Tim Peters
Tim Peters added the comment: Yup, you have a point there! :-) I guess I'm just not used to 0 being a multiplicative identity. Don't know what other systems do. Playing with Maxima, modulo 1 it seems to think 0 is the inverse of everything _except_ for 0. `inv_mod(0, 1)` returns

[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Mark Dickinson
Mark Dickinson added the comment: > Z/1Z is a perfectly-well-defined ring. More to the point, it's a perfectly well-defined ring in which every element is invertible. That's why the Euler phi function has phi(1) = 1 (rather than phi(1) = 0), for example. --

[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Mark Dickinson
Mark Dickinson added the comment: > While I doubt this, he may even argue that it's working correctly already ;-) Yes, I'd argue exactly that. There's nothing ill-defined about working modulo +/-1. Z/1Z is a perfectly-well-defined ring. What's the motivation for this change? --

[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Batuhan
Change by Batuhan : -- keywords: +patch pull_requests: +15061 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/15344 ___ Python tracker

[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Tim Peters
Tim Peters added the comment: @Batuhan, fine by me if you want to take this on! It should be relatively easy. But Mark wrote the code, so it's really up to him. While I doubt this, he may even argue that it's working correctly already ;-) --

[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Batuhan
Batuhan added the comment: Can i work on this? -- nosy: +BTaskaya ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue37893] pow() should disallow inverse when modulus is +-1

2019-08-20 Thread Tim Peters
New submission from Tim Peters : For example, these should all raise ValueError instead: >>> pow(2, -1, 1) 0 >>> pow(1, -1, 1) 0 >>> pow(0, -1, 1) 0 >>> pow(2, -1, -1) 0 >>> pow(1, -1, -1) 0 >>> pow(0, -1, -1) 0 -- components: Library (Lib) messages: 350015 nosy: mark.dickinson,