1

I have the following equation

$$x_1+x_2+x_3+x_4+x_5+...+x_n= M$$

and constraints is all elements should in between $1\leq x_i\leq k$. how to find the solution for the above equation.

I can easily found the number of solution of equation where $1\leq x_i$
Number of Solution: ${M-1 \choose n-1}$

Number of solution of equation where $k+1\leq x_i$
Number of Solution: ${M-n*(k+1)-1 \choose n-1}$.

But how to find the solution which satisfy the required criteria ?

Marvel
  • 340
  • 1
  • 11
  • You should specify integer solutions (x_1,...) – quasi May 10 '17 at 09:20
  • Anyway, do you have particular values of $n,M$ that you are trying to analyze? – quasi May 10 '17 at 09:21
  • @quasi Thanks for pointing out the type , the value of n,m and k can be any integer value , quite be large also in range – Marvel May 10 '17 at 09:22
  • There is one coefficient trick. That turns out to be good only if you have specific values of the parameters. – Sayan May 10 '17 at 09:23
  • 1
    Your count for the case $k+1 \le x_i$ is not correct. It should be $$\binom{M-nk-1}{n-1}$$ – quasi May 10 '17 at 09:24
  • @quasi why only nk ? – Marvel May 10 '17 at 09:28
  • If you don't have a specific pair of values for $n,M$, are there any known relationships (.e.g., inequalities) between $n,M$? – quasi May 10 '17 at 09:28
  • After subtracting $k$ from each $x_i$, now they're arbitrary positive integers. – quasi May 10 '17 at 09:29
  • @quasi value of all the parameter are such that there should be at least one valid solution – Marvel May 10 '17 at 09:31
  • That's not enough information to get a general formula for the count. – quasi May 10 '17 at 09:32
  • Let say N=50 , K=300 and M=1000 – Marvel May 10 '17 at 09:38
  • Ask that as a separate question with those values and you'll surely get some answers. – quasi May 10 '17 at 09:44
  • A suggestion: write $y_i=1+x_i$, replace $M$ by $M-n$ and get rid of the tiresome lower constraint. I think any explicit case is "easy", the one you suggest is, I reckon the sum/difference of four terms each the product of a couple of binomial coefficients. The generating function for the problem is something like $\frac{(1-x^k)^n}{(1-x)^k}$ from which you can easily get an expression for the answer, but I don't see how to simplify it. – ancient mathematician May 10 '17 at 10:28

2 Answers2

1

We can use inclusion/exclusion principle here. The total number of solutions of equation such that $x_i \ge b_i k + 1$ is $\binom{M - k\sum_i b_i - 1}{n - 1}$, where $b_i \in \{\,0, 1\,\}$. Then the number of solutions such that $1 \le x_i \le k$ is $$\binom{M - 1}{n - 1} - \binom{n}{1} \binom{M - k - 1}{n - 1} + \binom{n}{2} \binom{M - 2k - 1}{n - 1} - \cdots + (-1)^{\left\lfloor \frac{M - n}{k}\right\rfloor} \binom{n}{\left\lfloor \frac{M - n}{k}\right\rfloor} \binom{M - \left\lfloor \frac{M - n}{k}\right\rfloor k - 1}{n - 1}\\ = \sum_{\ell = 0}^{\left\lfloor \frac{M - n}{k}\right\rfloor}(-1)^{\ell}\binom{n}{\ell}\binom{M - \ell k - 1}{n - 1}.$$

Smylic
  • 6,715
0

Here is an answer based upon generating functions.

The constraints $1 \leq x_i \leq k$ can be encoded for each $x_i$ as \begin{align*} z+z^2+\cdots+z^k=z\frac{1-z^k}{1-z}\tag{1} \end{align*}

In the following we denote with $[z^n]$ the coefficient of $z^n$ of a series.

Since we are looking for $x_1+x_2+\cdots+x_n=M$ we calculate according to (1) \begin{align*} \color{blue}{[z^M]\left(z\frac{1-z^k}{1-z}\right)^n}&=[z^{M-n}]\frac{(1-z^k)^n}{(1-z)^n}\tag{2}\\ &=[z^{M-n}]\sum_{l=0}^n(-1)^l\binom{n}{l}z^{lk}\sum_{j=0}^\infty\binom{-n}{j}(-z)^j\tag{3}\\ &=\sum_{l=0}^{\lfloor(M-n)/k\rfloor}(-1)^l\binom{n}{l}[z^{M-n-lk}]\sum_{j=0}^\infty\binom{n+j-1}{n-1}z^j\tag{4}\\ &\color{blue}{=\sum_{l=0}^{\lfloor(M-n)/k\rfloor}(-1)^l\binom{n}{l}\binom{M-lk-1}{n-1}}\tag{5} \end{align*}

Comment:

  • In (2) we apply the rule $[z^{p-q}]A(z)=[z^p]z^qA(z)$.

  • In (3) we use the binomial theorem and the binomial series expansion.

  • In (4) we use the linearity of the coefficient of operator and apply again the rule as in (2). We restrict the upper limit of the series accordingly, since the exponent of $z^{M-n-lk}$ is non-negative. We also use the binomial identity $\binom{-p}{q}=\binom{p+q-1}{p-1}(-1)^q$.

  • In (5) we select the coefficients of $z^{M-n-lk}$.

Markus Scheuer
  • 108,315