Lexicographic and colexicographic order

Lexicographic (Lex) and colexicographic (CoLex) order are probably the most important ways to order tuples in mathematics.

Lex order is that of a dictionary.

CoLex order is obtained by reflecting all tuples, applying Lex order, and reflecting the tuples again.

Lex order is more intuitive for most people.

CoLex order is more practical when the finite sets of tuples to be ordered shall be generalized to infinite sets of sequences.

Both orderings can be reversed, so there are actually four different orderings.

They can also be reflected (see ), but that's not a different ordering of the set of tuples, but just a certain ordering written in a different way.

When the set of tuples contains all reflections, each reflected order is equal to some of the four others (see below).

Combinations
The sequence of the $$\scriptstyle \binom{n}{k}$$ k-subsets of $$\scriptstyle \{1,\ldots,n\}$$ in CoLex order is the beginning of the infinite sequence of k-subsets of $$\scriptstyle \{1,2,3,\ldots\}$$ in CoLex order. This corresponds to the increasing sequence = 7,11,13,14,19,21...

In the file on the left it can be seen that the blue patterns are horizontally reflected.

However, this is not the case in the file on the right, which shows only some of the subsets.

The triangle on the right shows 2-subsets of the integers. This corresponds to the sequence as a square array. The sequence of numbers (3,5,6,9,10,12...) corresponds to the CoLex ordering of 2-subsets: (1, 2), (1, 3), (2, 3), (1, 4), (2, 4), (3, 4)...

Permutations
Finite sets of permutations are often shown in lex order, but rev colex order has the advantage that it can be used to order an infinite number of permutations. This above all means the finitary symmetric group on $$\mathbb{N}$$, which is the union of all finite symmetric groups, and thus contains each finitary permutation of $$\mathbb{N}$$. Its n-th element (counted from 0) is found in row n of.

This makes it possible to assign a number to a permutation that is only given in cycle notation, without seeing it as a permutation of a particular number of elements. The reverse colex rank is its left inversion count interpreted as a (little-endian) factorial number.

The reverse colex order of the permutations corresponds to the colex order of these left inversion counts, as seen in the following illustrations.

Partitions
Infinite orderings of integer partitions and set partitions can be defined using CoLex ordering.

Walsh functions
The rows of binary Walsh matrices in Lex and CoLex order give symmetric matrices. For normal Walsh matrices (with 1 and −1 instead of 0 and 1) RevLex and RevCoLex would give this result.

Subsets
The following Python code shows the 16 subsets of the set {a,b,c,d} in lexicographic order. The second part shows that Lex order is the same as binary CoLex order, when the subsets themselves are reversed.

Hypercube faces


The following lists show the vertices of the s for k in {3, 2, 1}. (The tesseract is the 4-dimensional, and has 8 cubic cells, 24 square faces, 32 edges and 16 vertices.) For the cubes Lex and CoLex are the same. The binary matrix on the right has rotational symmetry. For squares and edges the two orderings are shown separately. Their binary matrices are rotations of each other.

As usual, the CoLex order is the one where the sequence for a lower dimension is the beginning of the sequence for a higher one. The binary matrices shown above can be interpreted as integer sequences:

vertices: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768... edges: 3, 5, 10, 12, 17, 34, 48, 68, 80, 136, 160, 192, 257, 514, 768, 1028, 1280, 2056, 2560, 3072, 4112, 4352, 8224, 8704, 12288, 16448, 17408, 20480, 32896, 34816, 40960, 49152... squares: 15, 51, 85, 170, 204, 240, 771, 1285, 2570, 3084, 3840, 4369, 8738, 12336, 13056, 17476, 20560, 21760, 34952, 41120, 43520, 49344, 52224, 61440... cubes: 255, 3855, 13107, 21845, 43690, 52428, 61680, 65280... tesseracts: 65535...

Petrie polygon
A hypercube of dimension n has a of size 2n, which is also the number of its. It passes the first half of them in ascending order, and the second half in descending order.

