combinat::subwords – subwords of a word

The library combinat::subwords provides functions for counting, generating, and manipulating the subwords of a word.

→ Examples

Superdomain

Dom::BaseDomain

Categories

Cat::CombinatorialClass

Axioms

Ax::systemRep

Related Domains:

combinat::words

Details:

Entries

"domtype"

The MuPAD domain used to represent subwords: DOM_LIST.

count – number of subwords of a word

combinat::subwords::count(word A)

combinat::subwords::count(word A, nonnegative integer math, <Repeat>)

Returns the number of subwords of a word.

Returns the number of subwords of length math of a word, with optional repetition of letters.

list – list of the subwords of a word

combinat::subwords::list(word A)

combinat::subwords::list(word A, nonnegative integer math, <Repeat>)

Returns the list of the subwords of a word.

Returns the list of the subwords of length math of a word, with optional repetition of letters.

generator – generator for subwords of a word

combinat::subwords::generator(word A)

combinat::subwords::generator(word A, nonnegative integer math, <Repeat>)

Returns a generator for subwords of a word.

Returns a generator for subwords of length math of a word, with optional repetition of letters.

first – first subword of a word

combinat::subwords::first(word A)

combinat::subwords::first(word A, nonnegative integer math, <Repeat>)

Returns the first subword of a word.

Returns the first subword of length math of a word, with optional repetition of letters.

last – last subword of a word

combinat::subwords::last(word A)

combinat::subwords::last(word A, nonnegative integer math, <Repeat>)

Returns the last subword of a word.

Returns the first subword of length math of a word, with optional repetition of letters.

Example 1:

There are math subwords of the word [a, c, b]:

combinat::subwords::count([a, c, b])

math

Here is the list:

combinat::subwords::list([a, b, c])

math

To compute the subwords of a given length:

combinat::subwords::count([a, c, b, b, c], 3);

combinat::subwords::list([a, c, b, b, c], 3)

math

math

Note that the word [a, c, b] is repeated twice.

When you want to run through the subwords, you can generate them one by one to save memory:

g := combinat::subwords::generator([a, c, b, b, c], 3):

g(), g();

g(), g(), g(), g(), g(), g(), g(), g(), g();

math

math

Typically, this would be used as follows:

g := combinat::subwords::generator([a, b, b, a], 2):

while (p := g()) <> FAIL do print(p): end:

[a, b]

 

[a, b]

 

[a, a]

 

[b, b]

 

[b, a]

 

[b, a]

 

The “first” and “last” subwords of length math, also called left and right factors are computed in this example:

combinat::subwords::first([a, b, b, a, d, b, a], 3);

combinat::subwords::last([a, b, b, a, d, b, a], 3);

math

math

Example 2:

To list the non-decreasing words of [a, b, d], you just have to list the subwords of [a, b, d] with repetitions:

combinat::subwords::list([a, b, d], 3, Repeat);

math

It also works for an input word with repeated letters:

combinat::subwords::list([a, b, b], 3, Repeat);

math

And also with generators:

g := combinat::subwords::generator([a, b, b], 3, Repeat):

g(), g();

g(), g(), g(), g(), g(), g(), g(), g(), g();

math

math