Showing posts with label simple. Show all posts
Showing posts with label simple. Show all posts

Saturday, 25 April 2026

Testing For Simple Permutations

Having explained what a simple permutation is in my previous post, I thought that testing the number associated with my diurnal age would be a good idea. Here is the output for today's number \( \textbf{28146} \) (permalink):

Simple Permutation Analyzer initialized...

--- Analyzing Number: 28146 ---

Intermediate Stage:

  Digits ranked descending: [8, 6, 4, 2, 1]

  Rank mapping (1=highest): {8: 1, 6: 2, 4: 3, 2: 4, 1: 5}

  Normalized permutation:   [4, 1, 5, 3, 2]

Result: False

Reason: Failed: Sub-block [3, 2] from digits [4, 6] forms an interval.

Alternative: Try 28416 instead. It is a simple permutation using your digits.

Having found that the digits 28146 do not form a simple permutation, the program finds a permutation that is simple, namely 28416. I tried entering a number with repeated digits and the number was regarded as invalid. I asked Gemini why:

The Definition of a Strict Permutation

The primary reason duplicate digits are rejected is rooted in the mathematical definition of a permutation. In combinatorics, a standard permutation is strictly defined as a rearrangement of a set of distinct, distinguishable items. Every item in the set must be unique.

When you introduce duplicate items (like the number 88234), you are no longer working with a standard set. You are working with what mathematicians call a multiset. While you can arrange the elements of a multiset, the rules, formulas, and structural properties change entirely.

The Problem of Ambiguity

Permutation theory relies on knowing exactly how many unique arrangements can be made. If all elements are distinct, a sequence of length n will always have n! (n factorial) possible arrangements.

However, duplicates introduce ambiguity. Imagine the number 122. Let's label the identical twos to tell them apart: 1, 2a, 2b. If we swap the two 2s, we get a structurally identical number:

    • Arrangement A: 1, 2a, 2b (Displays as 122)
    • Arrangement B: 1, 2b, 2a (Displays as 122)

Because swapping identical digits does not create a new, distinct sequence, the total number of unique arrangements drops. The mathematical framework built to analyze the structure of permutations assumes that every single shift in position creates a fundamentally new sequence. Duplicates break this assumption.

How Duplicates Break the "Simple" Math

Beyond the theoretical definition, duplicate digits physically break the mathematical logic used to define a simple permutation.

Recall the formula we used in the algorithm to test for intervals: max(block) - min(block) == length - 1. This formula only works because it assumes that an interval of distinct integers will have a predictable span. For example, a block of three distinct, consecutive numbers like {4, 5, 6} will always have a span of 2 (because 6 - 4 = 2, and the length 3 minus 1 is 2).

If we allow duplicates, this logic collapses. Consider a block of two identical numbers: {5, 5}.

    • The length of the block is 2.
    • The maximum value is 5.
    • The minimum value is 5.
    • max - min is 0.

The formula expects a span of 1 for a block of length 2. Because the span is 0, the math fails to recognize what is happening. Furthermore, the entire concept of a "continuous range of numbers" becomes nonsensical when numbers repeat. Does {5, 5} constitute an interval? What about {4, 5, 5, 6}?

Because the definition of simple permutations was explicitly designed to map the structural scattering of distinct integers, attempting to apply it to repeating digits forces the math to evaluate scenarios it was never designed to handle.

Fair enough. I've incorporated this algorithm into my daily number analysis. The no repeated digits restriction means that only xenodromes are acceptable input.

Simple Permutations

One of the properties associated with my diurnal age today (28146) is that it's a member of OEIS A111111:


A111111
: number of simple permutations of degree \(n\).


The initial members of this sequence beginning with \(n=1\) up to \(n=9\) are 1, 2, 0, 2, 6, 46, 338, 2926 and 28146.

I did not understand the explanation in the OEIS comments about what a simple permutation of degree \(n\) was so I turned to Gemini for help and its response forms the content of this blog post. I got NotebookLM to create a video overview of the post and then uploaded it to YouTube.

Understanding Simple Permutations

To understand OEIS A111111, it helps to think of the problem in terms of finding "hidden chunks" or "blocks" within a sequence of numbers.

The core rule is this: a permutation is simple if you cannot find any contiguous sub-sequence of length 2 or more (but less than the total length) that contains a continuous range of numbers, regardless of the order those numbers appear in.

Deconstructing the Example: 2647513

