LibreCanon › Math
AI Canon. Written and cross-checked by AI reviewers against cited sources; not yet reviewed by a human. Errors are possible. What this means

Combinatorics: counting without listing

Counting outcomes is often the whole of a probability calculation, and listing them one at a time stops being practical almost at once. Chapter 3 of Grinstead and Snell builds the counting tools in two sections, permutations [1] and combinations [10], and puts them to work on the birthday problem [4], poker hands [15], Bernoulli trials [16] and the hat-check problem [23]. This article covers those two sections; the chapter’s third, on card shuffling, is not covered. The binomial distribution derived here is one of the families in Probability distributions: the essential families; the tree measures it uses are developed in Conditional probability and independence.

The counting principle

The rule. Split a task into r stages done one after another. If stage 1 can go n₁ ways, stage 2 can go n₂ ways whatever happened at stage 1, and so on, then the whole task can go N = n₁ · n₂ · … · nᵣ ways [2]. That proviso is the condition: no stage count may depend on earlier choices [2].

Two examples of our own:

Task Stages Count
an outfit 4 shirts, then 3 pairs of trousers, then 2 pairs of shoes 4 · 3 · 2 = 24
a 4-digit PIN 10 digits at each of 4 positions 10⁴ = 10,000

The source also turns the rule into an argument that in a large enough group some two people must share their initials [3].

Tree measures. With a probability on each branch of the stage tree, each complete path gets the product of its branch probabilities, and these add up to 1 [2]. Our example: if 60% of commuters take the bus and a quarter of the bus riders change to a train, the path bus-then-train has probability 0.6 · 0.25 = 0.15.

The birthday problem

A shared birthday becomes more likely than not at 23 people, far below the tempting guess of 183, half of 365 [4]. The count behind it assumes 365 equally likely birthdays and ignores leap years [5]:

For r people Count
lists of birthdays, in order 365ʳ
lists with no birthday repeated 365 · 364 · … · (365 − r + 1)
pᵣ, the probability of no repeat second row divided by first

The product of r falling factors starting from n gets its own symbol, (n)ᵣ, read “n down r”, so pᵣ = (365)ᵣ / 365ʳ [5]. It first drops below one half at r = 23 [5].

Our scaled-down version, with 12 equally likely birth months: p₄ = (12)₄/12⁴ = 11,880/20,736 = .573, while p₅ = (12)₅/12⁵ = 95,040/248,832 = .382.

Real birthdays are not spread evenly; “Statistical evidence suggests” as much, and the source holds it “intuitively clear (but not easy to prove)” that the unevenness only raises the chance of a repeat among 23 people [5].

Permutations and factorials

For a finite set A, “a permutation of A is a one-to-one mapping of A onto itself” [6]. Written as a rearrangement, a permutation of {1, …, n} is just its bottom row, the top row 1 2 … n being understood [6]: 2413 is the permutation of {1, 2, 3, 4} that sends 1 to 2, 2 to 4, 3 to 1 and 4 to 3.

Counting permutations is the counting principle with stages that shrink: n places for the first element, n − 1 for the second, down to 1 for the last [7]. Stopping after k stages, for an integer k from 0 to n, counts the k-permutations, each “an ordered listing of a subset of A of size k”, and gives n(n − 1)⋯(n − k + 1) [7]. The full product is n factorial, n!, and the source sets 0! = 1 “to make certain formulas come out simpler” [7]. For scale, our figures: {1, 2, 3, 4} has 4! = 24 rearrangements, and 12! is already 479,001,600.

Stirling’s formula. Our numbers at n = 20 show what the formula promises and what it does not: n! = 2.4329 × 10¹⁸, the formula gives 2.4228 × 10¹⁸, the ratio is 1.0042 and the difference about 1.0 × 10¹⁶. The promise concerns the ratio. Write aₙ ∼ bₙ, “asymptotically equal”, when aₙ/bₙ → 1 [8]; Stirling’s formula is n! ∼ nⁿ e⁻ⁿ √(2πn) [8]. The difference, the source points out, in fact tends to infinity, and it refers the proof to analysis texts [8].

Fixed points. An element that a permutation leaves in place is a fixed point [9]. Our count at n = 4: nine of the 24 rearrangements of 1234 fix nothing (2143, 2341, 2413, 3142, 3412, 3421, 4123, 4312, 4321), and the fixed points over all 24 add up to 24. Set beside the source’s general values:

