How this calculation works
Build a canonical strong-interval decomposition tree and reconstruct the supplied permutation from its quotient labels.
[i,j] is an interval iff max(π_i…π_j)−min(π_i…π_j)=j−i; strong intervals overlap no other interval.A worked example
The permutation 2143 decomposes as 12[21,21]: an increasing root with two decreasing two-point children, reconstructing 2,1,4,3.
Good to know
One-line permutations of 1…n,n=1–50. Enumerate consecutive position intervals whose values are consecutive, identify nonoverlapping strong intervals and build an ordered containment tree. Internal quotient labels ascending, descending or simple; merge adjacent monotone nodes under a stated canonical convention. Return interval certificate and exact reconstruction. No generalized word substitution.
Reference: SageMath permutations: simple permutations and intervals (opens in a new tab) ↗
Enter one permutation in position order
Supply a permutation of one through n for n from one through fifty. Entries must be distinct and cover that exact label set. The input order is the position order used by the interval tree. Replacing the permutation by a sorted list destroys the structure being studied, even though it retains the same values.
The output is a decomposition of this one permutation, not a substitution rule on arbitrary words. Leaves correspond to original positions. Internal nodes group consecutive positions whose values form a consecutive integer range. Labels such as increasing, decreasing and simple describe quotient permutations at nodes rather than numerical trends fitted to the whole input.
Compare this with the Graph modular decomposition calculator with strong modules. Find common intervals of a permutation, select strong intervals, construct its substitution decomposition tree and reconstruct it by inflation. Existing graph modular decomposition works on graph neighborhoods; converting a permutation to its inversion graph loses permutation-specific positional/value order and does not supply the ordered inflation factors.
Find position-value intervals
A consecutive position segment is a permutation interval when its values are consecutive integers in some order. Distinctness makes the test max minus min equals segment length minus one sufficient. Single positions and the whole permutation always qualify. Other segments can be intervals even when their displayed values are internally scrambled.
Two intervals overlap when they intersect but neither contains the other. A strong interval overlaps no interval of the permutation. Strong intervals form a nested or disjoint family, allowing an ordered containment tree. Using every interval as a tree node would fail because overlapping intervals need not fit into a single parent-child hierarchy.
Construct quotient labels at each node
The maximal proper strong intervals inside a node become its children, ordered from left to right by position. Their value ranges are disjoint and consecutive. Standardizing the order of those ranges gives the node’s quotient permutation, which explains how the child blocks are arranged by value.
Classify a quotient as increasing, decreasing or simple. A simple quotient has no proper nontrivial interval. Apply the declared canonical convention that flattens adjacent monotone nodes of the same direction, so equivalent nested descriptions do not produce different trees. Retain exact child intervals and quotient arrays; a visual label alone is insufficient for reconstruction.
Check the decomposition of 2143
Positions one and two contain values {1,2}, and positions three and four contain {3,4}. Both are strong intervals, and their value ranges occur in increasing order. The root quotient is therefore 12. Each child contains a decreasing pair, giving child quotients 21 and 21.
Inflating the first root position by 21 uses values 1,2 and produces 2,1. Inflating the second by 21 uses values 3,4 and produces 4,3. Concatenating yields 2,1,4,3 exactly. This reconstruction checks both position order and allocation of value ranges, rather than merely reproducing the input length.
Read the tree from leaves to root
The figure shows an increasing root above two decreasing children, each above two leaves. A leaf is a single entry with no remaining internal arrangement. Moving upward combines child blocks according to the quotient at the parent. The tree organizes simultaneous position and value structure; it is not a binary search tree built by insertion.
The returned interval certificate should name each node’s position endpoints and value range. Verify that children partition the parent’s positions without gaps and that their ranges partition its values. Then check the quotient rank order. These local checks explain why the final inflation reconstructs the original permutation and why the strong-interval hierarchy is consistent.
Handle monotone and simple extremes
An increasing permutation has one increasing root with singleton children under the flattened convention. A decreasing permutation behaves analogously. A simple permutation of length at least four has no proper nontrivial intervals, so its root quotient is the whole permutation with singleton children. Length one has only its leaf.
These cases are valid structures, not failures to find a more detailed tree. Two-entry monotone quotients are treated by the monotone convention, avoiding ambiguity over whether tiny permutations should be called simple. The exact convention should accompany exported trees so another implementation can compare equivalent representations without mistaking harmless nesting differences for a structural disagreement.
Use decomposition rather than occurrence search
A classical pattern occurrence may use nonconsecutive positions and values, while a permutation interval requires consecutive positions and a consecutive value set. Pattern avoidance therefore answers a different question. A tree built from strong intervals summarizes substitution structure, not every occurrence of every smaller permutation.
For a reproducible certificate, retain the original permutation, all strong intervals, the ordered tree and exact reconstruction. The supported size makes direct interval enumeration practical; no heuristic clustering is needed. Any claim about an application of the decomposition, such as sorting complexity or a pattern-class theorem, requires additional arguments beyond the tree itself.
A few questions, answered
Is every interval a strong interval?
No. A strong interval must overlap no other interval.
What does a quotient label describe?
It records the relative value order of the node’s consecutive child blocks.
Why flatten adjacent monotone nodes?
It fixes a canonical representation when equivalent monotone nesting is possible.
How can I verify the tree?
Inflate its quotient labels recursively and check exact reconstruction of the original permutation.