LyndonWord - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


Iterator

  

LyndonWord

  

generate Lyndon words

 

Calling Sequence

Parameters

Options

Description

Examples

References

Compatibility

Calling Sequence

LyndonWord(n, m, opts)

Parameters

n

-

nonnegint; length of string

m

-

nonnegint; size of alphabet

opts

-

(optional) equation(s) of the form option = value; specify options for the LyndonWord command

Options

• 

compile = truefalse

  

True means compile the iterator. The default is true.

• 

rank = nonnegint

  

Specify the starting rank of the iterator. The default is one. Passing a value greater than one causes the iterator to skip the lower ranks; this can be useful when parallelizing iterators. The starting rank reverts to one when the iterator is reset, reused, or copied.

• 

atmost = truefalse

  

True means words with length less than or equal to n are returned, false means the returned words have length n. When atmost is true, the rank option and the Rank and Unrank methods cannot be used. The default is true.  The `<=` symbol is a synonym for this keyword.

Description

• 

The LyndonWord command returns an iterator that generates m-ary Lyndon words in lexicographic order. The alphabet consists of the integers from 0 to m1.

• 

The n parameter is the maximum length of the Lyndon word.

• 

The m parameter is the length of the alphabet, which consists of the integers from 0 to m1.

• 

A Lyndon word is an aperiodic necklace. A necklace is an equivalence class of strings under rotation. The representative of a class is the smallest string, lexicographically, in the class.

Methods

In addition to the common iterator methods, this iterator object has the following methods. The self parameter is the iterator object.

• 

Number(self): return the number of iterations required to step through the iterator, assuming it started at rank one.

• 

Rank(self,L): return the rank of the current iteration. Optionally pass L, a list or one-dimensional rtable, and return its rank.

• 

Unrank(self,rnk): return a one-dimensional Array corresponding to the iterator output with rank rnk.

Examples

withIterator&colon;

Create an iterator that generates all Lyndon words of length 4 in a 3-character alphabet.

PLyndonWord4&comma;3&colon;

PrintP&comma;showrank&colon;

 1: 0 0 0 1
 2: 0 0 0 2
 3: 0 0 1 1
 4: 0 0 1 2
 5: 0 0 2 1
 6: 0 0 2 2
 7: 0 1 0 2
 8: 0 1 1 1
 9: 0 1 1 2
10: 0 1 2 1
11: 0 1 2 2
12: 0 2 1 1
13: 0 2 1 2
14: 0 2 2 1
15: 0 2 2 2
16: 1 1 1 2
17: 1 1 2 2
18: 1 2 2 2

Compute the number of iterations.

NumberP

18

(1)

Compute the rank of an element in the sequence.

RankP&comma;0&comma;1&comma;1&comma;2

9

(2)

Compute the Lyndon word corresponding to a given rank.

UnrankP&comma;5

0021

(3)

Clone P, adding the atmost option so that the new iterator generates all Lyndon words with length less than or equal to 4.

PatmostObjectP&comma;atmost&colon;

PrintPatmost&comma;showrank

 1: 0
 2: 0 0 0 1
 3: 0 0 0 2
 4: 0 0 1
 5: 0 0 1 1
 6: 0 0 1 2
 7: 0 0 2
 8: 0 0 2 1
 9: 0 0 2 2
10: 0 1
11: 0 1 0 2
12: 0 1 1
13: 0 1 1 1
14: 0 1 1 2
15: 0 1 2
16: 0 1 2 1
17: 0 1 2 2
18: 0 2
19: 0 2 1
20: 0 2 1 1
21: 0 2 1 2
22: 0 2 2
23: 0 2 2 1
24: 0 2 2 2
25: 1
26: 1 1 1 2
27: 1 1 2
28: 1 1 2 2
29: 1 2
30: 1 2 2
31: 1 2 2 2
32: 2

References

  

Knuth, Donald Ervin. The Art of Computer Programming, volume 4, fascicle 2; generating all tuples and permutations, sec. 7.2.1.1, generating all n-tuples, pp. 26-27.

  

ibid, Algorithm F, prime and preprime string generation, p. 27.

  

Practical Algorithms to Rank Necklaces, Lyndon Words, and de Bruijn Sequences, Joe Sawada and Aaron Williams, Journal of Discrete Algorithms, vol. 43, March 2017, pp. 95-110.

Compatibility

• 

The Iterator[LyndonWord] command was introduced in Maple 2020.

• 

For more information on Maple 2020 changes, see Updates in Maple 2020.

• 

The Iterator[LyndonWord] command was updated in Maple 2022.

• 

The n and m parameters were updated in Maple 2022.

• 

The atmost option was introduced in Maple 2022.

• 

For more information on Maple 2022 changes, see Updates in Maple 2022.

See Also

DeBruijn

Iterator

Necklace

Prenecklace