The default implementation uses generic operations throughout, and requires that n
be a native integral. Wikipedia states that "the rising and falling factorials are well defined in any unital ring, and therefore x can be taken to be, for example, a complex number, including negative integers, or a polynomial with complex coefficients, or any complex-valued function." Implementing [[falling-factorial]] as a generic allows all of this (and more!) to work automatically.
(A unital ring is an abelian group - a type with a +
, -
and a sensible zero - as well as a *
operation that distributes over addition. The "unital" part means there is a sensible one, i.e., a multiplicative identity.)
Given a native integral input, we can be more efficient by using range
to generate the product terms. This is PROBABLY a case of premature optimization, since how fast does [[falling-factorial]] need to be? But if you see a way to keep the speed while unifying these almost-the-same implementations, please let me know and open a PR!
I learned about the next group of functions from John D Cook's Variations on Factorial and Multifactorial posts.
https://en.wikipedia.org/wiki/Double_factorial#Generalizations