[Math] How many ways to roll n with any number of dice

binomial-coefficientscombinatoricsdice

For example, if I want to roll n=6,

with 1 die it can be thrown in $$\binom {5} {0} = 1$$ way, with
2 dice $$\binom {5} {1} = 5$$
3 dice $$\binom {5} {2} = 10$$
4 dice $$\binom {5} {3} = 10$$
5 dice $$\binom {5} {4} = 5$$
6 dice $$\binom {5} {5} = 1$$
The sum of these is 32 – the correct answer, I believe.

I thought that the answer for any number n (where the number of dice is d) is
$$\sum_{d=1}^{d=n} \binom {n-1} {d-1}$$
It seems that this isn't working, though. For example the correct answer for n=8 is 125, but this equation gives me 128. Where am I going wrong? Thanks in advance.

Best Answer

The answer is surprisingly complicated. The number of ways to roll $n$ with $m$ die is the coefficient of $x^n$ in the generating function

$$(x + x^2 + \dots + x^6)^m = x^m \left( \frac{1 - x^6}{1 - x} \right)^m.$$

This can be simplified somewhat but not substantially by applying the binomial theorem to $(1 - x^6)^m$ and $\frac{1}{(1 - x)^m}$ (here you will need the binomial theorem with negative exponents).