\documentstyle[12pt,twoside,amsfonts,psfig]{article}
\input{macros-course-lectures}
\parskip1.5ex
\parindent0pt

\begin{document}
\lecture{notes17}{Notes 17}{November 5, 1996}

Reading: Section 4.6 \\
Next: ??? \\
\\
\\
So far, have studied permutations and combinations of sets of objects,
where each object can only be used once. \\
\\
Today consider a variety of more complicated permutation and
combination problems. \\
\\
1. Permutations and combinations where any number of repetitions of
elements is allowed. \\
\\
Related problems: \\
Number of ways of throwing indistinguishable balls into baskets. \\
Number of ways a number can be decomposed as a sum. \\
\\
2. Permutations and combinations where a bounded amount of repetition
is allowed. \\
\\
Related: \\
Indistinguishable balls in baskets, with constraints on number of
balls in each basket. \\
Distinguishable balls in baskets. \\
Dealing bridge or poker hands. 

\section{Permutations and Combinations with Unbounded Repetition}

\subsection{Permutations}

Recall that an $r$-permutation of a set of $n$ elements is a sequence
of length $r$ of distinct elements. 

\begin{defin}
An $r$-permutation of a set of $n$ elements allowing repetitions 
is a sequence of $r$ elements, each chosen from the set.
(Repeats allowed.)
\end{defin}

Recall that the number of $r$-permutations without repetitions is 
$\frac{n!}{(n-r)!}$. \\
\\
The number of $r$-permutations with repetitions is $n^r$. \\
\\
By Product Rule. \\
Simple.

\begin{example}
How many strings of length $10$, of letters A-M? \\
Same as number of $10$-permutations with repetitions allowed, of the
set of letters A-M. \\
$13^{10}$.
\end{example}

\begin{example}
Given a bag containing $5$ red balls and $5$ blue balls. \\
Experiment involves picking a sequence of $4$ balls (without
replacement). \\
How many different color sequences are possible? \\
\\
This is easy -- just the number of $4$-permutations of the set of $2$
elements (red, blue), \\
which is $2^4$. \\
\\
It doesn't matter here how many red and blue balls there are -- just
matters that there are more than $4$.  \\
Really the unlimited case. 
\end{example}

\subsection{Combinations}

Similar to permutations, but the order doesn't matter. \\
Still any number of repetitions allowed.

\begin{defin}
An $r$-combination of a set of $n$ elements allowing repetitions
is a multiset of $r$ elements, each chosen from the set. 
\end{defin}

Multiset is like a set, but it allows repeated elements. \\
E.g., $\{ R, R, B, B \}$ is multiset consisting of 2 reds and 2 blues. \\
Also written as $\{ 2 \cdot R, 2 \cdot B \}$. \\
\\
Recall that the number of $r$-combinations without repetitions is ${n
\choose r} = \frac{n!}{r!(n-r)!}$. 

\begin{theorem}
The number of $r$-combinations of $n$ elements, allowing repetitions, is: 
$${n + r - 1 \choose r}.$$
\end{theorem}

Not so clear why -- look at an example.

\begin{example}
Given $5$ red balls, $5$ blue balls, $5$ green balls. \\
How many different multisets of size $5$ can be chosen from among
these balls? \\
\\
Again, this is essentially the unlimited case, \\
since there are enough balls to allow any combination. \\
\\
Possibilities here: \\
$5R$, $5B$, $5G$ \\
$4R-1B$, $4R-1G$, $4B-1R$, $4B-1G$, $4G-1R$, $4G-1B$ \\
$3R-2B$, $3R-2G$, $3R-1B-1G$, (and six others like these) \\
$2R-2B-1G$ (and two others like this) \\
\\
Total number is: $21$ \\
Here, $n = 3$ since $3$ kinds of elements. \\
$r = 5$. \\
${n + r - 1 \choose r} = {3 + 5 - 1 \choose 5} = {7 \choose 5} = 21$.
\end{example}

