Latin Rectangles · A mathematical walkthrough

Counting legal third rows

Count one more row without listing every possibility. Follow the forbidden assignments into a rook count, then watch inclusion–exclusion keep exactly the legal rows.

Play at a reading pace, pause anywhere, or select a chapter. The board uses columns horizontally and symbols vertically.

Read the mathematics without motion

Count violations, then cancel them

The two existing rows are the identity and π = [2,1,4,3,6,7,8,5]. Their 16 used positions are the forbidden board. A proposed row is a permutation, so selected forbidden assignments can coexist only when they share neither a column nor a symbol.

Let rj count selections of j nonattacking forbidden squares. A selection fixes j assignments and leaves (8−j)! unrestricted completions. These completions may have further violations.

A permutation with t > 0 violations has total weight (1−1)t = 0. A permutation with none contributes one. Here the rook coefficients are (1,16,104,352,662,688,376,96,8), giving 4,744 legal third rows.

Components give the rook counts

Disjoint graph components use disjoint columns and symbols. Choose a matching in each, then combine them: the number of choices multiplies and the numbers of rooks add.

The full library

This example illustrates the specialized two-row structure. For general k-row starts, the same rook and inclusion–exclusion argument uses matchings in the forbidden bipartite graph; its components need not be cycles. Component matching is exponential in the largest component. Multiple added rows are ordered extensions and are intended for small-n exact work.

Two-row cycle polynomials also admit Touchard’s reduction, using qℓ(t) = tℓRℓ(−1/t), with formal q0 = 2. This is Touchard’s established counting identity. The current walkthrough explains the inclusion–exclusion mechanism; the README retains the full reversed-polynomial derivation and attribution.