-1

I struggle to get the formula for combinations with repetitions. I don't like metaphors and analogies widely used in the other explanations like bins/bars/bookshelves. It seems unnatural to me to introduce new entities. I want to draw out the formula by "debugging" each step of the flow. Take as an example a string ABC and all 2-letter combinations we can get from it. It's clear that this is 6 (done by hand): aa, ab, ac, bb, bc, cc. Correct my steps:

  1. I take an 'A'. Now it's just 'BC'. But since it must be with repetitions, I put another 'A' as a replacement, recovering the original string 'ABC'.
  2. I take another 'A'. This again leaves me with 'BC', but no need to put another 'A' back, since we've just got our 1st complete combination - 'AA'. Right?

Same for B and C. Yet I still don't see how can I recover the formula from this observation. Let's reverse engineer it.

First of all, the nominator: (n + k - 1)!

It's 24 in my case. But what exactly does it represent? 6 times 4-letter strings like 'AABC' or smth else? Then the denominator. In a "stars&bars" pattern it's explained as filtering out (n - 1)! bars and k! same-letter strings (ab=ba). I only get the k! part. What am I exactly reducing by (n - 1)! (if I intentionally want to avoid resorting to "bins" and "delimiters", as it's not clear for me so far what do I need to delimit in this case).

Mike Earnest
  • 84,902
  • First, you should not think of it as "reducing by $(n-1)!$". You should think of reducing by $k!$, because you are listing $k$ things but the order in which you list them doesn't matter. The $(n-1)!$ really comes from the other process, where you have $n+k-1$ possibilities and you must choose $k$ of them (the additional $k-1$ possibilities come from repeating a previously chosen letter). – Arturo Magidin May 13 '24 at 22:14
  • So here you must pick A, B, or C; then choose either a new one, or repeat the previous one. So you can think of $3+(2-1)$ choices: pick two from among the letters A, B, C, and "Repeat the other one". And after you pick $k=2$ from among the $n+(k-1)$ possibilities, the order in which you picked them does not matter, so you have to divide by $2!$, the $2$ being not $n-1$, but the length of the string. $k$. – Arturo Magidin May 13 '24 at 22:17
  • See the two proofs here. In both cases, you are figuring out that you need to find $\binom{n+k-1}{k}$, rather than expressing it as $\binom{n+k-1}{n-1}$ (though of course they are equal). – Arturo Magidin May 13 '24 at 22:20
  • That "pick two from among the letters A, B, C, and "Repeat the other one" part confuses me :( I thought I'm always picking from the string 'ABC', not from the string 'ABC' + the previous choice. Like, our choices are only these 3 letters, aren't they? – mohican93 May 13 '24 at 22:40
  • You can "code" your choices so that they correspond to a choice from among the letters A, B, C, but are not written that way. For example, surely you see that choosing from the letters A,B, C is "essentially the same" as choosing from the numbers 1, 2, 3. And choosing two out of 1,2,3 with repetition is the same as choosing two from 1,2,3,4 without repetition by "understanding" the pair $n_1,n_2$, with $n_1\lt n_2$ as representing the pair $n_1,(n_2-1)$ from among the original 1,2,3. So 11$\leftrightarrow$12, 13$\leftrightarrow$14, etc. – Arturo Magidin May 14 '24 at 01:17

2 Answers2

0

In general, suppose that you have an alphabet of $~\{L_1, L_2, \cdots, L_k\} ~: ~k \in \Bbb{Z_{\geq 2}},$ and you wish to compute the number of corresponding $~n~$ character strings.

This is in fact a Stars and Bars problem. For Stars and Bars theory, see this article and this article.

For $~i \in \{1,2,\cdots,k\},~$ let $~x_i~$ denote the number of occurrences of the letter $~L_i~$ in the $~n~$ character string.

Then, the number of $~n~$ character sequences, where each letter may be selected any non-negative-integer number of times, and where the order that the $~n~$ (not necessarily distinct) letters appear in the $~n~$ character sequence is deemed irrelevant, must be the exact same as the number of solutions to

  • $x_1 + x_2 + \cdots + x_k = n.$
  • $x_1, ~x_2, ~\cdots, ~x_k \in \Bbb{Z_{\geq 0}}.$

By basic Stars and Bars theory, as proven in the first Stars and Bars link above, the number of solutions must be $~\displaystyle \binom{n + [k-1]}{k-1}.$

So, to resolve your confusion, you need to :

  • Intuitively understand why the number of $~n~$ character strings is the same as the number of solutions to the above bullet pointed problem.

  • Review the first Stars and Bars link, which proves the validity of the formula.

If you have an issue with the first bullet point directly above, leave a comment/question directly below this answer, and I will try to explain it further.

user2661923
  • 42,303
  • 3
  • 21
  • 46
  • Thank you, I'll take some more time then to work on this pattern until it starts to make sense. I wanted to isolate this problem as much as possible and avoid the proof that includes "delimiters". But maybe it could actually be helpful – mohican93 May 14 '24 at 20:30
0

Write a "code" for your choices, to make it easier to keep track of them.

Let's say you need to choose $k$ numbers from among $1,2,\ldots,n$, with repetitions allowed. We will "code" each choice in a way that corresponds to choosing without repetitions from a larger collection.

Namely, when we have a choice, let us first agree that we will write the digits in nondecreasing order. So for your set for choosing two from among $1,2,3$ (corresponding to $A,B,C$), we would write $$11, 12, 13, 22, 23, 33.$$ Now, let us add $0$ to the first digit, $1$ to the second digit. So we will code the six choices above as $$12, 13, 14, 23, 24, 34.$$ respectively.

Note that under this code, the first digit must be among $1,2,3$; the second digit must be among $2,3,4$, and there is no repetition. So we are always choosing two digits from among $1,2,3,4$, without allowing repetition, and where the order does not matter.

Conversely, suppose you choose two digits from among $1,2,3,4$, without repetition. Now list them in order. The possibilities are: $$12, 13, 14, 23, 24, 34.$$ Note that the first digit must be between $1$ and $3$; the second must be between $2$ and $4$. Let us convert each of these two digit numbers into a two digit number in which all digits are among $1,2,3$, allowing repetition, by leaving the first digit as-is, and subtracting one from the second digit. That makes these six choices correspond to $$11, 12, 13, 22, 23, 33.$$

So making a choice of two digits from among $1,2,3$ allowing repetition and where the order is irrelevant, is equivalent to making a choice of two digits from among $1,2,3,4$, without allowing repetition and where the order is irrelevant. Thus, the number of ways of choosing twice from among $1,2,3$ allowing repetition and where order does not matter is the same as the number of ways of choosing twice from $1,2,3,4$ without allowing repetition and where order does not matter.

More generally, if we are trying to make $k$ choices from among $1,2,3$ allowing repetition (and where order does not matter), we can "code" any such choice by listing them in nondescending order, and adding $1$ to the choice, $2$ to the third choice,... and $k-1$ to the $k$th choice. This will give a sequence of $k$ numbers chosen from $1,2,3,3+1,\ldots,3+(k-1)$, without repetition, where order does not matter. That is, the count is $$\binom{3+(k-1)}{k} = \frac{(3+(k-1))!}{k!(3-1)!}.$$ The $k!$ is really because the order in which we make choice does not matter, and the $\frac{3+(k-1)!}{(3-1)!}= \frac{(3+(k-1))!}{\bigl(3+(k-1) - k\bigr)!}$ is the usual count for choosing $k$ times from among $3+(k-1)$ possibilities without replacement, where order matters.

If instead of starting with $3$ choices you start with $n$ possible objects, $A_1,\ldots,A_{n}$, the same kind of coding means that each choice of $k$ objects with repetitions can be "coded" with a choice of $k$ objects from among $n+(k-1)$ possibilities without repetitions, by associating to the list $$A_{i_1},A_{i_2},\ldots,A_{i_k}$$ where $1\leq i_1\leq i_2\leq\cdots\leq i_k\leq n$ with a choice from among $A_1,\ldots,A_n,A_{n+1},\ldots,A_{n+(k-1)}$ via the list $$A_{i_1},A_{i_2+1},A_{i_3+2},\ldots,A_{i_k+(k-1)}.$$ To choose $k$ from among $A_1,\ldots,A_{n+(k-1)}$ without repetition and where order matters, we get $$(n+(k-1))(n+(k-1)-1)\cdots (n+(k-1)-(k-1)) = (n+k-1)\cdots (n+1)(n)$$ and then we divide by $k!$ to account for the fact that the order doe snot matter. So we get $$\frac{(n+k-1)\cdots(n+1)(n)}{k!} = \frac{(n+k-1)!}{(n-1)!k!} = \binom{n+k-1}{k}.$$

Arturo Magidin
  • 417,286
  • That's a brilliant answer, thank you. But still I can't wrap my head around the intuition behind "n repeating <=> n + k - 1 non-repeating" mapping. What initial idea does point you first to this direction? Let's imagine that I don't know that (k, n) with repetition allowed equals (k, n + k -1) without it. What should hint me to this trick with +1 to the first combination's k-th value? – mohican93 May 14 '24 at 11:49
  • @mohican93 The unsatisfying answer is that you may not get the hint. Sometimes one cannot come up with the method in the first place and must be told the "trick". I figured this out on my own by using the "repeat whatever was in the $i$th position" method that I described earlier, but which you rejected as "confusing". It comes down to trying to come up with a systematic way of writing down all possibilities in a way that can be described unambiguously and systematically, so that you can count the descriptions instead of trying to count the outcomes. – Arturo Magidin May 14 '24 at 17:34
  • @mohican93 At the end of the day you don't need "intuition", you need understanding. If you understand why this method correctly counts the outcomes, then you can use it. – Arturo Magidin May 14 '24 at 17:35
  • Since I have no math education and am basically a self-taught, I probably just have to mature a little bit more in this field and develop that thinking. I just would hate switching to the next topic in Combinatorics & Prob.Theory without making sure first I understand this formula from inside out. I'll take some time to read thoroughly over and over what you've written until it settles down. – mohican93 May 14 '24 at 20:13
  • my first suspicion was, on each attempt to build up a new combination we will have n choices, plus after each pick we have to "refill the source", hence + k , and once we have our k-element combination, we don't need to "refill" that, then there's also -1 to it. But this is not the most mathematical approach, that's why I started to look for other opinions. Your algorithm inspired me to find new angles to look at this and future problems, thank you! – mohican93 May 14 '24 at 20:18