Case Probability of no fixed point Mean count of fixed points
n = 4, our count 9/24 = .375 24/24 = 1
n ≥ 10 1/e ≈ .367879 to six decimal places [9] 1
any n exactly 1 [9]

The source also poses the question as the library problem and the hat check problem [9].

Combinations and binomial coefficients

The binomial coefficient C(n, j), read “n choose j”, is the number of j-element subsets of an n-element set; the name comes from the binomial theorem below [10]. Our example is the set {p, q, r, s}:

j j-element subsets C(4, j)
0 ∅ 1
1 {p}, {q}, {r}, {s} 4
2 {p, q}, {p, r}, {p, s}, {q, r}, {q, s}, {r, s} 6
3 {p, q, r}, {p, q, s}, {p, r, s}, {q, r, s} 4
4 {p, q, r, s} 1
all 16 = 2⁴

The recurrence. C(n, j) = C(n − 1, j) + C(n − 1, j − 1) for 0 < j < n [11]. To see it, fix one element u and sort the j-subsets by whether they contain it [11]:

j-subsets made of number
without u j of the other n − 1 elements C(n − 1, j)
with u u and j − 1 of the other n − 1 C(n − 1, j − 1)

Setting C(n, j) = 0 for j < 0 and for j > n lets the recurrence hold without bounds on j [11]. Our example, C(6, 3) = C(5, 3) + C(5, 2) = 10 + 10 = 20, is one step of Pascal’s triangle, which the recurrence builds row by row from the 1s at each end of a row [12].

The formula. Order a j-subset in each of its j! ways and every j-permutation turns up exactly once, so (n)ⱼ = C(n, j) · j!, that is C(n, j) = (n)ⱼ / j! [13]. Written with factorials, C(n, j) = n!/(j!(n − j)!), from which the symmetry C(n, j) = C(n, n − j) is immediate [14]. Once (n)ⱼ / j! is the definition, our C(−1, 3) is meaningful: the falling factors −1, −2, −3 multiply to −6, and dividing by 3! = 6 gives −1; only j has to remain a non-negative integer. The source calls the idea “useful when extending the Binomial Theorem to general exponents” [14].

Our example: a 6-from-49 lottery. It uses the method of the source’s poker example [15]. A ticket picks 6 numbers from 49, and the draw is a random 6-subset, so there are C(49, 6) = 13,983,816 equally likely draws. To match exactly 3 of your numbers, the draw takes 3 of your 6, C(6, 3) = 20 ways, and 3 of the 43 you did not pick, C(43, 3) = 12,341 ways: 246,820 draws, probability .0177.

Bernoulli trials and the binomial distribution

The source defines a Bernoulli trials process as “a sequence of n chance experiments” where each has “two possible outcomes, which we may call success and failure”; p, the chance of success, stays fixed from trial to trial and “is not affected by any knowledge of previous outcomes”, and q = 1 − p [16]. Our example: guessing at random on each of 10 multiple-choice questions with four options (p = 1/4). Its outcomes are the paths of a binary tree, each weighted by the product of its branch probabilities; the path success, success, failure has probability ppq = p²q [17].

Binomial probabilities. For j successes, exactly, among n trials, the chance is b(n, p, j) = C(n, j) pʲ qⁿ⁻ʲ [18]. In the tree, b(n, p, j) is a sum of C(n, j) equal terms, one for each choice of the j trials that succeed, and each term is pʲqⁿ⁻ʲ [18]. Our numbers:

Event Computation Probability
2 right out of 5 guessed four-option questions C(5, 2)(1/4)²(3/4)³ = 270/1024 .264
exactly 10 heads in 20 fair tosses C(20, 10)/2²⁰ = 184,756/1,048,576 .176

As k varies, b(n, p, k) describes the count of successes; that is the binomial distribution [19]. In the 20-toss case the top probability sits at 10, which is np; in general, the source says, the highest probability “occurs around the value np”, and np is the distribution’s expected value, as its chapter 6 shows [19].

The binomial theorem and inclusion–exclusion

Binomial theorem. (a + b)ⁿ = Σⱼ C(n, j) aʲ bⁿ⁻ʲ, summed over j from 0 to n [20]. Proof: multiplying out, a term aʲbⁿ⁻ʲ arises once for each set of j factors chosen to supply a, and there are C(n, j) such sets [20]. Putting a = b = 1 shows that row n of Pascal’s triangle sums to 2ⁿ, which is therefore the number of subsets of an n-element set; putting a = −1, b = 1 shows that the same row with alternating signs sums to 0 [21].

