[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, -1, m) instead 
when m=1.  Offhand, I couldn't imagine a plausible use case for finding an 
inverse mod 1 - and still can't ;-)  In abstract algebra, sure - but for 
concrete numerical computation?  Oh well.

In any case, testing

(minv(a, m) * a - 1) % m == 0

instead appears to work for all non-error cases.

--

___
Python tracker 

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



[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 (commutative, unital) rings isn't helpful, and causes all 
sorts of otherwise universal constructs (quotients, localizations, categorical 
limits in general) to have only conditional existence. So nowadays most (but 
not all) people accept that the zero ring has the same right to exist as any 
other commutative ring.

Integral domains are another matter, of course: there you really _do_ want to 
insist that 1 != 0, though what you're really insisting is that any finite 
product of nonzero elements should be nonzero, and 1 != 0 is just the special 
case of that rule for the empty product, while x*y !=0 for x != 0 and y != 0 is 
the special case for two arguments.

--

___
Python tracker 

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



[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 

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



[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 
`false`.  Modulo -1, everything I tried returned `false`.

Which makes less sense to me.

Fine by me if you want to close this as "not a bug".

--

___
Python tracker 

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



[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.

--

___
Python tracker 

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



[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?

--

___
Python tracker 

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



[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 

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



[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 ;-)

--

___
Python tracker 

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



[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
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[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, tim.peters
priority: normal
severity: normal
stage: needs patch
status: open
title: pow() should disallow inverse when modulus is +-1
type: behavior
versions: Python 3.8, Python 3.9

___
Python tracker 

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