Stars and Bars with bounds [duplicate]

This question is related to Error solving “stars and bars” type problem

I have what I thought is a fairly simple problem: Count non-negative integer solutions to the equation

$$x_1 + x_2 + x_3 + x_4 + x_5 = 23$$

such that $0 \leq x_1 \leq 9$.

The difference here is on the constraint. It bounds all the $x_i$ under 10 : $\forall i\le5$ , $0 \leq x_i \leq 9$.

$8+8+0+0+7=23$ is accepted but not $18+3+0+0+2=23$ or $11+0+0+0+12=23$ . In other words all the $x_i$ must be usual digits.

Note that bad solutions may include one or two bad $x_i$. It is the main difficulty.

What is the count of combinations ?

Edit : this question includes a double bounds and a supplemental difficulty to find the right solution.


Solution 1:

The result $6000$ provided by @igael is correct. Here is supplement to the answer of @EricStucky. It is convenient to use the coefficient of operator $[x^j]$ to denote the coefficient of $x^j$ in a series. This way we can write e.g. \begin{align*} [x^j](1+x)^n=\binom{n}{j} \end{align*}

We obtain \begin{align*} [x^{23}]&(1-x^{10})^5\sum_{k\geq 0}\binom{k+4}{4}x^k\\ &=[x^{23}]\left(1-5x^{10}+10x^{20}\right)\sum_{k\geq 0}\binom{k+4}{4}x^k\tag{1}\\ &=\left([x^{23}]-5[x^{13}]+10[x^3]\right)\sum_{k\geq 0}\binom{k+4}{4}x^k\tag{2}\\ &=\binom{27}{4}-5\binom{17}{4}+10\binom{7}{4}\tag{3}\\ &=17550-5\cdot 2380+10\cdot35\\ &=6000 \end{align*}

Comment:

  • In (1) we expand the binomial up to $10x^{20}$ since higher powers do not contribute to $[x^{23}]$.

  • In (2) we use the linearity of the coefficient of operator and apply the rule $$[x^{p-q}]A(x)=[x^p]x^{q}A(x)$$

  • In (3) we select the coefficients accordingly.

Solution 2:

We cannot have $3$ $x_i= > 9$ because the result might be $>= 30$

We can have two $x_i > 9$ because the result may be in the bounds , example $10+10+1+1+1=23$ and $11+10+1+1+0=23$

1 ) let's see the case where there is one or two $x_i > 9$

We can have one $x_i > 9$ because the result may be in the bounds , example $10+9+2+1+1=23$.

The trick would be to remove $10$ and to focalize on the distribution of the remaining $13$ ( which will include a case of twice overflow ) :

Ways to chose the overflow candidates $ = \binom {5}{1} \begin{pmatrix}23 + (5-1) -10 \\ (5-1)\end{pmatrix} = \binom {5}{1} \begin{pmatrix}17 \\ 4\end{pmatrix} = 11900$

2 ) let's see the case where there are two $x_i > 9$ .

Again, the trick is to remove twice 10 and to focalize on the distribution of the remaining $3$.

Ways to chose the twice overflow candidates $ = \binom {5}{2} \binom {23 + (5-1) -10-10}{5-1} = \binom {5}{2} \binom {7}{4} = 350$

These last combinations had been counted twice and then we must deduced it once.

3 ) Now ignoring the bounds limitation, we have a total of combinations of $\begin{pmatrix}23 + (5-1) \\ (5-1)\end{pmatrix} = \begin{pmatrix}27 \\ 4\end{pmatrix} = 17550$

The result must be $17550 - (11900 - 350) =6000$