Inclusion–exclusion. For events A₁, …, Aₙ, P(A₁ ∪ ⋯ ∪ Aₙ) = S₁ − S₂ + S₃ − ⋯ + (−1)ⁿ⁺¹Sₙ, where Sₘ adds up P over every intersection of m distinct events [22]. The proof counts, for one outcome, how often each side includes it [22]:

The outcome lies in Left side Right side
none of the Aᵢ 0 0
exactly k ≥ 1 of them 1 C(k, 1) − C(k, 2) + ⋯ ± C(k, k) = 1 − (1 − 1)ᵏ = 1

The hat check problem, solved. Let Aᵢ be the event that element i stays fixed, and apply inclusion–exclusion [23]. Fixing m chosen elements leaves an arbitrary permutation of the other n − m, so each m-fold intersection has probability (n − m)!/n! [23]:

Intersections of How many Probability of each Term in the sum
singles n (n − 1)!/n! 1
pairs C(n, 2) (n − 2)!/n! −1/2!
triples C(n, 3) (n − 3)!/n! +1/3!
m-fold C(n, m) (n − m)!/n! (−1)ᵐ⁺¹/m!

So P(no fixed point) = 1/2! − 1/3! + ⋯ + (−1)ⁿ/n!, a partial sum of the series for e⁻¹ = .3678794 [23]. At n = 4 the sum is 1/2 − 1/6 + 1/24 = .375, the nine-in-24 counted directly above.

Where the ideas came from

The counting principle is “such a self-evident result” that the source, following N. L. Biggs, looks for early instances of it rather than a discovery [24]. Its historical remarks, arranged by date:

When What Cite
about 1650 B.C. a table on a mathematical manuscript listing the powers 7¹ to 7⁵, labelled houses, cats, mice, wheat and hekat; on one suggested reading the table counts the grain the cats saved; “It is not clear why the writer of the table wanted to add the numbers together” [24]
by 300 B.C. examples of the n! rule for permutations, which “seems to have occurred first in India” [25]
Euclid an early use of factorials: for each n, some prime exceeds n but not n! + 1, so the primes never run out [25]
eleventh century the general n! formula “seems to have been well known in India and then in the Arab countries” [25]
1708 first printing of de Montmort’s probability book, with the hat check problem posed as the card game Treize [26]
at least 1730 the St Ives nursery rhyme of sevens [24]
1730 Stirling’s formula in his Methodus Differentialis [28]
1950s the birthday problem made popular by Feller’s book; “Problems of this type were first discussed by von Mises” [27]

De Montmort’s count. Let wₙ count the derangements (permutations fixing nothing) on n elements. The recursion the source gives from de Montmort is wₙ = (n − 1)(wₙ₋₁ + wₙ₋₂) for n ≥ 3, with w₁ = 0 and w₂ = 1, and the source adds that “it is easy to prove by induction” that wₙ = n·wₙ₋₁ + (−1)ⁿ [26]. Our check: both rules give w₃ = 2 and w₄ = 9, the nine derangements of 1234 listed earlier, and w₄/4! = .375. Divided by n!, wₙ gives the alternating sum of the hat check section, near e⁻¹ ≈ .368 for large n [26]. De Montmort’s interest was Treize: in the simplified game he considered, the count called out and the card numbers both run from 1 to 13, so a game with no match is a derangement of 13 [26]. In the source’s words, “David remarks that this was possibly the first use of the exponential function in probability” [26].

The full game. In Treize as played, the dealer goes on until 13 cards in a row pass with no match. Two values for the dealer’s expected win from each player staking 1 [27]:

Calculated by Value
de Montmort about .801
Peter Doyle, exactly a ratio of two very long integers, printed in full in the source; .803 to three decimals

Stirling and de Moivre. De Moivre’s approximation for the binomial’s central term, 2B/√n, left B as an infinite series; the source describes his version as found “without identifying the constant π” [28]. In de Moivre’s words, “my worthy and learned Friend, Mr. James Stirling” found that B “did denote the Square-root of the Circumference of a Circle whose Radius is Unity” [28]. In modern terms that is √(2π) ≈ 2.5066, the constant in Stirling’s formula above.

Not covered here

