multinomial_coefficients(m,
n,
_tuple=<type 'tuple'>,
_zip=<built-in function zip>)
| source code
call graph |
|
| Call Graph |
Return a dictionary containing pairs {(k1,k2,..,km) : C_kn}
where C_kn are multinomial coefficients such that
n=k1+k2+..+km.
For example:
>>> print multinomial_coefficients(2,5)
{(3, 2): 10, (1, 4): 5, (2, 3): 10, (5, 0): 1, (0, 5): 1, (4, 1): 5}
The algorithm is based on the following result:
Consider a polynomial and it's m-th exponent:
P(x) = sum_{i=0}^m p_i x^k
P(x)^n = sum_{k=0}^{m n} a(n,k) x^k
The coefficients a(n,k) can be computed using the
J.C.P. Miller Pure Recurrence [see D.E.Knuth, Seminumerical
Algorithms, The art of Computer Programming v.2, Addison
Wesley, Reading, 1981;]:
a(n,k) = 1/(k p_0) sum_{i=1}^m p_i ((n+1)i-k) a(n,k-i),
where a(n,0) = p_0^n.
|