I wrote a Python program that is using recursion to generate multinomial coefficients - see next section.
Mathematically it is also using recursion by 'decrementing down to the boundary'.
My motivation for coding this was reading the wiki paragraph
Generalized Pascal's triangle
One can use the multinomial theorem to generalize Pascal's triangle or Pascal's pyramid to Pascal's simplex. This provides a quick way to generate a lookup table for multinomial coefficients.
I am not sure what the math is behind the program or if this technique is known. But the 'slow decrementer program' would really 'crank out' on a quantum computer storing massive lookup tables in memory.
What mathematics is the Python program using?
I am going to post this on stack overflow as an answer to this question,
$\quad$ Does Python have a function which computes multinomial coefficients?
but will be able to explain it better after getting feedback from this site.
Python program
def da_multi(A): # Multinomial
if len(A) < 2:
return 1
n = sum(A)
# # Remove the silly 1's
for i in range(0, len(A)):
if A[i] == 1:
B = A.copy()
del B[i]
return n * da_multi(B)
# # OK, dealing with no 1's
r = 0
for i in range(0, len(A)):
B = A.copy()
B[i] = B[i] - 1
r = r + da_multi(B)
return r
A = [1,2,2,7,1]
A_wrk = A.copy()
print('multi:', A, da_multi(A_wrk))
The program calculates a multinomial and the answer agrees with the Wolfram calculation.
OUTPUT
multi: [1, 2, 2, 7, 1] 308880
%%timeit. – JMoravitz Feb 03 '20 at 19:12