I really like this idea.  It fixes the weirdness whereby cmath is for 
complex numbers, and math is for real numbers and integers.  I like 
separating them into three categories.

One suggestion: Consider generalizing binom to the multinomial coefficent.

def binom(n, *ks):
    # Returns n! / prod(ki! for ki in ks)

Best,

Neil 

On Thursday, July 12, 2018 at 7:57:08 AM UTC-4, Serhiy Storchaka wrote:
>
> What are your thoughts about adding a new imath module for integer 
> mathematics? It could contain the following functions: 
>
> * factorial(n) 
>
> Is just moved from the math module, but non-integer types are rejected. 
> Currently math.factorial() accepts also integer floats like 3.0. It 
> looks to me, the rationale was that at the time when math.factorial() 
> was added, all function in the math module worked with floats. But now 
> we can revise this decision. 
>
> * gcd(n, m) 
>
> Is just moved from the math module. 
>
> * as_integer_ration(x) 
>
> Equivalents to: 
>
> def as_integer_ration(x): 
>      if hasattr(x, 'as_integer_ration'): 
>          return x.as_integer_ration() 
>      else: 
>          return (x.numerator, x.denominator) 
>
> * binom(n, k) 
>
> Returns factorial(n) // (factorial(k) * factorial(n-k)), but uses more 
> efficient algorithm. 
>
> * sqrt(n) 
>
> Returns the largest integer r such that r**2 <= n and (r+1)**2 > n. 
>
> * isprime(n) 
>
> Tests if n is a prime number. 
>
> * primes() 
>
> Returns an iterator of prime numbers: 2, 3, 5, 7, 11, 13,... 
>
> Are there more ideas? 
>
> _______________________________________________ 
> Python-ideas mailing list 
> python...@python.org <javascript:> 
> https://mail.python.org/mailman/listinfo/python-ideas 
> Code of Conduct: http://python.org/psf/codeofconduct/ 
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/NTSXZQAIC2OLSA2K4HP5N7HSFUNW7ZYF/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to