Why is this calculation the right one? \\
Understand it by a thought experiment: \\
\\
Represent each combination concisely by a string of stars and bars. \\
E.g., $3R-2B$ is ***|**| \\
$1R-3B-1G$ is *|***|* \\
The two bars are like dividers between compartments, the stars
represent how many of each color. \\
In order, red, blue, green. \\
\\
Every combination has a unique representation as a string of $5$ stars
and $2$ bars, and every string of $5$ stars and $2$ bars represents a
combination. \\
Bijection. \\
So enough to count the number of different strings of $5$ stars and
$2$ bars. \\
This is ${7 \choose 2} = {7 \choose 5} = 21$.
Think of choosing the positions representing the stars (or bars). \\
\\
\\
The general proof follows this argument:

\begin{proof}
(Combinatorial) \\
There is a bijection between the number of $r$-combinations of $n$
elements with repetition and the number of strings of stars and bars
having exactly $r$ stars and $n-1$ bars. \\
The number of such strings is ${n + r - 1 \choose r}$.
\end{proof}

\begin{example}
How many ways to choose 12 doughnuts from 21 varieties? \\
\\
This is a combination problem -- order doesn't matter. \\
Allows repetitions. \\
So it's asking for the number of $12$-combinations of a $21$-set, with
repetitions allowed. \\
\\
Formula says ${21 + 12 - 1 \choose 12} = ???$. \\
Intuitively, see in terms of $20$ bars and $12$ stars.
\end{example}

Now an equivalent problem -- counting the number of ways of putting 
$r$ indistinguishable balls into $n$ (distinguishable) baskets. \\
To see the equivalence, think of the doughnut problem as putting $12$
indistinguishable ``doughnut requests'' into the $21$ doughnut bins.

\begin{example}
Given $n$ baskets in an amusement park arcade game, $r$ balls (all
same), how many different results can you get by throwing the balls
into the baskets? \\
\\
Again, the number of $r$-combinations of $n$ elements. \\
Can see this by corresponding each result with a pattern of 
$r$ stars and $n-1$ bars. \\
${n + r - 1 \choose r}$ \\
\end{example}

Another equivalent problem: \\
Counting the number of ways to build up a number by addition:

\begin{example}
In how many ways can a positive integer $r$ be written as the sum of
exactly $n$ nonnegative integers, where the order matters? \\
\\
E.g., write $7$ as sum of at most $3$ positive integers: \\
$7 + 0 + 0$, $0 + 7 + 0$, $0 + 0 + 7$, \\
$6 + 1 + 0$, etc. \\
$5 + 2 + 0$, etc. \\
\\
Again, the number of $r$-combinations of $n$ elements. \\
Can see this by corresponding each sum with a pattern of $r$ stars and
$n-1$ bars. \\
The bars are the $+$ signs, the stars are the units being counted. \\
\\
Here, ${7 + 3 - 1 \choose 7} = {9 \choose 7} = 36$.
\end{example}

Note the preceding is different from the number of ways where the
order of terms doesn't matter. \\
For $7$ and $3$, that gives $8$: \\
$7+0+0$, $6+1+0$, $5+2+0$, $5+1+1$, $4+3+0$, $4+2+1$, $3+3+1$,
$3+2+2$. \\
Q: What is that number, in general?

\begin{example}
How many increasing $7$-sequences are there, of the numbers 
${1,2,3,4,5,6,7,8,9,10}$? \\
\\
There's one for every way of choosing $7$ distinct elements from these
$10$, i.e., ${10 \choose 7}$. \\
\\
What if they are only required to be nondecreasing? \\
\\
Then there is one for every $7$-combination of these elements,
allowing repeats. \\
That's ${10+ 7-1 \choose 7} =  {16 \choose 7}$.
\end{example}

\section{Perms and Combs with Bounded Repetition}

\subsection{Combinations}

So far, these $r$-combination problems all allowed arbitrary numbers
of occurrences of each element of the set. \\
(Arbitrary number of balls in each basket, arbitrary number for each
summation term.) \\
Can also consider variations in which there are constraints on the
number of occurrences of each element. \\
Start with some lower bounds: 