The comment in the sequence notes that the permutation 2647513 is not simple because of the interval of indices [2..5]. Let's map the positions (indices) to their actual values.

  • Position 1: 2
  • Position 2: 6
  • Position 3: 4
  • Position 4: 7
  • Position 5: 5
  • Position 6: 1
  • Position 7: 3

If we look strictly at positions 2 through 5, the numbers present are 6, 4, 7, and 5. If we sort that subset of numbers, we get 4, 5, 6, 7. This forms a perfect, unbroken mathematical sequence (an interval). Because we found a contiguous block of positions that maps to a contiguous block of values, and this block is smaller than the entire sequence but larger than a single number, the permutation fails the test. It is not simple.

Why is n=3 exactly 0?

Looking at the sequence (1, 2, 0, 2, 6, 46...), the third term is 0. This means there are absolutely zero simple permutations of length 3. We can prove this by testing all six possible permutations of the numbers 1, 2, and 3:

  • 123: Positions 1-2 contain {1, 2}. (Fails)
  • 132: Positions 2-3 contain {3, 2}, which sorts to {2, 3}. (Fails)
  • 213: Positions 1-2 contain {2, 1}, which sorts to {1, 2}. (Fails)
  • 231: Positions 1-2 contain {2, 3}. (Fails)
  • 312: Positions 2-3 contain {1, 2}. (Fails)
  • 321: Positions 1-2 contain {3, 2}, which sorts to {2, 3}. (Fails)

Every single permutation of length 3 contains an embedded chunk of length 2 that forms a continuous range. Therefore, none of them are simple.

The n=4 Case: The Two Survivors

The sequence tells us there are exactly 2 simple permutations for n=4. Out of the 24 possible combinations, only two survive the test: 2413 and 3142.

Let's test 2413 to see why it passes:

Check all chunks of length 2:

  • Positions 1-2: {2, 4} — Gap between 2 and 4.
  • Positions 2-3: {4, 1} — Gap between 1 and 4.
  • Positions 3-4: {1, 3} — Gap between 1 and 3.

Check all chunks of length 3:

  • Positions 1-3: {2, 4, 1} — Sorts to {1, 2, 4}. Missing the 3.
  • Positions 2-4: {4, 1, 3} — Sorts to {1, 3, 4}. Missing the 2.

Because no sub-sequence forms an unbroken chain of numbers, 2413 is a simple permutation. The same logic applies to 3142, making them the only two simple permutations of degree 4.

I then asked Gemini the following:
So in the case of n=9 we are looking at all permutations of the digits 123456789 and finding that there are 28146 simple permutations? Is that correct? Also, can you explain what is meant by a permutation of degree n. Is there a formula for calculating the number of simple permutations of degree n? 

The n=9 Case

For n=9, you are looking at all possible arrangements of the digits 1 through 9. There are 362880 total possible permutations for those nine digits (which is 9 factorial). If you were to test every single one of those 362880 arrangements for hidden consecutive blocks, you would find that exactly 28146 of them are simple permutations.

What is a "Permutation of Degree n"?

In combinatorial mathematics, the "degree" simply refers to the total number of elements in the set you are arranging.

  • A permutation of degree 4 means you are finding the arrangements of a set containing exactly 4 distinct items (usually the integers 1, 2, 3, and 4).
  • A permutation of degree n just means you are arranging the integers from 1 up to n.

It is just a formal way of stating the length of the string of numbers you are working with.

Is There a Formula?

There is no simple, single-line closed-form algebraic formula to instantly calculate the exact number of simple permutations for a specific degree. You cannot just plug n into a basic equation to get the answer.

Instead, mathematicians calculate exact values using generating functions and recurrence relations. The foundational logic is based on substitution decomposition: the idea that every standard permutation can be uniquely constructed by taking a simple permutation and "inflating" its individual points with other, smaller permutations. By knowing the total number of permutations (n!), mathematicians can work backward recursively to strip away the complex ones and isolate the count of simple ones.

However, there is a very elegant asymptotic formula for this sequence.

As the degree n becomes very large, the number of simple permutations, denoted as \( S_n\), can be approximated by:$$ S_n \approx \frac{n!}{e^2}$$Here, e is Euler's number. Because e2 is approximately 7.389056, this formula reveals a fascinating property of permutations: as the length of the number string approaches infinity, the probability that a randomly generated permutation will be simple approaches 1 / e2, or roughly 13.53%.

