I am trying to figure out how to implement a routine that calculates the whole sequence of multinomial (Newton) coefficients for a polynomial of any degree $d$ and any number $n$ of terms.
The formulation of such coefficient is:
d! / (k_1! k_2!...k_n!), with k_1 + k_2 +...+ k_n = d.
And the polynomial is given by:
(x_1 + x_2 +...+ x_n)^d = \Sum_{k_i \geq 0, \Sum_{k_i}=n} d! / (k_1! k_2! ... k_n!) x_1^k_1 x_2^k_2 ... x_n^k_n.
I know that any complete vector of such coefficients has a length given by the binomial permutations $(n + d - 1, n - 1)$.
The issue that I cannot crack is the fact that there is a variable number of conditions under the sum for any generic function that would be defined by
int[] multinomial(int n, int d)
For example, for a trinomial $n=3$, this function would return:
d multinomial(n=3, d)
0 [1]
1 [1, 1, 1]
2 [1, 1, 1, 2, 2, 2]
3 [1, 1, 1, 3, 3, 3, 3, 3, 3, 6]
for the respective polynomials with terms
d multinomial(n=3, d)
0 [1]
1 [x_1, x_2, x_3]
2 [x_1^2, x_2^2, x_3^2, x_1 x_2, x_1 x_3, x_2 x_3]
3 [x_1^3, x_2^3, x_3^3,
x_1^2 x_2, 3 x_1^2 x_3,
x_2^2 x_1, 3 x_2^2 x_3,
x_3^2 x_1, 3 x_3^2 x_2,
x_1 x_2 x_3]