I need to compute the rising factorial of big numbers, 开发者_如何学JAVAthe best I found until now is the rising factorial function from the sympy package sympy package, that is really nice, but I would still need something faster.
What I would need exactly is a really fast version of this:
from itertools import combinations
from numpy import prod
def my_rising_factorial(degree, elt):
return sum([prod(i) for i in combinations(xrange(1,degree),elt)])
EDIT: that is given a rising factorial, x(n) = x (x + 1)(x + 2)...(x + n-1), I would like to retrieve a given multiplier of its expanded formula.
eg:
given: x(6) = x(x + 1)(x + 2)(x + 3)(x + 5)(x + 6)
and the expanded form: x(6) = x**6 + 15*x**5 + 85*x**4 + 225*x**3 + 274*x**2 + 120*x
I want some how to get one of those multipliers (in this case 1, 15, 85, 225, 274, 120)
with "my_rising_factorial()" it works well... but really slowly
>>>[my_rising_factorial(6,i) for i in xrange (6)]
[1.0, 15, 85, 225, 274, 120]
Try this package: http://tnt.math.se.tmu.ac.jp/nzmath/
Like job said, the function you want is Stirling Number of the 1st kind (I'd worked out the recursive definition and was about to post it, but I didn't know the name).
The function is nzmath.combinatorial.stirling1
The other versions I know about are in mpmath.qfunctions and scipy.special.orthogonal.
If neither of those nor SymPy are fast enough, you can try PyPy (another implementation of Python) to speed them up. If that doesn't work, try Psyco (an extension module), Shedskin or Nuitka (Python compilers), Cython, or writing it in C.
These are just the unsigned Stirling Numbers of the First Kind. I don't have a fast method of computing them, but you could probably use the fact that they follow a simple recursive relationship: S(n,k) = (n-1)*S(n-1,k) + S(n-1,k-1)
精彩评论