So, while calculating the exact integer for a specific degree requires heavy recursive computation, calculating the approximate scale of simple permutations for massive degrees is surprisingly straightforward.

I asked Gemini to give an example for the case of \(n=9\):


An Example for \(n=9\)

Here is one of the 28146 simple permutations of the digits 1 through 9:

4 1 7 3 9 6 2 8 5

To verify that this permutation is simple, we can apply the same logic used previously. We must ensure that no subset of contiguous positions (from length 2 up to length 8) contains a continuous range of values.

Why This Example Works

The easiest way to prove it is simple is to test the difference between the highest and lowest values within various blocks. If the difference between the maximum and minimum values in a block equals the length of the block minus 1, it forms a continuous interval.

  • Testing Length 2 Blocks: Let's look at the adjacent pairs: {4, 1}, {1, 7}, {7, 3}, {3, 9}, {9, 6}, {6, 2}, {2, 8}, and {8, 5}. None of these pairs are consecutive numbers. The smallest gap is 3 (between 1 and 4, 6 and 9, 5 and 8). Because no pair has a difference of exactly 1, there are no length 2 intervals.
  • Testing Length 4 Blocks: If we take the first four positions (4, 1, 7, 3), the highest value is 7 and the lowest is 1. The span is 6, which is much larger than the block length of 4. If we take the last four positions (6, 2, 8, 5), the highest is 8 and the lowest is 2. The span is 6. Because the numbers are scattered, they do not pack tightly enough to form an interval.
  • Testing Length 8 Blocks: If we take the first eight numbers (4, 1, 7, 3, 9, 6, 2, 8), the values range from 1 to 9. The only missing number is 5. Because 5 is missing from the middle of the set, the remaining numbers cannot form an unbroken sequence. The same applies to the last eight numbers (1, 7, 3, 9, 6, 2, 8, 5), which are missing the 4.

Because this "scattering" holds true for every possible block size between 2 and 8, the permutation strictly avoids all intervals and perfectly satisfies the definition of a simple permutation.

I asked Gemini the following: 

Of what use are simple permutations? Are there any practical applications or is the concept purely theoretical.

While simple permutations originated as a purely theoretical concept in combinatorial mathematics, they have proven to be surprisingly useful in several practical, real-world applications. Because mathematics is the language of structure, these "irreducible" sequences provide the foundational logic for any field that needs to analyze, dismantle, or scramble data.

Here is a breakdown of how simple permutations bridge the gap between pure theory and practical application.

The "Prime Numbers" of Permutations (Theoretical Foundation)

Before looking at applied fields, it is helpful to understand their role in pure mathematics. Just as every integer can be factored into a unique set of prime numbers, every single permutation can be uniquely broken down into a "tree" of simple permutations through a process called substitution decomposition. In this sense, simple permutations are the fundamental, indivisible building blocks of all mathematical sequences.

Bioinformatics and Evolutionary Genomics

One of the most robust practical applications of this concept is in computational biology, specifically regarding genome rearrangement.

When scientists compare the DNA sequences of different species, they look at how chunks of genes have moved around over millions of years of evolution. A sequence of genes in a fruit fly might be a permuted version of the same genes in a mosquito. If a block of genes moves together as a single, unbroken unit during evolution, it forms an "interval" (meaning the permutation of that genome is not simple).

Simple permutations represent the extreme cases of genetic mutation: complete and total structural rearrangement where no contiguous blocks of genes have been preserved intact. By programming algorithms to search for and isolate these simple permutation structures, geneticists can map exactly where and how evolutionary divergence occurred.

Computer Science and Algorithm Optimization

In computational analysis, particularly when writing custom data analysis scripts in Python or SageMath, efficiency is critical. Because every complex sequence can be mathematically decomposed into a structural tree of simple permutations, computer scientists use these trees to drastically speed up sorting and search algorithms.

Problems involving "permutation pattern matching" that would normally take an impossible amount of exponential computing time can often be reduced to manageable polynomial time. The algorithm simply breaks the massive dataset down into its simple permutation components first, and then solves the problem on those smaller, irreducible blocks.

Cryptography and Data Diffusion

A secure cryptographic cipher relies on two primary principles: confusion and diffusion. Diffusion requires that a small, localized change in the input data is spread completely across the entire output data.

Because the strict definition of a simple permutation means it perfectly avoids forming neat, predictable blocks of adjacent numbers, it represents a state of maximum "scattering." This mathematical framework helps cryptographers design the substitution-permutation networks (the architecture behind modern encryption standards like AES) that resist pattern analysis and keep digital communications secure.

