User Rating 0.0 ā˜…ā˜…ā˜…ā˜…ā˜…
Total Usage 0 times
Order defines lexicographic baseline. Each token is one symbol.
Must contain every dictionary symbol exactly once.
Is this tool helpful?

Your feedback helps us improve.

ā˜… ā˜… ā˜… ā˜… ā˜…

About

Lexicographic ordering assigns a unique rank to every permutation of a finite set. The rank is computed via the Lehmer code, which encodes positional displacement against remaining unused symbols. For a permutation of n distinct elements, there exist n! total arrangements. Miscounting a single position cascades through every subsequent factorial weight, producing an entirely wrong index. This tool computes both directions: sequence → index (0-based) and index → sequence, using arbitrary-precision BigInt arithmetic so it handles dictionaries well beyond 20 symbols where 20! 2.43 Ɨ 1018 exceeds standard floating-point range.

The tool assumes all characters in the input sequence are distinct members of the supplied dictionary. Repeated characters violate the permutation constraint and are rejected. Dictionary order defines the lexicographic baseline. Changing the dictionary order changes the rank. Pro tip: for numeric systems (base-n positional), supply digits in ascending order as your dictionary.

lexicographic permutation sequence index factoradic lehmer-code combinatorics

Formulas

The lexicographic rank of a permutation σ over n distinct symbols is computed via the Lehmer code:

rank = nāˆ’1āˆ‘i=0 Li ā‹… (n āˆ’ 1 āˆ’ i)!

where Li is the number of symbols in the remaining (unused) set that are lexicographically smaller than σi. The inverse operation recovers the permutation from an index:

Li = r(n āˆ’ 1 āˆ’ i)! , r ← r mod (n āˆ’ 1 āˆ’ i)!

where r is the running remainder initialized to the target index. At each step, the Li-th smallest remaining symbol is selected and removed from the available set.

Where: σ = input permutation, n = dictionary size (number of distinct symbols), Li = Lehmer code digit at position i, r = remainder during index decomposition, i = position index from 0 to nāˆ’1.

Reference Data

Dictionary Size nTotal Permutations n!Bits RequiredDigits in IndexExample Dictionary
3631A B C
424521 2 3 4
512073a b c d e
67201030 1 2 3 4 5
840,320165A B C D E F G H
103,628,8002270 1 2 3 4 5 6 7 8 9
12479,001,600299A B C D E F G H I J K L
151,307,674,368,0004113a b c d e f g h i j k l m n o
186,402,373,705,728,0005316A through R
202,432,902,008,176,640,0006119a through t
26≈ 4.03 Ɨ 10268927A through Z (full alphabet)
30≈ 2.65 Ɨ 103210833Custom 30-symbol set
36≈ 3.72 Ɨ 1041138420-9 + A-Z (alphanumeric)

Frequently Asked Questions

In combinatorics, the first permutation in lexicographic order (the identity permutation matching dictionary order) has rank 0. The last permutation has rank n! āˆ’ 1. This is consistent with the factorial number system where the all-zeros Lehmer code maps to rank 0. If you need 1-based indexing, simply add 1 to the output.
The tool rejects the input and displays an error toast identifying the invalid character(s). Every symbol in the sequence must exist exactly once in the dictionary. The Lehmer code algorithm requires a well-defined ordering over a known finite set - unknown symbols have no position and break the computation.
Yes. Separate dictionary entries with spaces. Each space-delimited token is treated as a single atomic symbol. For example, a dictionary of "01 02 03 04" defines four two-character symbols. Your input sequence must then use the same tokens separated by spaces.
The tool uses JavaScript BigInt for all factorial and rank arithmetic, so there is no upper overflow limit - it handles arbitrarily large dictionaries. However, the Lehmer code computation is O(n²) in the dictionary size n, so dictionaries beyond roughly 10,000 symbols may cause noticeable delay. For typical use (n ≤ 100), computation is instantaneous.
Absolutely. The rank is defined relative to the dictionary's ordering. If your dictionary is "B A C", then "B A C" is rank 0 (not 'A B C'). The tool uses the exact left-to-right order you provide. Rearranging the dictionary reassigns every permutation's rank. This is by design - lexicographic order is always relative to the underlying alphabet ordering.
This tool computes full permutations only - the input sequence must use every dictionary symbol exactly once. For k-permutations (arrangements of k items from n), the formula changes to n!/(nāˆ’k)! total arrangements with a modified Lehmer code. That is a different combinatorial object not covered here.