Counting

See disclaimer about the slides.
See learning objectives and sources.

Rule of sum

If $A \cap B = \varnothing$, then $|A \cup B| = |A| + |B|$.
Generalize to any number of sets.
Example: $A$ is a set of 3 movies, $B$ is a set of 2 sport games.
In how many ways can you choose a show (either a movie or game)?
Discuss solution during the lecture.

Rule of product

$|A \times B| = |A|\,|B|$.
Generalize to any number of sets.
Example as before: In how many ways can you choose first to watch a movie and then to go to a game?
Discuss solution during the lecture.
Power notation: $|A^n| = |A|^n$.

Incl-Excl principle

$|A \cup B| = |A| + |B| - |A \cap B|$.
Generalize to any number of sets.
Example: $A$ is a set of hats: red, blue and green. $B$ is another set of hats: red and yellow.
How many different hats can you wear?
Discuss solution during the lecture.

Countability (definition)

A set $A$ is countable if there is an injection from $A$ to $\mathbb {N}$.
Interesting case: countably infinite, bijection with $\mathbb {N}$.

Countability (examples)

The non-negative even numbers are countable.
The witnessing injection is $f : {\mathbb E} \to {\mathbb N}$ defined by $f(x)=x$.
$f$ does not prove that ${\mathbb E}$ is countably infinite.
Prove during the lecture that they are.

The integers are countably infinite.
The witnessing bijection is $f : {\mathbb Z} \to {\mathbb N}$ defined by $f(x)= \left\{ \begin{array}{l l} 2x & \quad \mbox{if $x \geqslant 0$;} \\ -2x-1 & \quad \mbox{otherwise.} \end{array} \right.$

Cantor Enumeration

Proves that $\mathbb N \times \mathbb N$ is countable. [Reference].

cantor_enumeration_5.png

Consequence: the countable union of countable sets is countable.
Every language, including C and Java, is countable.

Cantor Diagonalization

Proves the existence of an uncountable set [Reference].

cantor_diagonalization_5.png

Consequences: basis for proving that many sets are uncountable,
e.g., real numbers, $2^{\mathbb N}$, languages over an alphabet.
Theorem: $\forall A ~ (|A| \lt |2^A|)$ (no injection $ 2^A \to A$ ).
There are not enough programs to compute the decimal digits of every real number.
There are not enough ''names'' (clarify the meaning) to identify every real number.
Contradiction: The set $S$ of all sets does not exist.
Each element $x$ of $2^S$ would be an element of $S$ (because $x$ is a set).
Hence $2^S$ would be both bigger (because of theorem) and smaller (because contained in) than $S$.

Combinatorics

Permutation

An arrangement of $k$ objects from a set of $n$.
No repetitions, order matters.
Example: permutations of 2 digits from $\{5,6,7,8\}$.
Solution compactly written: [56,57,58,65,67,68,75,76,78,85,86,87].
$P(n,k)=\overbrace {n\cdot (n-1)\cdot (n-2)\cdots (n-k+1)} ^{k\ \mathrm {factors} }$ (other notations).
Factorial notation: $n\cdot (n-1)\cdot (n-2)\cdots 1= n!$, convention $0!=1$.
Close form: $P(n,k)={\displaystyle \frac {n!}{(n-k)!}}$.
Special case: $P(n,n) = n!$.
Example: $P(4,2)=12$.

Combination

A subset of $k$ objects from a set of $n$.
No repetitions, order does not matter.
Example: combinations of 2 digits from $\{5,6,7,8\}$.
Solution compactly written: [56,57,58,67,68,78].
Close form: $C(n,k)={\displaystyle \frac {n!}{k!\ (n-k)!}}$.
Binomial notation: $C(n,k)={\displaystyle \binom{n}{k}}$.
Special cases: $C(n,n)=C(n,0)=1$, $C(n,1) = C(n,n-1) = n$.
Example: $C(4,2)=6$.
Problem: count the number of poker hands (5 cards out of 52).

Permutation with repetitions

Repetitions allowed, order matters.
Each element has a fixed count.
Example: word with the letters $a,b,b,b$. Counts are 1 and 3.
Solution: $[abbb,babb,bbab,bbba]$.
Let $a_1,a_2, \ldots a_k$ elements with counts $n_1,n_2, \ldots n_k$.
$P(n;n_1,\ldots n_k)={\displaystyle \frac {n!}{n_1! \cdots n_k!}}$.
Example: $P(4;1,3)={\displaystyle \frac{4!}{1! \cdot 3!}}=4$.

Combination with repetitions

Any choice (multiset) of elements from a set.
Repetitions allowed, order does not matter.
Example: four coin changes with pennies, nickels, and dimes.
Solution compactly written: $[pppp,pppn,pppd, ppnn, ppnd, \ldots]$
$C(n+k−1;k,n−1)={\displaystyle \binom {n+k-1}{k}= \frac {(n+k-1)!}{k!\ (n-1)!}}$.
In this case, $n=3$ and $k=4$, thus $C(3+4-1;4,2)=15 ={\displaystyle \frac {6!}{4!\ 2!}}$.
Computation: bijection between the $k$-element multisets over $\{1, 2, \ldots, n\}$ and the $k$-element subsets of $\{1, 2, \ldots , n + (k – 1)\}$. Add 0123 component-wise to the left to get the right.
1111$\leftrightarrow$1234
1112$\leftrightarrow$1235
1113$\leftrightarrow$1236
$\ldots$$\leftrightarrow$$\ldots$
2333$\leftrightarrow$2456
3333$\leftrightarrow$3456
See also this nice explanation.

Binomials

Pascal Triangle:
    0:                    1                 
    1:                 1     1               
    2:              1     2     1             
    3:           1     3     3     1           
    4:        1     4     6     4     1
Row number $n$ contains the numbers ${\displaystyle {\binom {n}{k}}}$, for $k = 0, \ldots n$.
Application: ${\displaystyle (x+y)^{n}=\sum _{k=0}^{n}{\binom {n}{k}}x^{n-k}y^{k}}$.

Pigeonhole Principle

If $n$ pigeonholes are occupied by $m$ pigeons and $m > n$, then at least one pigeonhole is occupied by more than one pigeon.