\begin{example}
In how many ways can $7$ be written as the sum of {\em exactly\/} $3$
{\em positive\/} integers (that is, no zeros)? \\
\\
In terms of stars and bars, there are $7$ stars and $2$ bars, as
before, only now there must be at least one star in each compartment. \\
We can just eliminate consideration of $3$ stars -- their position is
determined. \\
What's left is distributing the remaining $4$ stars into the $3$
compartments, which is ${4 + 3 - 1 \choose 4} = {6 \choose 4} = 15$. \\
\\
In general, to write $r$ as sum of $n$ positive integers (where order
matters), where $r \geq n$, \\
have 
$${(r-n) + (n-1) \choose r-n} = {r-1 \choose r-n} = {r-1 \choose n-1}.$$
\end{example}

Express this as another theorem:

\begin{theorem}
The number of $r$-combinations of $n$ elements, allowing repetitions, and
where each element occurs at least once, is 
$${r-1 \choose n-1}.$$
\end{theorem}

\begin{proof}
As in the example above. \\
Each such combination can be represented by a sequence of $r-n$ stars
and $n-1$ bars.  \\
The number of these is $${(r-n) + (n-1) \choose r-n} = {r-1 \choose
r-n} = {r-1 \choose n-1}.$$
\end{proof}

Same thing here:

\begin{example}
Given $n$ baskets in arcade, $r$ balls, how many different results in
which each basket has at least one ball? \\
\\
This is number of $r$-combinations of $n$ elements in which each
element is represented at least once, which is 
$${r-1 \choose n-1}.$$
\end{example}

Generalize this to other constraints: 

\begin{example}
Arcade, $n$ baskets, $r$ balls, but now basket $i$ has to have at
least $b_i$ balls. \\
\\
Just subtract off the number that are already assigned to baskets,
that is, $b = \Sigma_i b_i$, and allocate the rest to the $n$ baskets. \\
\\
So, the number of $(r-b)$-combinations of $n$ elements, which is ${r -
b + n - 1 \choose r-b} = {r-b+n-1 \choose n-1}$.
\end{example}

\begin{theorem}
\label{thm1}
The number of $r$-combinations of $n$ elements, with repetitions, and
where each element $i$ occurs at least $b_i$ times, is 
$${r-b+n-1 \choose r-b} = {r-b+n-1 \choose n-1},$$
where $b = \Sigma_i b_i$.
\end{theorem}

The following examples use these ideas:

\begin{example} 
In how many ways can the $2n+1$ seats in a congress be  
divided among three parties so that any two parties can form a
majority? \\
(Not distinguishing the individuals here -- just the combinations of
numbers.) \\
\\
To compute this number, we first compute the number of all
assignments of the seats to the parties, without any restrictions. 
This is the number of $2n+1$-combinations of $3$ objects (parties)
allowing repetitions: \\
$${3 + (2n+1) - 1 \choose 2n+1} = {2n+3 \choose 2n+1} = {2n+3 \choose
2}.$$ \\
Second, we compute the number of 
{\em wrong\/} distributions, i.e., when there is a party with at least
$n+1$ seats. \\
We have three choices for this unique party, then we can give it $n+1$
seats and distribute the remaining n seats in 
$${3 + n - 1 \choose 2} = {n+2 \choose 2}$$ ways. \\
Thus the number of wrong distributions is $3{n+2 \choose 2}$,
so the number of good  distributions is
\[{2n+3 \choose 2} - 3{n+2 \choose 2} =
\frac{n(n+1)}{2} = {n+1 \choose 2}.\] 
\end{example}

Q: Combinatorial interpretation?
Well, suppose that we consider distributing negative seats to the
three parties instead of positive seats.  \\
If everyone starts with presumption of the full $2n+1$, we need to
distribute $4n+2$ negative seats. \\
Everyone has to have at least $n+1$ negative seats, in order not to
have $n+1$ positive seats. \\
So that leaves $4n+2 - 3(n+1) = n-1$ to be allocated to $3$ bins, or 
$${(n-1) + 3 - 1 \choose 2} = {n+1 \choose 2}.$$
(Get by applying Theorem \ref{thm1}, where $b = 3(n+1)$, $r = 4n+2$,
$n = 3$, and ${r - b + n - 1 \choose n - 1} = {n - 1 + 2 \choose 2}).$ \\

