How this calculation works
Count permutations avoiding supplied classical patterns, or locate every occurrence of those patterns inside a fixed permutation.
An occurrence i₁<…<i_k satisfies rank(π(i₁),…,π(i_k))=pattern; avoidance means no occurrence.A worked example
For the forbidden pattern 123, counts for sizes 0…5 are 1,1,2,5,14,42. In 24135, the occurrences use positions (1,2,5),(1,4,5),(3,4,5).
Good to know
Enumeration n=0–9, up to 8 distinct classical patterns length 2–6. Exact backtracking with early occurrence pruning, count plus≤100 witness permutations and a size 0…ncount table;2,000,000 states cap. Occurrence mode permutation length≤30 with≤10000 occurrences displayed. No consecutive/vincular/mesh pattern convention silently substituted.
Reference: SageMath permutation reference: avoiding patterns (opens in a new tab) ↗
Choose counting or occurrence search
Counting mode enumerates permutations through a requested size n from zero through nine. Enter up to eight distinct forbidden patterns, each a permutation of one through its own length, with lengths two through six. Occurrence mode instead examines one supplied permutation of length at most thirty.
Patterns describe relative order, not literal values. The pattern 132 asks for three increasing positions whose first value is smallest and middle-position value largest. A pattern longer than the containing permutation has no occurrence. Multiple forbidden patterns are combined by avoidance of every pattern; separate input lines do not create separate independent counting problems.
Compare this with the Permutation inversion count distribution calculator. Count permutations avoiding a supplied finite family of classical order-isomorphic subsequence patterns; alternatively locate pattern occurrences in a supplied permutation. Inversion distributions describe pairwise inversions and do not detect arbitrary length 3–6 subsequence constraints. Existing word avoidance matches contiguous symbol strings, a different notion.
Keep the classical convention
Classical pattern positions form an increasing subsequence and need not be consecutive. Standardize the chosen values by replacing the smallest with one, the next smallest with two and so on. An occurrence exists when this standardized sequence equals the pattern exactly. The original permutation has distinct values, so ties do not arise.
This differs from consecutive, vincular and mesh pattern definitions, which impose extra restrictions. None are silently substituted. Position tuples are reported in increasing order and refer to the original permutation. Reading a value tuple as a position tuple can produce an incorrect witness even when both happen to use small integers.
Prune enumeration without changing the set
Build candidate permutations incrementally and reject a branch once an already formed subsequence realizes a forbidden pattern. Existing relative-order occurrences persist when more entries are added, so this pruning does not remove a possible avoider. Canonical permutation enumeration still visits every surviving object exactly once.
The calculator records counts from size zero through n, including the unique empty permutation. It also retains up to one hundred witness avoiders for display. A two-million-state cap limits the search; if reached, the final requested count is unresolved rather than the number seen so far. A witness display limit is different from a search-completion limit.
Check increasing triples explicitly
Avoiding 123 gives the sequence 1,1,2,5,14,42 through size five. At size three, all six permutations except 123 avoid the pattern, so the value five can be checked directly. At size five, complete independent enumeration of 120 permutations yields 42 avoiders.
For the supplied occurrence example 24135, increasing triples appear at positions (1,2,5), (1,4,5) and (3,4,5), with value triples (2,4,5), (2,3,5) and (1,3,5). Each standardizes to 123. Listing every index combination independently verifies that there are exactly three occurrences, including nonconsecutive ones.
Read a pattern witness in two steps
The figure connects selected positions while labeling their relative value order. First check that the positions increase from left to right. Then check only the ranks of the selected values. Unselected entries may lie between them or have values between them without affecting whether the chosen subsequence is an occurrence.
One permutation can have many occurrences of the same pattern. The occurrence list may therefore be truncated after ten thousand displayed tuples while preserving the exact counted total. Avoidance needs only the distinction between zero and positive occurrence count; the richer occurrence output explains exactly where a failed avoidance condition appears.
Interpret symmetries and small cases
Reversing positions, complementing values or taking permutation inverses transforms pattern problems in predictable ways. A corresponding transformation of both the pattern and containing permutation preserves occurrence existence. These operations provide useful checks, but they do not mean two different forbidden sets always have identical counts without a valid symmetry argument.
At n=0 there is one empty avoider for every supported forbidden set. At sizes below the shortest forbidden pattern, every permutation avoids all patterns, giving n factorial. These boundary values help detect accidental consecutive-pattern logic or a missing empty case. Duplicate forbidden patterns should not change the mathematical result.
Use exact counts within the declared scope
The counting output is a finite enumeration result, not a fitted asymptotic formula. A few initial values cannot establish a new closed form or prove equality of two pattern classes at every size. The witness permutations help explore examples, while completion status determines whether the requested finite count has actually been established.
Use occurrence mode when the question concerns one known permutation and counting mode when the whole avoidance class at a given size matters. Preserve the pattern list and the classical convention with exported results. Pattern avoidance is a relative-order question, so replacing the input by arbitrary ranks is valid only when all entries are distinct and their order is preserved. Occurrence positions remain meaningful even when unrelated entries are inserted between the selected indices.
A few questions, answered
Must pattern entries be adjacent?
No. Classical occurrences use arbitrary increasing position subsequences.
Why is the size-zero count one?
There is exactly one empty permutation, which avoids every nonempty pattern.
Are multiple forbidden patterns combined?
Yes. Counted permutations must avoid every listed pattern.
Does a truncated occurrence list mean an approximate count?
No. Display truncation is separate from exact counting.