2

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?

EBP
  • 1,388
  • 3
    Let $y_i=x_i+10$. Then the problem transforms to counting the number of solutions of $y_1+y+2+y_3+y_4=70$ subject to $0\le y_i\le 30$. This is still not easy, but at least you don't have any negative numbers to deal with. – TonyK Jan 06 '21 at 12:41
  • @TonyK first, thank you, I have two questions, is the +2 in your comment a typo? And is it possible to just add 11 so that I do not have to deal with the zero? –  Jan 06 '21 at 12:46
  • Yes, $y+2$ is a typo for $y_2$. And you can add $11$ if you like, but that is a backwards step in my opinion. – TonyK Jan 06 '21 at 12:49
  • Why do you think, that this is a backwards step? And could you please verify my "java solution"? –  Jan 06 '21 at 12:52
  • Certainly not! Go to Code Review for that. – TonyK Jan 06 '21 at 13:06
  • Thanks for the link, I meant not the code I meant the solution of 17266 possible solutions for the problem. –  Jan 06 '21 at 13:09
  • It is worth pointing out the difference between the usage of $\Bbb N$ where some mean to have it be the strictly positive integers not including zero while others mean to have it be the non-negative integers which does include zero. In the one case you do have $\binom{n-1}{k-1}$ where zero is not allowed and in the other case $\binom{n+k-1}{k-1}$ if zero is allowed. Different people prefer different explanations and use one identity over the other as the basis of their work. In either event, using a change of variable like TonyK suggests is the common first step here. – JMoravitz Jan 06 '21 at 13:21
  • It will continue then with inclusion-exclusion over the events that you have violated the upper bound conditions on whichever of the variables. Counting how many violate a particular upper bound can also be found via change of variables in a similar fashion, noting it may be possible to violate multiple simultaneously. – JMoravitz Jan 06 '21 at 13:22
  • Thank you, this helped a lot. –  Jan 06 '21 at 13:25
  • 1
    Checkout this https://math.stackexchange.com/questions/553960/extended-stars-and-bars-problemwhere-the-upper-limit-of-the-variable-is-bounded answer. You could create a non-negative version of your problem first and then use the results from this discussion to include the upper bound. – David Scholz Jan 06 '21 at 13:41

4 Answers4

2

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} $$

achille hui
  • 122,701
0

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)

enter image description here

enter image description here

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.

yugikaiba
  • 156
0

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.

Joffan
  • 39,627
  • Thank you for this answer, could you please further eleborate the last part with the 6 * (11 over 3)? The part with 4 * (42 over 3) is perfectly clear. –  Jan 06 '21 at 14:47
  • 1
    There are 6 possible ways to choose which two variables break the 30 limit. These 6 cases have been double-counted (double removed from the total) in the previous adjustment for single-variable constraint breaking.. – Joffan Jan 06 '21 at 14:54
  • Thank you, this helps a lot :) –  Jan 06 '21 at 14:57
  • @JohnDoe usually the expression $\binom {11}3$ is said as "11 choose 3". You can use small MathJax code in comments like $\binom {11}3$ – Joffan Jan 06 '21 at 15:08
  • Thank you, I will use the correct notation next time :) –  Jan 06 '21 at 15:12
0

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