0

I want to find the number of solutions for $$x_1 + x_2 + x_3 +\ldots + x_k = n$$ where:

  • $x_i$ is a positive integer $\forall i \in {1, \dots, k}$.
  • if $i \neq j$ then $x_i \neq x_j$, for all $i, j \in {1\dots k}$.
  • $n$ is a positive integer.

I've tried (unsuccessfully) to play around with generating functions and I'm out of ideas. Any help will be appreciated!

  • If $n = 3$ do you count $1+2$ and $2+1$ as the same solution or two different solutions. Is $k$ given? Btw, this is a variant of the coin change problem. In this case, you have coins of denominations $1$ through $n$ and can use each denomination at most once. The coin change problem asks what is the minimum number of coins needed to make $n$, but this one asks how many ways can you make $n$.

    https://en.wikipedia.org/wiki/Change-making_problem

    – joseville Mar 28 '23 at 23:07
  • hey thanks for your answer, I actually don't mind! it'd be just multiplying/dividing by $k!$ if I'm not mistaken. I'll looking into that Wikipedia article – Matías Santurio Mar 28 '23 at 23:09
  • Hint: How do you convert "distinct integers" to a different set of variables without that constraint? – Calvin Lin Mar 28 '23 at 23:24
  • 1
    You want the number of solutions for fixed $n$ and $k$, or for fixed $n$ and variable $k$? – bof Mar 28 '23 at 23:39
  • Both $n$ and $k$ are fixed – Matías Santurio Mar 28 '23 at 23:54
  • 1
    This might not pan out, but I wonder if it can be solved with dynamic programming? Let $D(m, j, X)$ be the number of ways to make $m$ with $j$-coins using coins larger than or equal to $X$. Then $D(m, j, X) = \sum_{x=X}^n D(m-x, j-1, x+1)$. I think the $x+1$ encapsulates the distinct coins constraint. The answer would be $D(n, k, 0)$. Some base cases would be $D(m, 1, X) = 1$ if $X \leq m$ and $D(m, j, X) = 0$ if $X > m$. Just some ramblings. Might pan out or not and even if it does, there might be a better way to solve this using other methods. – joseville Mar 29 '23 at 00:05
  • $\displaystyle\left[x^n\frac{y^k}{k!}\right]\prod_{n=1}^{\infty}(1+x^ny)$ – Alexander Burstein Apr 02 '23 at 02:44

4 Answers4

3

Elaborating on my hint (If you're stuck, explain what you've tried):
How do you convert "distinct integers" to a different set of variables without that constraint?

First consider when $x_i$ are in increasing order.
Define $ a_1 = x_1, a_2 = x_2 - x_1, a_3 = x_3 - x_2, \ldots $.
Show that these $a_i$ are positive integers.
Show that $ x_1 = a_1, x_2 = a_1 +a_2, x_3 = a_1+a_2+a_3, \ldots $.
Show that the condition is $ ka_1+(k-1)a_2+(k-2)a_3+\ldots + 1a_k = n$, with the only constraint being that the variables are positive integers.

Can you create the corresponding generating function for this scenario?

$$ \frac{ x^{k(k+1)/2} } { ( 1-x)(1-x^2)\ldots ( 1-x^{k}) } $$

Finally, remember to multiply by $k!$ due to the "$x_i$ are in increasing order".

Calvin Lin
  • 77,541
1

Accroding to this paper, we consider $C(n, k)$, the number of compositions of $n$ with $k$ distinct parts.

we then have, $$ C(n, k)=C(n-k, k)+k C(n-k, k-1) $$ We deduce this by subtracting 1 from each part of the distinct compositions of $n$ into $k$ parts. Then those distinct compositions in which no part is 1 have a one to one correspondence with distinct compositions of $n-k$ into $k$ parts, whereas those distinct compositions with a part 1 correspond to a distinct composition of $n-k$ into $k-1$ parts with an additional zero part which can occur in any of $k$ positions.

ClearAll["Global`*"]

C1[n_, k_] := 0 /; n <= 0 C1[n_, 1] := 1 C1[n_, k_] := C1[n - k, k] + k*C1[n - k, k - 1]

