MathLabs

Combinatorics and discrete mathematics

Invariants and monovariants

Quantities that stay fixed, or change monotonically, under the moves of a combinatorial process, used to prove impossibility.

IntuitionWhy some puzzles can never be solved

Remove two opposite corner squares from an 8×88\times 8 chessboard, leaving 6262 squares. Can you tile the remaining board with 3131 dominoes of size 2×12\times 1? Trying by hand fails every time, yet there are millions of ways to place dominoes. Instead of testing cases, look at the colors: each domino always covers 11 black square and 11 white square, so 3131 dominoes must cover 3131 black and 3131 white squares. But opposite corners of a chessboard have the same color, leaving 3232 squares of one color and 3030 of the other! The difference W−BW - B is an invariant of domino placement, and it proves impossibility in one line.

Interactive bipartite graph network illustrating parity and two-coloring invariants.
Bipartite coloring as an invariant: every edge (domino) connects one vertex from each side, so any perfect matching requires equal counts on both sides.

UndergraduateDefinitions: invariants and monovariants

Definition: Invariant and monovariant of a state system

Consider a combinatorial process with state space S\mathcal{S} and allowed transitions s→s′s \to s'. A function I:S→XI: \mathcal{S} \to X is an invariant if I(s′)=I(s)I(s') = I(s) for every valid move s→s′s \to s'. A real-valued function M:S→RM: \mathcal{S} \to \mathbb{R} is a monovariant (or potential function) if M(s′)<M(s)M(s') < M(s) (strictly decreasing) or M(s′)>M(s)M(s') > M(s) (strictly increasing) on every valid move.

I(s0)=I(s1)=⋯=I(sk)  ⟹  if I(starget)≠I(s0), starget is unreachableI(s_0) = I(s_1) = \cdots = I(s_k) \implies \text{if } I(s_{\mathrm{target}}) \neq I(s_0),\ s_{\mathrm{target}} \text{ is unreachable}
M(s0)>M(s1)>M(s2)>⋯≥0,M(s)∈N  ⟹  process terminates in ≤M(s0) stepsM(s_0) > M(s_1) > M(s_2) > \cdots \ge 0,\quad M(s) \in \mathbb{N} \implies \text{process terminates in } \le M(s_0) \text{ steps}
Common invariant and monovariant templates in competition and research problems
ToolTypical formWhat it proves
Parity invariantS mod 2S \bmod 2 or (−1)inversions(-1)^{\text{inversions}}Target state is unreachable
Modular / algebraic invariant∑ai mod m\sum a_i \bmod m or polynomial evaluationFinal configuration is uniquely determined
Integer monovariantM(s)∈NM(s) \in \mathbb{N} with M(s′)≤M(s)−1M(s') \le M(s) - 1Process must halt in ≤M(s0)\le M(s_0) steps

UndergraduateKey theorems: 15-puzzle parity and monovariant termination

In the 4×44\times 4 sliding 1515-puzzle, let N(s)N(s) be the number of tile inversions (pairs (i,j)(i,j) with i>ji > j such that tile ii appears before tile jj in row-major snake order) and let r(s)∈{1,2,3,4}r(s) \in \{1,2,3,4\} be the row of the blank square when reading in standard row-major order, or equivalently let d(s)d(s) be the Manhattan distance of the blank from the bottom-right corner. Then the parity (N(s)+r(s)) mod 2(N(s) + r(s)) \bmod 2 is invariant under every legal slide. In particular, the configuration with tiles 1414 and 1515 swapped is insolvable.

Why is it true?

A horizontal slide leaves the row-major order of the 1515 numbered tiles completely unchanged, while a vertical slide jumps one tile past exactly 33 other tiles in row-major order (changing the inversion count by ±1\pm 1 or ±3\pm 3, always odd) and simultaneously changes the blank's row r(s)r(s) by ±1\pm 1.

Proof

Step 1 (horizontal slides). When the blank slides left or right within the same row, no numbered tile changes its position in the row-major listing of the 1515 tiles, and the blank stays in row r(s)r(s). Thus ΔN=0\Delta N = 0 and Δr=0\Delta r = 0, so N(s)+r(s)N(s) + r(s) is unchanged.

Step 2 (vertical slides). When the blank slides up or down, the tile tt moving into the blank's old square shifts by 33 positions in the row-major sequence of the 1515 numbered tiles. Crossing each of those 33 tiles flips whether (t,u)(t, u) is an inversion, changing N(s)N(s) by +1+1 or −1-1 per tile. The total change is ΔN∈{−3,−1,+1,+3}\Delta N \in \{-3, -1, +1, +3\}, which is always odd. At the same time Δr∈{−1,+1}\Delta r \in \{-1, +1\} is also odd, so Δ(N+r)\Delta(N + r) is even.

Step 3 (swapping 14 and 15). Swapping tiles 1414 and 1515 with the blank fixed at row r=4r = 4 changes N(s)N(s) by +1+1 (from 00 to 11) while Δr=0\Delta r = 0. Hence (N+r) mod 2(N + r) \bmod 2 differs between the start state (1+4≡1(mod2)1 + 4 \equiv 1 \pmod 2) and the solved state (0+4≡0(mod2)0 + 4 \equiv 0 \pmod 2), proving no sequence of legal slides can reach the solved state.

Suppose every legal move s→s′s \to s' of a process decreases an integer-valued function M:S→ZM: \mathcal{S} \to \mathbb{Z} by at least 11, i.e. M(s′)≤M(s)−1M(s') \le M(s) - 1, and M(s)≥0M(s) \ge 0 for all states s∈Ss \in \mathcal{S}. Then starting from any state s0s_0, the process must terminate in at most M(s0)M(s_0) steps.

Why is it true?

You cannot step down a staircase of height M(s0)M(s_0) more than M(s0)M(s_0) times if each step drops at least one stair and you can never go below the ground floor 00.

Proof

**Step 1 (inductive bound after kk moves).** Let s0→s1→s2→⋯→sks_0 \to s_1 \to s_2 \to \cdots \to s_k be any sequence of kk valid moves. Applying the hypothesis M(si)≤M(si−1)−1M(s_{i}) \le M(s_{i-1}) - 1 for i=1,2,…,ki = 1, 2, \dots, k and summing telescopes the inequality to M(sk)≤M(s0)−kM(s_k) \le M(s_0) - k.

**Step 2 (upper bound on kk).** Since M(sk)≥0M(s_k) \ge 0 for every reachable state sk∈Ss_k \in \mathcal{S}, combining the two inequalities gives 0≤M(sk)≤M(s0)−k0 \le M(s_k) \le M(s_0) - k, which rearranges immediately to k≤M(s0)k \le M(s_0). Therefore no valid trajectory can have length k>M(s0)k > M(s_0), and the process must terminate in at most M(s0)M(s_0) steps.

AdvancedReal-World Applications and Worked Examples

In formal verification and software engineering, loop invariants and ranking functions (monovariants) are the standard way proof assistants (Lean, Coq, Dafny) certify that critical algorithms return the right answer and never hang in an infinite loop. In distributed consensus and chip-firing networks, algebraic invariants determine which load-balancing states are reachable.

Example: Erasing two numbers and writing their difference

The numbers 1,2,3,…,20261, 2, 3, \dots, 2026 are written on a blackboard. Each step, you erase two numbers a,ba, b and write ∣a−b∣|a - b| in their place, until a single number remains. Can the final number be 00?

Solution

Notice that ∣a−b∣≡a+b(mod2)|a - b| \equiv a + b \pmod 2, because (a+b)−∣a−b∣=2min⁡(a,b)(a + b) - |a - b| = 2\min(a,b) is always even. Thus the parity of the sum of all numbers on the board, S mod 2S \bmod 2, is an invariant!

Initially the sum is S0=2026×20272=1013×2027S_0 = \frac{2026 \times 2027}{2} = 1013 \times 2027. Since both 10131013 and 20272027 are odd, S0S_0 is odd (S0≡1(mod2)S_0 \equiv 1 \pmod 2). After 20252025 steps, the single remaining number must still be congruent to S0≡1(mod2)S_0 \equiv 1 \pmod 2, so it is odd and can never be 00.

Example: Untangling crossing segments in the plane

Given nn red points and nn blue points in general position in the plane, we pair them with nn straight segments. Whenever two segments A1B1A_1B_1 and A2B2A_2B_2 cross, we replace them with A1B2A_1B_2 and A2B1A_2B_1. Prove that this process must terminate in finitely many steps, leaving no crossings.

Solution

Define the potential L(s)=∑i=1n∣AiBi∣L(s) = \sum_{i=1}^n |A_iB_i|, the total Euclidean length of the nn segments. When A1B1A_1B_1 and A2B2A_2B_2 cross at a point PP, the triangle inequality in △A1PB2\triangle A_1 P B_2 and △A2PB1\triangle A_2 P B_1 gives ∣A1B2∣+∣A2B1∣<(∣A1P∣+∣PB2∣)+(∣A2P∣+∣PB1∣)=∣A1B1∣+∣A2B2∣|A_1B_2| + |A_2B_1| < (|A_1P| + |PB_2|) + (|A_2P| + |PB_1|) = |A_1B_1| + |A_2B_2|.

Thus L(s)L(s) is a strictly decreasing monovariant on every move! Since there are only n!n! possible matchings between the nn red and nn blue points, L(s)L(s) can take at most n!n! distinct values and cannot decrease more than n!−1n! - 1 times. Hence the process terminates in at most n!−1n! - 1 steps.

Why is it impossible to tile an 8×88\times 8 chessboard missing two opposite corners with 3131 dominoes of size 2×12\times 1?

Start with five numbers 1,2,3,4,51, 2, 3, 4, 5. Each step you may add 11 to any two of them. Can all five numbers ever become equal?

An integer-valued monovariant M(s)∈NM(s) \in \mathbb{N} starts at M(s0)=42M(s_0) = 42 and satisfies M(s′)≤M(s)−3M(s') \le M(s) - 3 on every legal move. What is the maximum number of moves before the process must halt?

When we replace two numbers a,ba, b by a+b+aba + b + ab, which algebraic quantity stays invariant across the whole list?

References

  1. Arthur Engel (1998). Problem-Solving Strategies · DOI:10.1007/b97682
  2. Jessica Striker (2017). Dynamical Algebraic Combinatorics: Promotion, Rowmotion, and Resonance · DOI:10.1090/noti1539