Invariants, the Trick of Finding What Never Changes
Discover how a quantity that survives every move proves that some goals are impossible, with puzzles worked from parity to coloring.
Key takeaways
- An invariant is unchanged by every allowed move, so it is the same at the start and at every reachable position.
- Different invariant values prove that a target is unreachable, while equal values prove nothing by themselves.
- Parity, remainders, colorings, sums and products are the first candidates to test.
- A quantity that only ever moves in one direction, called a monovariant, can prove that a process must stop.
An invariant is a quantity or property that stays the same however you carry out the allowed moves. If your starting position and your target have different values of that quantity, then no sequence of moves, however long or clever, can take you from one to the other.
That one idea settles questions that trial and error never could. You cannot try infinitely many sequences of moves, but you can check each kind of move once and confirm that it leaves something fixed.
A first example with parity
Write the numbers 1 through 10 on a board. At each step, erase two numbers a and b and write the difference |a − b| in their place. After nine steps one number remains. Can it be 0?
Experimenting gives many different final numbers, but never 0. To see why, track the parity of the total, meaning whether it is even or odd.
start: 1 + 2 + ... + 10 = 55 odd
move: remove a + b, add |a − b|
change: if a ≥ b, change = (a − b) − (a + b) = −2b even
if b > a, change = (b − a) − (a + b) = −2a even
end: the last number has the same parity as 55 Every move changes the total by an even amount, so the total stays odd forever. The final number is the final total, so it is odd. It can never be 0, whatever order you choose.
Notice the shape of the argument. It says nothing about strategy. It looks at one general move and finds something the move cannot touch.
An invariant hiding in a product
Now change the rule. Start with 1, 2, 3, 4. Replace any two numbers a and b with a + b + ab. What is the last number?
The parity trick is no longer enough. Look instead at the quantity you get by adding 1 to each number and multiplying.
new number plus 1: a + b + ab + 1 = (a + 1)(b + 1)
so the product of all the (number + 1) values never changes
start: 2 × 3 × 4 × 5 = 120
end: (last number) + 1 = 120
last number = 119 The answer is forced. Every order of moves ends at 119. An invariant can therefore do more than prove impossibility: when it determines the final state completely, it computes the answer.
Coloring a board
Remove two opposite corner squares from an 8 by 8 chessboard. Can 31 dominoes, each covering two neighboring squares, cover the 62 squares that remain?
Color the board in the usual way. Each domino covers exactly one dark square and one light square, wherever you put it. So the difference between the number of covered dark squares and covered light squares is always 0.
Opposite corners share a color. The damaged board therefore has 32 squares of one color and 30 of the other. Covering it would need a difference of 2, which is impossible. The full argument appears in the mutilated chessboard.
Coloring is a favorite device because you may invent any coloring you like: stripes, three colors or a larger repeating block. The only requirement is that every allowed piece or move interacts with the colors in a predictable way.
Remainders as invariants
A remainder after division is often preserved when the numbers themselves change wildly. Adding the digits of a whole number leaves its remainder on division by 9 unchanged, because 10, 100, 1000 and so on each leave remainder 1.
That fact powers an old arithmetic check. Suppose someone claims that 347 × 26 = 9,032.
347 → 3 + 4 + 7 = 14 → remainder 5
26 → 2 + 6 = 8 → remainder 8
product of remainders: 5 × 8 = 40 → remainder 4
9032 → 9 + 0 + 3 + 2 = 14 → remainder 5
5 ≠ 4, so the claimed product is wrong The true product is 9,022, whose digits add to 13, giving remainder 4. A match would not have proved the answer right, since an error that is a multiple of 9 slips through. See casting out nines for more.
The color-changing creatures
A well-known puzzle imagines 13 gray, 15 brown and 17 red chameleons. Whenever two of different colors meet, both change to the third color. Can they all end up the same color?
Track the differences between the color counts. Suppose a gray and a brown meet.
change in counts: gray −1, brown −1, red +2
gray − brown changes by 0
gray − red changes by −3
brown − red changes by −3 The other two kinds of meeting behave the same way. So each difference keeps its remainder on division by 3. At the start the differences are 13 − 15 = −2, 15 − 17 = −2 and 13 − 17 = −4, none of them a multiple of 3.
If every chameleon were the same color, two of the counts would be 0 and their difference would be 0, a multiple of 3. That can never happen. The goal is unreachable, even though the total of 45 creatures could in principle all share one color.
Invariants inside an algorithm
Programmers and mathematicians use the same idea to show that a procedure gives the right answer. The Euclidean algorithm finds the greatest common divisor of two positive whole numbers by repeatedly replacing the larger one with the difference between them. Any number that divides both a and b also divides a − b and b, and the reverse holds too. So the greatest common divisor is invariant.
(84, 30) → (54, 30) → (24, 30) → (24, 6) → (18, 6) → (12, 6) → (6, 6)
the gcd is the same at every step, so gcd(84, 30) = 6 The invariant shows that the answer is correct. A second observation shows that the process ends: the sum of the two numbers is a positive whole number that decreases with every step. In programming, a condition that holds before and after each pass through a loop is called a loop invariant.
What invariants cannot do
The logic runs in one direction. Different values mean "unreachable". Equal values mean only "this particular test does not rule it out".
Sometimes a stronger invariant exists that settles the matter. Sometimes one can show that the invariant is complete, meaning that matching values always guarantee a path. That second result needs its own proof, usually by describing how to build the sequence of moves. The fifteen puzzle is a good example: a parity invariant rules out half of all arrangements, and a separate argument shows that all the others can be reached.
Monovariants and why processes stop
A monovariant is a quantity that changes only in one direction. It proves that some processes cannot go on forever.
Take a rectangular table of integers. A move consists of choosing a row or column whose sum is negative and flipping the sign of every entry in it. Must you eventually run out of moves?
Yes. Flipping a line with negative sum s replaces s with −s, so the total of the whole table rises by −2s, a positive amount. The total strictly increases with every move. There are only finitely many ways to assign signs to the entries, so only finitely many tables can ever appear. The process must end, and it ends with every row sum and column sum at least 0.
A simpler case: a chocolate bar of 4 by 6 squares must be broken into single squares, one straight break of one piece at a time. Each break increases the number of pieces by exactly 1. Going from 1 piece to 24 takes 23 breaks, no matter how you choose them.
Invariants across mathematics
The same thinking runs through whole fields. For a convex polyhedron, vertices minus edges plus faces equals 2. A cube gives 8 − 12 + 6 = 2. This is the starting point of the Euler characteristic, which stays fixed when a surface is bent or stretched and so can tell a sphere from a doughnut shape.
In knot theory, a property called tricolorability survives every deformation of a knot. The trefoil has it and a plain loop does not, so the trefoil cannot be untangled. Knot invariants develop this much further.
Physics has its conserved quantities, such as energy and momentum under suitable conditions. Noether's theorem connects them to symmetries.
Finding an invariant yourself
When a puzzle asks whether something can be done, try this routine.
- Carry out several moves by hand and record the position each time.
- Compute simple summaries of each position: the sum, the sum's parity, the product, a remainder.
- Look for anything that repeats exactly, then prove it for a general move.
- For boards and grids, color the squares and count each color under a single move.
- If a quantity changes but only upward or only downward, use it as a monovariant.
- Compare the start with the goal.
Try one: a knight is on a 5 by 5 board. Can it visit every square exactly once and return to where it began? A knight always moves to a square of the opposite color, so after an odd number of moves it is on the opposite color from its start. A round trip through 25 squares takes 25 moves, so it is impossible. Symmetry is the natural companion to this tool: one looks for what moves preserve, the other for what the problem itself preserves.