Table[C1[n, k], {n, 1, 6}, {k, 1, 3}] // Grid

$$ \begin{array}{cccccccccccccccccccc} 1 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 2 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 2 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 4 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 4 & 6 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 6 & 6 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 6 & 12 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 8 & 18 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 8 & 24 & 24 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 10 & 30 & 24 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 10 & 42 & 48 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 12 & 48 & 72 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 12 & 60 & 120 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 14 & 72 & 144 & 120 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} & \text{} \\ 1 & 14 & 84 & 216 & 120 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} & \text{} \\ 1 & 16 & 96 & 264 & 240 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} & \text{} \\ 1 & 16 & 114 & 360 & 360 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} & \text{} \\ 1 & 18 & 126 & 432 & 600 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & \text{} \\ 1 & 18 & 144 & 552 & 840 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ \end{array} $$

0

This is a long winded comment.
This is not an answer.

First of all, the OP (i.e. original poster) has indicated at least some involvement with generating functions, which I am totally ignorant of. In my experience and observation of others on MathSE, this type of problem is best attacked by either generating functions or Stars and Bars.

For Stars and Bars theory, see this article and this article. As I discuss below, I think that Stars and Bars is not the right approach, for this type of problem.

So, I think that the OP should show work, in accordance with this article on MathSE protocol before someone provides them with an answer.


$\underline{\text{Stars and Bars discussion}}$

The $k$ variables, which must be distinct can be permuted in $~k!~$ ways. So, you can reserve the factor $~(k!),~$ and then assume that

$$x_1 < x_2 < \cdots < x_k.$$

For $~i \in \{2,3,\cdots,k\},~$
let $~y_i = x_i - x_{i-1} \implies y_i \geq 1.$

This implies that for $~j \in \{2,3,\cdots,k\},~$ that $~x_j = x_1 + y_2 + y_3 + \cdots + y_j.~$

So, the problem has now been converted into counting the number of solutions to

  • $k(x_1) + (k-1)y_2 + (k-2)y_3 + \cdots + y_k = n ~: ~n \in \Bbb{Z^+}.$

  • $x_1, y_2, y_3, \cdots, y_k \in \Bbb{Z^+}.$

At this point, the natural move is to use the further change of variables:

$$u_1 = x_1 - 1, ~~u_i = y_i - 1 ~: ~i \in \{2,3,\cdots,k\}.$$

This transforms the problem into

  • $\displaystyle k(u_1) + (k-1)u_2 + (k-2)u_3 + \cdots + u_k = n - \left[ ~\frac{(k+1)k}{2} ~\right].$

  • $u_1, u_2, u_3, \cdots, u_k \in \Bbb{Z_{\geq 0}}.$

My reaction at this point is $\color{red}{\text{so what}}$.
Unless I am missing something, even this alteration of the problem still doesn't seem to lend itself to Stars and Bars.

