Bijections and the Division Rule
Two more counting tools come from the mapping rules of Finite Cardinality. The bijection rule counts a set by matching it with one that is easier to count. The division rule counts objects when each one has been counted the same number of times, , by dividing by . Together they explain the formulas for combinations, circular arrangements and arrangements with repeated letters.
The bijection rule
If there is a bijection , then .
Example: emoji packs. A chat app sells packs of 9 stickers, and each sticker is one of 4 designs (cat, dog, fox, owl); only the number of each design matters. Write a pack as a string of 9 stars (stickers) and 3 bars (separators between designs). For instance
*** | | ***** | *means 3 cats, no dogs, 5 foxes and 1 owl. Every pack gives exactly one string and every string of 9 stars and 3 bars gives one pack, so we count strings of length 12 with 3 bars: choose the 3 bar positions, . This is the stars and bars method. In general, choosing items from kinds with repetition can be done in ways.
from itertools import combinations_with_replacement
from math import comb
designs = ["cat", "dog", "fox", "owl"]
count = sum(1 for _ in combinations_with_replacement(designs, 9))
print("by enumeration:", count, " stars and bars:", comb(12, 3))by enumeration: 220 stars and bars: 220
The division rule
If is -to-1 (every element of is the image of exactly elements of ), then
Round tables. Seat people at a round table, where only who sits next to whom (in which order) matters, not which chair. Map each row arrangement to the circular seating obtained by bending the row into a circle. Each circular seating comes from rows (one per starting point), so there are circular seatings.
Combinations. How many -element subsets does an -element set have? Map each -permutation (ordered choice of items) to the set of its items. Each -set is the image of orderings, so
Anagrams and multisets
How many distinct arrangements does the word BANANA have? If the letters were all different there would be . But swapping the three A's among themselves gives the same word ( ways), and swapping the two N's too ( ways). Each distinct word is counted times:
from itertools import permutations
from math import factorial
word = "BANANA"
distinct = set(permutations(word))
print("distinct arrangements:", len(distinct))
print("formula:", factorial(6) // (factorial(3) * factorial(2) * factorial(1)))
print("examples:", sorted("".join(p) for p in distinct)[:5])distinct arrangements: 60
formula: 60
examples: ['AAABNN', 'AAANBN', 'AAANNB', 'AABANN', 'AABNAN']
This is the bookkeeper rule, studied in the next lesson.
In software
The division rule is how you count objects "up to symmetry": distinct necklaces, distinct game boards up to rotation, distinct molecules. Hash-based deduplication of permutations (store a sorted tuple as the canonical form) implements the -to-1 map in code. Stars and bars counts the ways to distribute identical tasks among workers or to split a budget into whole units.
Exercises
Exercise 1: Committees
How many 3-person committees can be chosen from 10 people? Use the division rule.
Answer
Solution
ordered choices; each committee is counted times. .
Exercise 2: Anagrams
How many distinct arrangements does MISSISSIPPI have?
Answer
Solution
11 letters: M once, I four times, S four times, P twice.
Exercise 3: Stars and bars (code)
In how many ways can 10 identical tasks be assigned to 4 servers if each server must get at least 1 task? Use stars and bars and check by brute force.
Answer
.
Solution
Give each server 1 task first; then distribute the remaining 6 freely: .
from math import comb
brute = sum(1 for a in range(1, 11) for b in range(1, 11) for c in range(1, 11) if 1 <= 10 - a - b - c)
print(brute, comb(9, 3))84 84
Test yourself
In how many ways can 7 people sit around a round table (rotations considered the same)?
- 5040
- 720
- 7
- 120
How many distinct arrangements does the word LEVEL have?
- 120
- 60
- 30
- 20
How many ways can you choose 5 scoops from 3 ice cream flavours (repetition allowed, order irrelevant)?
- 15
- 21
- 10
- 243