While you may never see a simple permutation explicitly named in a piece of commercial software, the mathematical rules governing them are silently working behind the scenes to optimize data, track genetic history, and secure information.

Saturday, 6 February 2021

Hamiltonian Paths and Knight's Tours

I encountered Hamiltonian paths before but never in the context of my daily number count. The reason is clear when we look at Figure 1 showing the initial members of OEIS A003216:

  
   A003216

Number of Hamiltonian graphs with \(n\) nodes.     
 

Figure 1: source

Looking at Figure 1, it can be seen that \(n\)=8 yields a value of 6196 but \(n\)=9 yields a value of 177083. This is a massive jump that completely misses the numbers that I am traversing as I track my diurnal age. Currently I am 26241 days old and one of the properties of this number is that it is a member of OEIS A283420 where \(n\)=9:

   
  A283420

Number of simple (not necessarily connected) untraceable graphs on \(n\) nodes.     
   

Even in the A283420 sequence the numbers get large very quickly. Here are the values from \(n\)=1 to 11: 0, 1, 2, 6, 16, 65, 310, 2316, 26241, 522596, 18766354. My current diurnal age just happened to be a member of this sequence and this is what led me to reacquaint myself with Hamiltonian graphs. Figure 2 shows all the possible non-Hamiltonian graphs for the case of \(n\)=5:


Figure 2: source

Looking at Figure 2, the distinction between graphs that are connected and those that are disconnected is apparent. But what about the terms simple and untraceable? At this point, it's a good idea to define separately what is meant by a simple graph and traceable graph (which will then explain an untraceable graph).

To quote from WolframMath World:
A simple graph, also called a strict graph, is an unweighted, undirected graph containing no graph loops or multiple edges. A simple graph may be either connected or disconnected. Figure 3 shows the differences between a simple graph and a nonsimple one:

Figure 3: source
A traceable graph is a graph that possesses a Hamiltonian path. Hamiltonian graphs are therefore traceable, but the converse is not necessarily true. The numbers of traceable graphs on \(n\)=1, 2, ... are 1, 1, 2, 5, 18, 91, 734, ... (OEIS A057864), where the singleton graph \(K_1\) is conventionally considered traceable. The first few are illustrated in Figure 4, with a Hamiltonian path indicated in orange for each. Source.

Figure 4: source

Comparing Figures 2 and 4, it can be seen what it is that defines a Hamiltonian path and a Hamiltonian cycle:
A Hamiltonian path or traceable path is a path that visits each vertex of the graph exactly once. A graph that contains a Hamiltonian path is called a traceable graph ... A Hamiltonian cycle, Hamiltonian circuit, vertex tour or graph cycle is a cycle that visits each vertex exactly once. A graph that contains a Hamiltonian cycle is called a Hamiltonian graph. Source.
Figure 5 shows a Hamiltonian cycle for the dodecahedron. 


Figure 5: source

A knight's tour can be viewed as either a Hamiltonian cycle or path when each square is regarded as a vertex:
A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square exactly once. If the knight ends on a square that is one knight's move from the beginning square (so that it could tour the board again immediately, following the same path), the tour is closed; otherwise, it is open. The knight's tour problem is an instance of the more general Hamiltonian path problem in graph theory. The problem of finding a closed knight's tour is similarly an instance of the Hamiltonian cycle problem. Unlike the general Hamiltonian path problem, the knight's tour problem can be solved in linear time. Source.
Figure 6 shows an open knight's tour that is a Hamiltonian path but not a cycle:


Figure 6: source
It has been shown that closed knight's tours are possible on any \(m\) x \(n\) board with \(m\) ≤ \(n\) unless one or more of these three conditions are met:
  • \(m\) and \(n\) are both odd
  • \(m\) = 1, 2, or 4
  • \(m\) = 3 and \(n\) = 4, 6, or 8
On an 8 × 8 board, there are exactly 26,534,728,821,064 directed closed tours (i.e. two tours along the same path that travel in opposite directions are counted separately, as are rotations and reflections). The number of undirected closed tours is half this number, since every tour can be traced in reverse. Source. 

Finally let's not fail to mention the great mathematician, Sir William Rowan Hamilton, after whom the Hamiltonian paths and cycles were named. Figure 7 shows a photograph of him.


Figure 7: Hamilton (1805-1865)

For a brief account of his life, follow this link.