我需要计算大数的上升阶乘,到目前为止我发现的最好的是来自 sympy 包sympy package的上升阶乘函数,这非常好,但我仍然需要更快的东西。
我需要的是一个非常快速的版本:
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)])
编辑:给定一个上升阶乘,x(n) = x (x + 1)(x + 2)...(x + n-1),我想检索其扩展公式的给定乘数。
例如:
给定: x(6) = x(x + 1)(x + 2)(x + 3)(x + 5)(x + 6)
和扩展形式: x(6) = x**6 + 15*x**5 + 85*x**4 + 225*x**3 + 274*x**2 + 120*x
我想要一些如何获得这些乘数之一(在本例中为 1、15、85、225、274、120)
使用“my_rising_factorial()”效果很好......但真的很慢
>>>[my_rising_factorial(6,i) for i in xrange (6)]
[1.0, 15, 85, 225, 274, 120]