combinat::subwords – subwords of a word
The library combinat::subwords provides functions for counting, generating, and manipulating the subwords of a word.
Superdomain
Categories
Axioms
Related Domains:
Details:
A subword of a word is a word obtained by deleting the letters at some of the positions in (see also combinat::words). A subword is generated as many times as it appears in the word.
Sometimes, a letter in the word can be repeated several times in the subword, even it only appears once in . This is done with the option Repeat.
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 , <Repeat>)
Returns the number of subwords of a word.
Returns the number of subwords of length 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 , <Repeat>)
Returns the list of the subwords of a word.
Returns the list of the subwords of length 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 , <Repeat>)
Returns a generator for subwords of a word.
Returns a generator for subwords of length 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 , <Repeat>)
Returns the first subword of a word.
Returns the first subword of length 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 , <Repeat>)
Returns the last subword of a word.
Returns the first subword of length of a word, with optional repetition of letters.
There are subwords of the word [a, c, b]:
combinat::subwords::count([a, c, b])
Here is the list:
combinat::subwords::list([a, b, c])
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)
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();
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 , 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);
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);
It also works for an input word with repeated letters:
combinat::subwords::list([a, b, b], 3, Repeat);
And also with generators:
g := combinat::subwords::generator([a, b, b], 3, Repeat):
g(), g();
g(), g(), g(), g(), g(), g(), g(), g(), g();