\begin{example}
What if the total number of seats is even, $2n$?
Majority is still $n+1$. \\
This is more complicated. \\
We can again compute the number of all distributions, this time
getting ${2n+2 \choose 2}$. \\
What about the number of wrong permutations? \\
If the parties $B$ and $C$ fail to have absolute majority, 
then it means that $A$ has at least $n$ seats. \\
Thus we can give to $A$ $n$ seats in advance and then distribute the
$n$ remaining seats to among the three parties
in ${n+2 \choose 2}$ ways. \\
The same can be said if $B$ or $C$ has at least $n$ seats. \\
However, we {\em cannot} say that ``therefore, the number of 
wrong distributions is $3{n+2 \choose 2}$'' as we did before, 
because three distributions, namely $(n,n,0)$, $(n,0,n)$ and $(0,n,n)$,
were counted twice. \\
\\
(This couldn't happen in the previous example since there couldn't be
more than one party that held alone at least the half of the seats.)
\\
Therefore, the number
of wrong distributions is $3{n+2 \choose 2}-3$, thus the number of good
distributions is 
\[{{2n+2 \choose 2}}-3{{n+2 \choose 2}} + 3 = \frac{(n-1)(n-2)}{2}=
 {{n-1 \choose 2}}.\] 
\end{example}

Q: Combinatorial interpretation?
Negative votes, need $4n$, each needs at least $n+1$, so leaves $4n -
3(n+1) = n - 3$ to be allocated to $3$ bins. \\
That's 
$${n - 3 + 3 - 1 \choose 2} = {n-1 \choose 2}.$$
\\
Can also apply inclusion-exclusion to understand the last example. \\
The wrong combinations are those in which some party has $\geq n$
seats. \\
This is the union of three sets, one for each party. \\
To count the union, use the sum of the three, minus the sum of the
sizes of the pairwise intersections, plus the size of the 3-way
intersection.  \\
Each set has size ${n + 2 \choose 2}$, for the number of ways of
allocating the remaining $n$ seats to the $3$ parties. \\
Each 2-way intersection has exactly one possibility. \\
There is no 3-way intersection. \\
$$3 {n+2 \choose 2} - 3 \cdot 1$$
\\
\\
Now consider the $r$ balls in $n$ baskets problem again, only now
with {\em upper bound\/} constraints. \\
That is, suppose that we have to have  $< b_i$ balls in basket
$i$, for all $i$. 

\begin{example}
$10$ balls in $4$ baskets, with fewer than $7$ in each basket. \\
Can calculate by all $10$-combinations of $4$ elements minus the wrong
ones. \\
\\
All: ${4 + 10 - 1 \choose 10} = {13 \choose 10}$. \\
\\
Wrong:  Some basket has at least $7$.  \\
Do as union of $4$ sets, based on which has at least $7$. \\
Disjoint, so don't need inclusion-exclusion. \\
Each reduces to number of $3$-combinations of $4$ elements (allowing
repetitions), or ${3 + 4 - 1 \choose 3} = {6 \choose 3}$. \\
\\
So, total is ${13 \choose 10} - 4{6 \choose 3}$. 
\end{example}

\begin{example}
Same, but for $10$ balls in $9$ baskets, with fewer than $4$ in each
basket \\
Now will need inclusion-exclusion. \\
\\
All: ${9 + 10 - 1 \choose 8} = {18 \choose 8}$. \\
\\
Wrong: Let $A_i$ be the set of combinations in which basket $i$ has
$\geq 4$ balls. \\
Want size of $\cup A_i$, do by inclusion-exclusion. \\
\\
For each $i$, $|A_i|$ is the number of $6$-combinations of $9$,
which is ${9+6-1 \choose 8} = {14 \choose 8}$. \\
There are ${9 \choose 1}$ such $i$. \\
\\
For each $i, j$, $|A_i \cap A_j|$ is the number of $2$-combinations of
$9$, which is ${9+2-1 \choose 8} = {10 \choose 8}$. \\
There are ${9 \choose 2}$ such pairs. \\
\\
All the 3-way or more-way intersections are empty. \\
\\
So, we have ${18 \choose 8} - {9 \choose 1}{14 \choose 8} + {9
\choose 2} {10 \choose 8}$.
\end{example}

