[Python-ideas] Add the imath module

Danilo J. S. Bellini danilo.bellini at gmail.com
Fri Jul 13 12:15:41 EDT 2018


If we have a fast and exact primality test up to 2**64,
a signature like this would help:

def is_prime(n, probabilistic=False):

When probabilistic is False and the number is beyond 2**64,
it'll return OverflowError.
When probabilistic is True, it's unbounded, but probabilistic.
The docs should be explicit about that, though.

Instead of an OverflowError,
a number beyond 2**64 might simply use a slower strategy.
But to make it an explicit option, the signature could be:

def is_prime(n, exact=True, unbounded=False):

By tellling it should be both exact and unbounded,
the user is aware that it might be slow.

The alternatives are:

   - exact, unbounded: Slower test
   - not exact, unbounded: Probabilistic test
   - exact, bounded: Default, raises OverflowError beyond 2**64
   - not exact, bounded: Invalid, but it can just ignore exact input

-- 
Danilo J. S. Bellini
---------------
"*It is not our business to set up prohibitions, but to arrive at
conventions.*" (R. Carnap)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180713/030d1c41/attachment.html>


More information about the Python-ideas mailing list