The Power of Invariants

We can find invariants in many branches of mathematics. Let us try to use the theory of invariants to solve a few popular brainteasers.

The Power of Invariants

The history of mathematics has profound roots. We can seek first traces of using algebra in works of Babylonian mathematicians tracing back to almost 4000 years ago. With firm confidence, we even can say that they had enough knowledge for solving classic quadratic equations.

Babylonian clay tablet with an approximation of square root of 2 from Wikimedia

Since then, mathematics was growing at a decent pace, and people created many useful mathematical instruments. When mathematicians say instruments, they usually mean methods or techniques that they use for building logical statements. After, mathematicians join these statements into separate lemmas and lemmas later transform into theorems.

Probably we will not be able to enumerate all available techniques that could be used for building theorems in mathematics. However, we can remember a few popular ones: mathematical induction and proof by contradiction. Conventional education in undergraduate schools covers these two methods very well. In this article we will try to get a glimpse into other technique that is rarely mentioned formally but has enough power to solve many interesting problems.

Introducing the Invariants

Let us assume that we have a mathematical object and the set of transforms T. We can take any element of the set T and apply it to to change its state. In that way, we can form a chain of different states of x.

Chain of the states

After defining changes of our object x, we are ready to introduce our main function I. This function will be summarising any state of the object x.Potentially I may have almost any output. For example, it can output the natural number or set of rational numbers. It is crucial to be able to check equality of different outputs of the function I for different states of x.

Now if we can prove that our function I does not change its value if we apply any element of the set T to any state of x, then we can use that fact to prove logical statements. We will call I as an invariant on the set of objects produced with the set of transforms T.

Value of the invariant function do not change for any chain of states x

Let us consider examples from below to see how can we utilise invariants for proving logical statements.

Imaginary Islands

We will start with a simple example, and then we will try to increase complexity in a slow pace.

Let us pretend that we are imaginary people who live on the set of islands. Our task will be to formally prove that we cannot reach a particular island if a series of bridges do not connect it with our starting point.

Our small imaginary world from Wikimedia

We can walk freely inside our starting island. Because bridges connect only a few of them, we cannot reach all islands from the starting point. Let us identify each island and bridge with a number.

Number representation of islands and bridges

After it, we can introduce our invariant functions I. This function will be taking our current island where we stand and giving us a set of reachable islands as the output.

Example of schematic view of our world after mapping islands and bridges into numbers

Given the scheme from above, we can enumerate all possible outputs of function I.

Values of invariant function I

It is quite obvious that this function does not change its values if we move by bridges around our world because we defined it to behave like this. So if someone asked us whether we can reach island number from the island a, we could reformulate this question in term of values of function I.

Answering reachability questions using the function I

We synthetically built this example to show the main idea of using invariants, let us move to more interesting problems.

Chess puzzle

Imagine that we have got a chessboard, but not the ordinary one. Someone removed two cells from corners lying on the same diagonal.

Weird chessboard

The person who gave us this board also challenged us with a problem. He promised to give us 1000$ dollars if we will be able to fill this board using only 2dominoes pieces.

From first glance, this problem does not sound very hard. We removed even number of cells from the original board that had 64 cells, so placing dominos that take even number of the cells does not contradict anything.

After understanding it, we will probably accept a challenge without hesitation. Who does not want to have a spare 1000$?

Random fillings of the chessboard

Author of this article made a web version of such board, so we can find and present a proof that such cover exists. Please use the left button of the mouse to place a domino and the right button of the mouse to change the direction of the domino.

After trying to fill the whole board for a while, we will start to suspect something. Thought of impossibility of covering will start to rise in our heads. Let us try to use the method of the invariants to dissect this problem.

First of all, let us define invariant function I as a difference between the number of black cells and the number of white cells on the unfilled part of the table. The initial value of this function was equal to 0, but we increased it to 2 when we removed two cells of the same colour from the board.

Second of all, we can spot that one piece of domino always covers one black and one white cell, so placing any amount of dominoes never change the value of previously defined function I.

Our invariant function does not change its value when we place dominoes.

Can we see the contradiction now? The fully covered board should have the value of equals to 0, but we just showed that this value is impossible to reach if we place any number of dominoes.

Philosopher Max Black posted this problem in his book “Critical Thinking” in 1946.

14–15 puzzle

There is another quite famous puzzle that was proposed by the end of the 19th century by Sam Loyd. He was an American chess player who challenged the world to solve his variation of 15 puzzle.

Scrambled 15 puzzle game from Wikimedia

15 puzzle is a brainteaser where we should move tiles around the board to get the initial position of tiles numbered from 1 to 15. It is not hard to find an online version of this puzzle to see how it works. This puzzle was created about ten years before Sam Loyd by Noyes Palmer Chapman from Canastota, New York. However, it became viral when Sam Loyd offered 1000$ dollars to anyone who can solve his variation of the same puzzle named 14–15 puzzle.

14–15 puzzle of Sam Loyd where last two tiles are swapped from Wikimedia

Sam Loyd took the initial arrangements of tiles and swapped tiles with numbers 14 and 15. The goal remained the same — find a way to get the initial position of the tiles.

How can we use the power of invariants to solve this problem? Try to work on this problem before looking further.

Let us rearrange rows of the puzzle in one straight line.

Make one row from all tiles

That way we can index every cell by the number from 1 to 15 to get its value v.

The initial arrangement of the puzzle

We can map each move of tiles in the original puzzle into rearrangement of cells in this line.

Mapping of an original puzzle into the line for random moves

For this line, we can calculate the number of inversions. For every value from 1to 15 we should calculate how many values are less than starting to the right from the position of the cell having this value v.

Number of inversions for one particular cell, Ind function outputs 1 if input is true expression and 0 else

If we calculate the sum of all these values, it will give us the total number of inversions.

Total number of inversions

Now, we do the trick. Sum of the row index with empty cell and the total number of inversions is always even. This way we can define our invariant function I. It will output 0 if the sum is even and if the sum is odd.

Invariant does not change its value on random moves

We can find rigorous proof that will not change its value with every legal move in this paper. This proof uses theory of permutations to show it.

Now we can easily see the contradiction in proposed by Sam Loyd version of 14-15 puzzle. If we swap any two adjacent cells without changing initial position of empty cell, we will increase the number of inversion by 1, so will always have an odd number as the output. This fact shows us that it is impossible to reach the original arrangement of the board using only legal moves.

Can we go further?

Usage of invariants is not limited only to solving puzzles. We can find usage of this rich method in many areas of modern mathematics: complex analysis, the theory of differential equations and many others.

Identifying the possibility of using invariants and creation of appropriate function I for real problems could be seen as an art, and probably it is why mathematicians are falling in love with this branch of science.

I hope that this story also will help someone to love mathematics a little more.