Permutations
------------

A _permutation_ of a finite set S is an ordered list of its elements.

An _r-permutation_ of S is an ordered list of r of its elements.

Warning:
    there is another, related, meaning of 'permutation': an element of the
    group of bijections of S. We won't use that meaning in this course.

P(n,r) := number of r-permutations of a set of size n.

e.g. P(26,5) = number of strings of 5 distinct letters from the Roman alphabet.

By the multiplication principle,
    P(n,r) = n * (n-1) * ... * (n-(r-1))
(n choices for first, n-1 for second...)

P(n,r) = n! / (n-r)!

P(n,n) = n!

Remark:
    Can interpret "P(n,r) = n! / (n-r)!" as follows:
	We can obtain an r-permutation of S by taking the first r elements of
	a permutation of S.
	Partition the permutations of S according to the r-permutation which
	results from this: we see that the elements of each set of the
	partition correspond to the permutations of the left-over n-r
	elements, so we recover the formula by the division principle.

A _circular r-permutation_ of a set is a way of putting r of its elements
around a circle, with two such considered equal if one can be rotated to the
other.

We can obtain a circular r-permutation from an r-permutation by "joining the
ends into a circle". Each circular r-permutation is obtained from r different
r-permutations, so by the division principle:
    number of circular r-permutations of n elements
	= P(n,r) / r
	= n! / r(n-r)!

Example:
    How many different kinds of necklace can be made from 7 spherical beads
    of different colours? Consider two necklaces to be of the same kind when
    they can be non-destructively manipulated to look the same.
Solution:
    There are 7!/7 = 6! circular permutations of the 13 colours. Each kind
    of necklace is obtained from exactly *two* circular permutations, because
    flipping the necklace in space doesn't change the kind. So
	6! / 2 = 360.

Example:
    How many ways can 13 people be sat around a round table, if Professor Q
    is not to be sat next to his arch-nemesis Inspector P?
Solution:
    Without the restriction, there would be 12! seating arrangements.
    Consider seating everyone but P; each such arrangement yields two
    forbidden arrangements of all 13, one by placing P to Q's right and one by
    placing P to Q's left. We count each forbidden arrangement once in this
    way.

    So the answer is 12! - 2*11! = 10*11! = 399168000


Subsets ("Combinations")
-------

An _r-subset_, or _r-combination_, of a set S is a subset of size r.

C(n,r) = number of r-subsets of a set of size n.

e.g. C(26,5) = number of unordered selections of 5 letters from the roman
    alphabet

Theorem:
    C(n,r) = n! / r!(n-r)!
Proof:
    The r-permutations of a set are precisely the permutations of the
    r-subsets. Each r-subset has r! permutations, so
	P(n,r) = r! * C(n,r).
    So
	C(n,r)
	    = P(n,r) / r!
	    = n! / r!(n-r)!.

C(n,r) is also called a "binomial coefficient".

Example:
    If we expand out (x+y)^n and collect terms to obtain
	a_0 x^n + a_1 x^{n-1}y + ... + a_{n-1} xy^{n-1} + a_n y^n,
    what are the coefficients a_k?
Solution:
    a_k is the number of ways of choosing y k times when we have to choose
    either x or y from each factor of the product
	(x+y)(x+y)...(x+y)  (n times),
    which is the number of subsets of this set of n factors.

    So a_k = C(n,i).

Theorem [Pascal's Formula]:
    If 0 < k < n,
	C(n,k) = C(n-1,k) + C(n-1,k-1)
Proof:
    |S| = n.
    Fix x \in S; let S' := S \\ {x}.
    Partition the k-subsets of S according to whether they contain x.
    Those which don't correspond to k-subsets of S',
    those which do correspond to (k-1)-subsets of S'.

Theorem:
    \Sigma_{k=0}^n C(n,k) = 2^n
Proof:
    |S| = n.
    \Sigma_{k=0}^n C(n,k) = number of subsets of S.
    But to choose a subset of S is to choose for each element of S whether it
    should or should not go in to the subset. That's two choices for each of
    the n elements, so by the multiplication principle there are
    2*2*...*2 = 2^n subsets of S.