user2661923
  • 42,303
  • 3
  • 21
  • 46
  • Sorry I'm not following, why are you so fixed on stars and bars? I never even mentioned it – Matías Santurio Mar 28 '23 at 23:44
  • @MatíasSanturio I was attempting to infer (perhaps wrongly), that the problem should be attacked by generating functions. Therefore, I was making the further inference that the OP (i.e. original poster) should not be provided with assistance until the OP improves the quality of their posting, in accordance with the cited article on MathSE protocol. – user2661923 Mar 28 '23 at 23:46
  • Do you mean you want me to tag the question with generating-functions? ` – Matías Santurio Mar 28 '23 at 23:49
  • @MatíasSanturio That's probably a good idea. But the thrust of my response is to ask you to read the protocol article and then improve the quality of your posting, accordingly. – user2661923 Mar 28 '23 at 23:49
  • Lol, there are easier ways to communicate that, will do! – Matías Santurio Mar 28 '23 at 23:49
  • 2
    @MatíasSanturio I think that it was important, both for you and for the forum as a whole to demonstrate that Stars and Bars is not the way to go here. – user2661923 Mar 28 '23 at 23:51
  • While I do not disagree that Stars and Bars doesn't seem that helpful, to be fair what you have shown is "Stars and Bars as user2661923 knows it is not the way to go here", though you did condition on "Unless I am missing something". $\quad$ You have not demonstrated that "there is no creative approach whatsoever which might allow us to use Stars and Bars, perhaps combined with other ideas like Principle of Inclusion and Exclusion" – Calvin Lin Mar 29 '23 at 14:46
  • @CalvinLin On the one hand, in the past, I have looked for creative ways to use Stars and Bars for this particular problem, and come up empty. On the other hand, I am forced to concede your point. As far as a creative approach involving Inclusion-Exclusion goes, I would regard that as wizardry. Suppose that you let $~S~$ be the set of all solutions, without regard to the constraint that the coefficient of $~x_i,y_i~$ must be a multiple of $~(k+1-i),~$ and that you let $~S_i~$ denote the subset of $~S~$ such that the constraint on $~x_i,y_i~$ is violated. ...see next comment – user2661923 Mar 29 '23 at 16:10
  • @CalvinLin It seems to me that the computation of $$T_r = \sum_{1 \leq i_1 < i_2 < \cdots < i_r \leq k} ~\left| ~S_{i_1} ~\cap ~S_{i_2} ~\cap ~\cdots ~\cap ~S_{i_r} ~\right| $$ is a nightmare. – user2661923 Mar 29 '23 at 16:15
  • FWIW The computation of GF is also a nightmare. In fact, it offers no simplification despite the nice form, as we still essentially have to do the hard work of finding solutions to $\sum i a_{k+1-i} = n$. EG If we wanted to find $n= 9, k = 3$, expanding the denominator and finding the coefficient of $x^9$ is essentially finding solutions to $ a + 2b + 3c = 9$, Even the term-wise expansion of the product could be viewed as first solving $ a + 2b = 9 - 3c$. $\quad$ I was thinking of applying PIE to the original, where $S_i \cap S_j \Leftrightarrow x_i = x_j$. – Calvin Lin Mar 29 '23 at 16:27
  • @CalvinLin Interesting. I suspected but wasn't sure that GF computation would not be elegant. Also, nice idea of applying PIE to original problem. However, the idea may need re-structuring. PIE normally would have $~S_i,~$ rather than $~S_i \cap S_j,~$ directly associated with the violation of a specific constraint (e.g. $~x_i \geq x_{i+1}~$). So, if this re-structuring is needed, then (I could be wrong here) it seems that the application of PIE would remain problematic. ...see next comment – user2661923 Mar 29 '23 at 16:46
  • @CalvinLin If you actually post any less-nightmarish approach of any sort, that does not involve generating functions, as a separate answer, please leave me another flagging comment. I would be interested in reading your answer. – user2661923 Mar 29 '23 at 16:49
  • See Aspen's answer. Finding some bijection with smaller cases was the next approach I would have taken, and it turns out that there is a nice setup. It only works for this "distinct integers", as opposed to the more general $\sum C_i a_i = n$. – Calvin Lin Mar 29 '23 at 17:00
  • The corresponding PDF article that Aspen's answer references does not seem to not be freely available. Is there a free online copy? – user2661923 Mar 29 '23 at 17:09
0

A slight variation on stars and bars.

Let $1+1+1+...+1=n$, where there are $n$ ones.

Pick a plus sign. Add up all the ones to the left of the plus sign, and all the ones to the right, now you have an expression of the form $x+y=n$. There are as many ways to add two positive numbers to get $n$ as there are ways to pick 1 plus sign out of the $(n-1)$ total plus signs.

If you pick 2 plus signs instead, then add all ones to the left of the left most plus signs, the ones to the right of the right most plus sign, then the remaining 1's to get an expression of the form $x+y+z=n$.

This can be generalized. There are $\binom{n-1}{k-1}$ ways to add up $k$ numbers to sum to $n$.

This doesn't eliminate cases where addends are the same and it doesn't account for commutativity of addition.

You can account for commutativity by dividing by $k!$ if the addends are all different.

How do you guarantee they are different?

TurlocTheRed
  • 6,458