Extending this idea, we get:

\begin{theorem}
The number of $r$-combinations of $n$ elements, with repetitions, and
where each element $i$ occurs fewer than $b$ times, is:
${n+r-1 \choose n-1}
- {n \choose 1}{n+r-b-1 \choose n-1}
+ {n \choose 2}{n+r-2b-1 \choose n-1} 
- \ldots 
+ (-1)^{n}{n \choose n}{n+r-nb-1 \choose n-1}$.
\end{theorem}

In the previous sum the $n+r-kb-1$ expressions might become $0$, but
that's OK -- the binomial coefficients containing them will then reduce
to $0$, which is what we want. \\
\\
Of course, could also extend to a different bound for each element,
LTTR.

\subsection{Permutations}

One last topic -- permutations of elements allowing repeats, with
bounds. \\
\\
The general problem is: \\
Given $n$ elements, with upper and/or lower bounds on number of times
to use each, \\
how many different $r$-permutations are there? \\
\\
Simplest case: \\
Where each of the $n$ elements has exact bounds -- we're told exactly
how many to use of each. \\
This only makes sense when $r$ is equal to the sum of the bounds. \\
\\
This is the only case we will work out in this course. 

\begin{example}
$n=3$; the elements are the letters P, E, R. \\
The bounds are: $P-3$, $E-2$, $R-1$. \\
$r=6$. \\
\\
How many permutations? \\
Same as asking how many permutations of the word PEPPER. \\
\\
To analyze, subscript each letter to make them distinct, yielding
$P_1,P_2,P_3,E_1,E_2,R_1$. \\
This set has $6!$ permutations. \\
However, by mapping all the $P_i$ to $P$ and all the $E_i$ to $E$, we
get a $3! 2!:1 $ mapping. \\
So by rule of division, we see that the correct number of distinct
permutations of PEPPER is $\frac{6!}{3! 2!}$.
\end{example}

The question is the same as asking for the number of permutations of a
particular multiset.

\begin{theorem}
Let $S$ be a multiset with finite repetition counts $b_1,b_2,\ldots b_n$, 
where $b_1+b_2+\ldots +b_n = r = |S|$. \\
Then the number of permutations of $S$ is
\[\frac{r!}{b_1!b_2!\cdots b_n!}.\] 
\end{theorem}

We can do a proof using the division rule, as in the example for
PEPPER. \\
Give an alternative proof below: \\

\begin{proof}
(Combinatorial) \\
Consider $r$ slots in which we put the elements (exactly one element
to each slot) for each permutation.  \\
Then there are ${r \choose b_1}$ ways to choose slots for the
first type of element, \\
then ${r-b_1 \choose b_2}$ ways to choose slots for the second type of element
from the remaining slots, \\
and so on. \\
This shows that the total number of permutations is:
\[ {r \choose b_1} {r-b_1 \choose b_2} \cdots {r-b_1-\cdots -b_{n-1} 
 \choose b_n}  =   \frac{r!}{b_1!b_2!\cdots b_n!} \]
\end{proof}

The quantity above is the {\em multinomial coefficient}
\[
{r \choose b_1,b_2,\ldots,b_n},
\]
which generalizes binomial coefficients, which corresponds to the case $n = 2$.


\subsection{Distinguishable Balls in Baskets}

