Lyndon word


In mathematics, in the areas of combinatorics and computer science, a Lyndon word is a nonempty string that is strictly smaller in lexicographic order than all of its rotations. Lyndon words are named after mathematician Roger Lyndon, who investigated them in 1954, calling them standard lexicographic sequences. Anatoly Shirshov introduced Lyndon words in 1953 calling them regular words.

Definitions

Several equivalent definitions exist.
A k-ary Lyndon word of length n > 0 is an n-character string over an alphabet of size k, and which is the unique minimum element in the lexicographical ordering in the multiset of all its rotations. Being the singularly smallest rotation implies that a Lyndon word differs from any of its non-trivial rotations, and is therefore aperiodic.
Alternately, a word w is a Lyndon word if and only if it is nonempty and lexicographically strictly smaller than any of its proper suffixes, that is w < v for all nonempty words v such that w = uv and u is nonempty.
Another characterisation is the following: A Lyndon word has the property that it is nonempty and, whenever it is split into two nonempty substrings, the left substring is always lexicographically less than the right substring. That is, if w is a Lyndon word, and w = uv is any factorization into two substrings, with u and v understood to be non-empty, then u < v. This definition implies that a string w of length ≥ 2 is a Lyndon word if and only if there exist Lyndon words u and v such that u < v and w = uv. Although there may be more than one choice of u and v with this property, there is a particular choice, called the standard factorization, in which v is as long as possible.

Enumeration

The Lyndon words over the two-symbol binary alphabet, sorted by length and then lexicographically within each length class, form an infinite sequence that begins
The first string that does not belong to this sequence, "00", is omitted because it is periodic ; the second omitted string, "10", is aperiodic but is not minimal in its permutation class as it can be cyclically permuted to the smaller string "01".
The empty string also meets the definition of a Lyndon word of length zero. The numbers of binary Lyndon words of each length, starting with length zero, form the integer sequence
Lyndon words correspond to aperiodic necklace class representatives and can thus be counted with Moreau's necklace-counting function.

Generation

provides an efficient algorithm for listing the Lyndon words of length at most n with a given alphabet size s in lexicographic order. If w is one of the words in the sequence, then the next word after w can be found by the following steps:
  1. Repeat the symbols from w to form a new word x of length exactly n, where the ith symbol of x is the same as the symbol at position of w.
  2. As long as the final symbol of x is the last symbol in the sorted ordering of the alphabet, remove it, producing a shorter word.
  3. Replace the final remaining symbol of x by its successor in the sorted ordering of the alphabet.
The worst-case time to generate the successor of a word w by this procedure is O.
However, if the words being generated are stored in an array of length n, and the construction of x from w is performed by adding symbols onto the end of w rather than by making a new copy of w, then the average time to generate the successor of w is constant. Therefore, the sequence of all Lyndon words of length at most n can be generated in time proportional to the length of the sequence. A constant fraction of the words in this sequence have length exactly n, so the same procedure can be used to efficiently generate words of length exactly n or words whose length divides n, by filtering out the generated words that do not fit these criteria.

Standard factorization

According to the Chen–Fox–Lyndon theorem, every string may be formed in a unique way by concatenating a sequence of Lyndon words, in such a way that the words in the sequence are nonincreasing lexicographically. The final Lyndon word in this sequence is the lexicographically smallest suffix of the given string. A factorization into a nonincreasing sequence of Lyndon words can be constructed in linear time. Lyndon factorizations may be used as part of a bijective variant of the Burrows–Wheeler transform for data compression, and in algorithms for digital geometry.
Such factorizations can be written as finite binary trees, with the leaves labelled by the alphabet, with each rightward branch given by the final Lyndon word in the sequence. Such trees are sometimes called standard bracketings and can be taken as elements of the free group or the free Lie algebra.
Every Lyndon word can be understood as a permutation, the suffix standard permutation, and thus provides a direct mechanism for creating a basis for Lie algebra.

Duval algorithm

developed an algorithm for finding the standard factorization that runs in linear time and constant space. It iterates over a string trying to find as long a Lyndon word as possible. When it finds one, it adds it to the result list and proceeds to search the remaining part of the string. The resulting list of strings is the standard factorization of the given string. More formal description of the algorithm follows.
Given a string S of length N, one should proceed with the following steps:
  1. Let m be the index of the symbol-candidate to be appended to the already collected symbols. Initially, m = 1.
  2. Let k be the index of the symbol we would compare others to. Initially, k = 0.
  3. While k and m are less than N, compare S to S. There are three possible outcomes:
  4. #S is equal to S: append S to the current collected symbols. Increment k and m.
  5. #S is less than S: if we append S to the current collected symbols, we'll get a Lyndon word. But we can't add it to the result list yet because it may be just a part of a larger Lyndon word. Thus, just increment m and set k to 0 so the next symbol would be compared to the first one in the string.
  6. #S is greater than S: if we append S to the current collected symbols, it will be neither a Lyndon word nor a possible beginning of one. Thus, add the first m-k collected symbols to the result list, remove them from the string, set m to 1 and k to 0 so that they point to the second and the first symbol of the string respectively.
  7. When m > N, it is essentially the same as encountering minus infinity, thus, add the first m-k collected symbols to the result list after removing them from the string, set m to 1 and k to 0, and return to the previous step.
  8. Add S to the result list.

    Connection to de Bruijn sequences

If one concatenates together, in lexicographic order, all the Lyndon words that have length dividing a given number n, the result is a de Bruijn sequence, a circular sequence of symbols such that each possible length-n sequence appears exactly once as one of its contiguous subsequences. For example, the concatenation of the binary Lyndon words whose length divides four is
This construction, together with the efficient generation of Lyndon words, provides an efficient method for constructing a particular de Bruijn sequence in linear time and logarithmic space.

Additional properties and applications

Lyndon words have an application to the description of free Lie algebras, in constructing a basis for the homogeneous part of a given degree; this was Lyndon's original motivation for introducing these words. Lyndon words may be understood as a special case of Hall sets.
For prime p, the number of irreducible monic polynomials over the field is the same as the number of Lyndon words of length p.
A theorem of Radford states that a shuffle algebra over a field of characteristic 0 can be viewed as a polynomial algebra over the Lyndon words. More precisely, let A be an alphabet, let k be a field of characteristic 0, and let R be the free noncommutative k-algebra. The words over A can then be identified with the "noncommutative monomials" in R; namely, we identify a word with the monomial xa1xa2...xan. Thus, the words over A form a k-vector space basis of R. Then, a shuffle product is defined on R; this is a k-bilinear, associative and commutative product, which is denoted by ш, and which on the words can be recursively defined by
The shuffle algebra on the alphabet A is defined to be the additive group R endowed with ш as multiplication. Radford's theorem now states that the Lyndon words are algebraically independent elements of this shuffle algebra, and generate it; thus, the shuffle algebra is isomorphic to a polynomial ring over k, with the indeterminates corresponding to the Lyndon words.