Number of solutions for $x_1 + x_2 + x_3 + x_4 = 30$ with $(x_1,x_2,x_3,x_4) \in \{-10,...,19,20\}^4$ I have to solve the following problem: calculate the number of solutions for $$x_1 + x_2 + x_3 + x_4 = 30$$ with $$(x_1,x_2,x_3,x_4) \in \{-10,...,19,20\}^4$$.
I know that if the domain is $$\mathbb{N}$$ the solution is as simple as
$$
\binom{n - 1}{k - 1}=\binom{30 - 1}{4 - 1}=\binom{29}{3}
$$
But the negative values are confusing me.
I wrote a little Java program to calculate the result, it displays 17266.
Could somebody please help me?
 A: For any formal Laurent series $\sum\limits_{k=-\infty}^\infty \alpha_k t^k$ in indeterminate $t$, let $[t^n] \sum\limits_{k=-\infty}^\infty \alpha_k t^k$ be a short hand for the coefficient $\alpha_n$ associated with the monomial $t^n$.
If one expand following product of sums,
$$\sum_{x_1=-10}^{20} (tz_1)^{x_1}
\sum_{x_2=-10}^{20} (tz_2)^{x_2}
\sum_{x_3=-10}^{20} (tz_3)^{x_3}
\sum_{x_4=-10}^{20} (tz_4)^{x_4}
$$
and look at coefficients of $t^{30}$ as a finite Laurent series in $z_1,z_2,z_3,z_4$, one will notice
there is an one-one correspondence between solutions of $x_1 + x_2 + x_3 + x_4 = 30$ and monomials $z_1^{x_1} z_2^{x_2} z_3^{x_3} z_4^{x_4}$ with matching exponents.
This means the number of solutions of $x_1 + x_2 + x_3 + x_4 = 30$, let's call it $\mathcal{N}$, can be computed by first setting $z_1, z_2, z_3, z_4$ to $1$ and then extract the coefficients of $t^{30}$ in above expression. In other words,
$$\begin{align}
\mathcal{N} &= [t^{30}] \left( \sum_{k=-10}^{20} t^k\right)^4
= [t^{30}] \left(t^{-40} \sum_{k=0}^{30} t^k \right)^4
= [t^{70}] \left(\frac{1 - t^{31}}{1-t}\right)^4\\
&= [t^{70}] \frac{1 - 4 t^{31} + 6 t^{62} - 4t^{93} + t^{124} }{(1-t)^4}\\
&= [t^{70}]\frac{1}{(1-t)^4}
 -4[t^{39}]\frac{1}{(1-t)^4}
+ 6[t^8]\frac{1}{(1-t)^4}
\end{align}$$
Notice for any positive integer $\ell$, we have  following power series expansion in $t$:
$$\frac{1}{(1-t)^\ell} = \sum_{n=0}^\infty \binom{n+\ell-1}{\ell-1} t^n$$
This implies $\displaystyle\;[t^n]\frac{1}{(1-t)^4} = \binom{n+3}{3}$. As a result,
$$\begin{align}
\mathcal{N} 
&= \binom{70+3}{3}
- 4\binom{39+3}{3}
+ 6\binom{8+3}{3}\\
&= \binom{73}{3} - 4\binom{42}{3} + 6\binom{11}{3}\\
&= 17266
\end{align}
$$
A: The same expression reached by achille-hui can also be achieved through some inclusion-exclusion reasoning on the limits imposed, using the transformed form of $$y_1 + y_2 + y_3 + y_4 = 70$$ with $$(y_1,y_2,y_3,y_4) \in \{0,...,29,30\}^4$$.
Without the constraint, this is a straight stars-and-bars evaluation of dividing 70 items into four groups, $\binom {73}{3}$.
We can then find the constraint-breaking cases for each variable in turn by pre-allocating one more than the limit ($31$) to each variable in  turn and repeating the division on the remaining items, giving four cases of $\binom {42}{3}$ of above-constraint cases to remove.
Finally we can find the double-counted cases of two constraints being simultaneously broken (the maximum possible), again preallocating $31$ to each of two chosen variables in each combination, $\binom 4 2=6$ cases, and dividing to give $\binom {11}{3}$.
The inclusion-exclusion result is then $$\binom {73}{3} -4\binom {42}{3} +6\binom {11}{3}$$ as before.
A: Assuming $0$ is included in $\Bbb {N}$, let $Y_i = X_i +11$,
then the problem transforms to
$Y_1 + Y_2 +Y_3+Y_4 = 74,\;$subject to$\,\; 1\leq{Y_i}<31$
Applying "stars and bars" formula and inclusion-exclusion, we get
(All ways) - (at least one variable breaks upper limit) + (at least two variables break upper limit)
$\binom{74-1}{4-1} - \binom 4 1\binom{74-1-31}{4-1} + \binom 4 2\binom{74-1-62}{4-1}$
= $\binom{73}3 - \binom 4 1 \binom{42}3 + \binom4 2\binom{11}3 = 17266$

Further simplification
I added $11$ rather than $10$ to transform the problem as you wanted, but just realized that it also had the advantage of putting it into a larger class of familiar problems  regarding sum obtained from rolling dice.
The problem is to obtain a sum of $74$ rolling a $31$ faced die $4$ times. Now the median value of the sum $= 4*16 = 64$, and the required sum is $74$ which is $10$ above the median, hence by symmetry, will be identical to the number of ways to get $10$ below the median, viz. $54$
The answer is then obtained more simply as $\binom{53}3-\binom4 1\binom{22}3 = 17266$
In this formulation, only one variable can break the upper limit, in some others, you might not need to apply inclusion-exclusion at all !
Transforming a problem into one of a familiar class of problems often leads to new insights !
We can even encapsulate the whole thing in a formula (ignoring the final twist) as
$$W(n,k,D,j)= \sum_{j=0}^{\lfloor{\frac{n-k} D}\rfloor}(-1)^j \binom{k} {j}\binom{n-1-Dj}{k-1}$$
where $W$ = answer, $n$ = desired sum, $k$ = number of throws, $D$ is number of faces on die, and $j$ is the counter
A: If you have two dices and you throw them you have a probability of
1/36 -> sum is 2
2/36 -> sum is 3
3/36 -> sum is 4
...
6/36 -> sum is 7
...
1/36 -> sum is 12
if you do it  with 3 dices:
1/216, 3/216, 6/216, ... (Tartaglia)


For 4 dices is the next diagonal (1, 4, 10, 20, 35)
$$x_1 + x_2 + x_3 + x_4 = 30$$ with $$(x_1,x_2,x_3,x_4) \in \{-10,...,19,20\}^4$$
Is equivalent to:
$$x_1 + x_2 + x_3 + x_4 = 70$$ with $$(x_1,x_2,x_3,x_4) \in \{0,...,30\}^4$$
out of $31*4$, yours is the 70th element, since the mid element is 31*4/2=62, so 124-70=54, where the first is $x_1+x_2+x_3+x_4=0$ so it is $\binom{54+3}{3}=55*56*57/6=29260$
Which makes me think your little java program might have a mistake.