Here is another problem that looks quite different from the
permutation problem we just did, but whose solution turns out to look
very similar, using multinomial coefficients. \\
\\
After presenting the problem and its solution, I'll try to explain how
it corresponds to the permutation problem, which will show {\em why\/}
the solutions look so much the same. \\
\\
\\
The problem is another balls-in-baskets problem, with $r$ balls in $n$
baskets, only this time, the balls are {\em distinguishable\/}, e.g.,
they have numbers written on them.  \\
(They are all one color.) \\
We assume that each basket $i$ can hold $n_i$ balls, where $\Sigma_i
n_i = r$. \\
What we are counting is the number of different patterns that are
possible, where a pattern describes the sets of balls in all the
baskets. 

\begin{example}
Bridge hands.  Have $n = 4$ for the $4$ players.  Want to deal out all
$52$ cards into $4$ hands of $13$ each. \\
How many possible ways to do this?  \\
(Count as different if it's the same hands but different players.) \\
\\
There are ${52 \choose 13}$ ways to choose the first player's hand,
then ${39 \choose 13}$ ways to choose the second player's hand from
the remaining cards, then ${26 \choose 13}$ ways to choose the third
player's hand from the remaining cards, then there is only one way for
the last player. \\
So (using trees), the total number of ways is: \\
${52 \choose 13}{39 \choose 13}{26 \choose 13}$, \\
which is 
\[ \frac{52!}{13!39!} \frac{39!}{13!26!} \frac{26!}{13!13!} = \frac{52!}{13!13!13!13!}.
\]
This latter is the multinomial coefficient ${52 \choose 13,13,13,13}$.
\end{example}

\begin{example}
Poker hands, dealing $5$ to each of $4$ players. \\
Corresponds to $5$ bins, where one bit represents all the cards that
aren't dealt out. \\
Then get ${52 \choose 5}{47 \choose 5}{42 \choose 5}{37 \choose 5}$,
which reduces to the multinomial coefficient ${52 \choose 5,5,5,5,32}$.
\end{example}

In general, for $n$ bins with capacities $b_1, \ldots, b_n$ with sum
$r$, we get the multinomial coefficient ${r \choose
b_1,b_2,\ldots,b_n}$. \\
\\
Same answer as for number of permutations of $r$ elements, where
groups of $b_1, b_2, \ldots, b_n$ are indistinguishable. \\
\\
Why are these the same problem?  \\
Show a bijection between the two sets. \\
Let $B$ be the set of patterns of balls in baskets (dealt hands), and
$P$ the set of permutations of the ``capacity multiset''
${b_1 \cdot 1, b_2 \cdot 2, \ldots, b_n \cdot n}$ \\
\\
Arrange all the $r$ balls in a sequence $R$, and number them according
to their order in this sequence. \\
So we can talk about ball $1$, ... ball $r$. \\
\\
Consider any element of $B$, a pattern of $r$ balls in the $n$
baskets, with $b_i$ in basket $i$. \\
Represent it by a permutation of the capacity multiset as follows: \\
In the sequence $R$, replace each ball that goes in basket $i$ with
$i$, the name of the basket itself. \\
\\
This clearly yields a unique permutation of the capacity multiset. \\
Two different patterns don't yield the same permutation (one-to-one).\\
Every permutation of the capacity multiset arises from some pattern.\\
\\
Inverse: Given a permutation of the capacity multiset, assign the balls
whose positions are labelled with $i$ to basket $i$. 

\begin{example}
Bridge hands, enumerate the cards $1,\ldots, 52$ in the usual order,
ace to king, spades, hearts, diamonds, clubs. \\
The two sets are the deals, vs. the set of permutations of the
multiset $\{ 13 \cdot 1, 13 \cdot 2, 13 \cdot 3, 13 \cdot 4 \}$. \\
\\
Here, $1-4$ represent the four players. \\
Represent a deal by putting $1$ in the positions in the
sequence indicating the cards that are dealt to player $1$, and
similarly for $2$, $3$ and $4$. 
\end{example}
\end{document}

Problems:

All from Section 4.6:

Prob. 16 (combinations)
Prob. 26 (permutations -- finger exercise)
Prob. 30 (permutations -- is there a nice general solution for this?)
Prob. 42 (combinations)
Prob. 48 (multinomial)

Tom will also give problems on Generating Functions.  You might want
to eliminate one of these problems, but they should be good to help in
studying.  
