2

What is the number of solutions of -

$x_1 + x_2 + x_3 + \dots + x_n = k$

$(1)$ When all the $x_i$ are between $0$ and $r$.

$(2)$ What if the order of the $x_i$ doesn't matter?

I have doubts about the solution to the first part being the multinomial coefficient. For example, n=3, k=3, r=2. We get (1,1,1) and the 6 permutations of (0,1,2). So the total is 7. I don't think any multinomial coefficient will give 7.

EDIT: This question was for a video I was making on hypercubes. If you're interested, check it out :) https://www.youtube.com/watch?v=KuXnrg1YpiY

Rohit Pandey
  • 6,803

2 Answers2

2
  • If the order does not matter, it is a money changing problem with coins $\{0,\dots,r\}$. We have the generating function $$\sum_{k,n\geq 0} p(k,n,r) x^k y^n = \frac{1}{(1-y)(1-yx)(1-yx^2)\cdots(1-y x^r)} = \prod_{j=0}^r (1-yx^j)^{-1}. $$ You can obtain the values of $p(k,n,r)$ by taking the appropriate number of derivatives, i.e., $$p(k,n,r) =\frac{1}{k! \,n!} \frac{\partial^k}{\partial x^k} \frac{\partial^n}{\partial y^n} \prod_{j=0}^r (1-yx^j)^{-1} \Big|_{x,y=0}$$

  • If the order matters, we can obtain $p(k,n,r)$ by the coefficient of $x^k$ in $$ \left(\sum_{i=0}^r x^i \right)^n =\left(\frac{1-x^{r+1}}{1-x} \right)^n $$ i.e. the generating function in this case is given by $$ \sum_{k}p(k,n,r) x^k = \left(\frac{1-x^{r+1}}{1-x} \right)^n$$ and we have $$p(k,n,r) = \frac{1}{k!}\frac{\partial^k}{\partial x^k} \left(\frac{1-x^{r+1}}{1-x} \right)^n \Big|_{x=0}.$$

Fabian
  • 23,360
  • For the first part, I'm actually not quite sure its multinomial anymore. For example, n=3, k=3, r=2. We get (1,1,1) and the 6 permutations of (0,1,2). So the total is 7. I don't think any multinomial coefficient will give 7. For the second part, let me study your solution. – Rohit Pandey Apr 16 '17 at 07:35
  • 1
    @RohitPandey: fixed it. Please note the new solution. – Fabian Apr 16 '17 at 09:22
2

(1) When order of the summands matters, you are asking for the (weak) compositions of $k$ in $n$ parts with restricted parts at most $r$, i.e from $\{0,\ldots,r\}$.

The binomial formula (stars-and-bars) is correct when $r$ (the bound on largest part) is omitted or sufficiently large as not to matter.

When $r$ is small enough to restrict the solutions, the resulting problem has been referred to in the literature as "compositions inside a rectangle". See for example:

B. E. Sagan, "Compositions inside a rectangle and unimodality", J. Algebraic Combin. 29 (2009), 405–411.

A discussion of these is given by the online paper (end of Section 6.2)

S. Eger, "Restricted Weighted Integer Compositions and Extended Binomial Coefficients", Journal of Integer Sequences, Vol. 16 (2013)

There was an earlier Question here that also addressed these "restricted compositions". The OP there accepted a self-posted Answer pointing to this paper by M. Abramson, which appears to have been published as:

M. Abramson, "Restricted combinations and compositions", Fibonacci Q. (1976), 439–452

(2) You are asking, when order does not matter, for the integer partitions of $k$ with at most $n$ parts and largest part at most $r$. A related problem asks also that the summands all be distinct, and there is a simple way to convert a problem of that form into the one described here (and conversely). Notation for such countings vary among authors.

Counting the number of such solutions is not especially simple, although it yields readily to recursive solution/dynamic programming methods for modest values of $k$.

I've often turned to an online calculator (written in Java, by Henry Bottomley) for such modest computations, but running Java programs in modern browsers is no longer an easy task (due to security concerns about NPAPI, the interface Java uses in browsers).

Many software packages address the problem of counting integer partitions through (brute force) listing of all possible solutions. In a sense the latter is easier algorithmically, because we cannot expect to improve much in the output of a long list of solutions. A recently updated broad survey of capabilities ("Software for enumerative and analytic combinatorics") by Andrew MacFie (2013/2016) describes "the capabilities that the packages offer as well as some of the algorithms used, and provide[s] links to original documentation."

hardmath
  • 37,015