[Python] Fastest rising factorial (Pochhammer function) in python

Discussão em 'Python' iniciado por Stack, Maio 18, 2025.

  1. Stack

    Stack Membro Participativo

    I need to compute the rising factorial of big numbers, the 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]

    Continue reading...

Compartilhe esta Página