[Python-ideas] Introduce `start=1` argument to `math.factorial`

Nick Coghlan ncoghlan at gmail.com
Thu Sep 18 08:15:38 CEST 2014


On 18 September 2014 14:13, Steven D'Aprano <steve at pearwood.info> wrote:
> On Wed, Sep 17, 2014 at 04:02:44PM -0700, Ram Rachum wrote:
>> I suggest introducing a `start=1` argument to `math.factorial`, so the
>> result would be (the C-optimized version of) `product(range(start, x+1),
>> start=1)`. This'll be useful for combinatorical calculations.
>
> Then it wouldn't be the factorial function any more.
>
> There are lots of functions which could be useful for combinatorical
> calculations, including !n and n!!, do you think this particular one
> would be of broad enough interest that it deserves to be in the standard
> library?
>
> Do you know of any other programming languages which offer this "partial
> factorial" function in their standard library?

It's also worth noting that "pip install mpmath" will provide rising
and falling factorials
(http://mpmath.org/doc/current/functions/gamma.html#rising-and-falling-factorials)
and a whole lot more. There's no need to add such complexity to the
standard library.

However, now that CPython ships with pip by default, we may want to
consider providing more explicit pointers to such "If you want more
advanced functionality than the standard library provides" libraries.

Yes, that may be contentious in the near term as folks argue over
which "stdlib++" modules to recommend, but in some cases there are
clear "next step beyond the standard library" category winners that
are worth introducing to newcomers, rather than making them do their
own research.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list