Generating random permutations by computer, records in permutations, the Galton board and the power-curve example, Bose–Einstein versus Fermi–Dirac sample spaces (section 3.2’s “Choosing a Sample Space”), the chapter’s exercises, section 3.3 (card shuffling, from p. 120), and the rest of section 3.2 from page 107 on. Nothing is claimed about counting in computer science or statistics beyond the source’s examples.

Sources

  • [1]Grinstead, C. M. and Snell, J. L., Introduction to Probability, §3.1, p. 75 (chapter aim; Example 3.1, Émile’s restaurant, 12 menus). View at source ↗
  • [2]Same, §3.1, pp. 75–76 (stage independence stated p. 75; “A Counting Technique” and “Tree Diagrams”, 8/10 · 1/2 = 4/10, p. 76). View at source ↗
  • [3]Same, §3.1, p. 77 (Example 3.2, shared initials). View at source ↗
  • [4]Same, §3.1, p. 77 (Example 3.3 opening: 183 guess, 23). View at source ↗
  • [5]Same, §3.1, pp. 78–79 (derivation of pᵣ, “n down r”; Tables 3.1 and 3.2; birthdays not equally likely). View at source ↗
  • [6]Same, §3.1, p. 79 (Definition 3.1; rearrangements of {1, 2, 3}). View at source ↗
  • [7]Same, §3.1, p. 80 (Theorems 3.1 and 3.2; Definition 3.2; factorials, 0! = 1; Table 3.3). View at source ↗
  • [8]Same, §3.1, p. 81 (Definition 3.3; Theorem 3.3, Stirling’s formula; Table 3.4; ratio versus difference). View at source ↗
  • [9]Same, §3.1, p. 82 (Fixed points: 1/e for n ≥ 10, average 1; library and hat check problems). View at source ↗
  • [10]Same, §3.2, p. 93 (Example 3.5; binomial coefficients; 2³ = 8). View at source ↗
  • [11]Same, §3.2, p. 93 (Theorem 3.4, equation (3.1), and proof; convention C(n, j) = 0 outside 0 ≤ j ≤ n). View at source ↗
  • [12]Same, §3.2, p. 94 (Pascal’s triangle, Figure 3.3; C(5, 2) = 6 + 4 = 10). View at source ↗
  • [13]Same, §3.2, p. 94 (Theorem 3.5, equation (3.2), and proof). View at source ↗
  • [14]Same, §3.2, p. 95 (n!/(j!(n − j)!); symmetry; n need not be a positive integer, j must be a non-negative integer). View at source ↗
  • [15]Same, §3.2, p. 95 (Example 3.6, poker hands: the counting method). View at source ↗
  • [16]Same, §3.2, pp. 96–97 (Definition 3.5; Example 3.7, roulette 18/38 = .474). View at source ↗
  • [17]Same, §3.2, pp. 96–97 (binary tree, Figure 3.4 on p. 96; pqp; b(3, p, j)). View at source ↗
  • [18]Same, §3.2, p. 98 (Theorem 3.6 and proof; Examples 3.8 and 3.9; 100 tosses, about .08). View at source ↗
  • [19]Same, §3.2, p. 99 (Table 3.8; Definition 3.6; symmetry at p = .3; np). View at source ↗
  • [20]Same, §3.2, p. 103 (Theorem 3.7, Binomial Theorem, and proof). View at source ↗
  • [21]Same, §3.2, pp. 103–104 (Corollary 3.1 and proof; 2ⁿ subsets). View at source ↗
  • [22]Same, §3.2, pp. 104–105 (Theorem 3.8, equation (3.3), and proof). View at source ↗
  • [23]Same, §3.2, pp. 105–106 (Example 3.12, hat check by inclusion–exclusion; Table 3.9; e⁻¹ = .3678794). View at source ↗
  • [24]Same, §3.1, pp. 84–85 (Historical Remarks: Biggs; St Ives rhyme, 1730; the 1650 B.C. table). View at source ↗
  • [25]Same, §3.1, p. 85 (Euclid’s primes; n! rule in India, 300 B.C., eleventh century). View at source ↗
  • [26]Same, §3.1, pp. 85–86 (de Montmort 1708, Treize; derangement recursion; e⁻¹ ≈ .368; David’s remark). View at source ↗
  • [27]Same, §3.1, pp. 86–87 (Treize rules; .801; Doyle’s exact answer, .803; birthday problem history, von Mises, Feller). View at source ↗
  • [28]Same, §3.1, p. 88 (Stirling 1730, Methodus Differentialis; de Moivre’s quotation). View at source ↗

Wikipedia was not used as a source.

Works cited