The WordRange class
Class for generating words in a given range and in a particular order.
The WordRange class is a class for generating words (i.e. lists of int
values) in a given range and in a particular order.
The order and range of the words in a WordRange instance can be set using
the member functions:
See also
Example
>>> from libsemigroups_pybind11 import WordRange, Order
>>> words = WordRange();
>>> words.order(Order.shortlex) \
... .alphabet_size(2) \
... .min(1) \
... .max(5)
<WordRange of length 30 with letters in [0, 2) in shortlex order>
>>> words.order()
<Order.shortlex: 1>
>>> from libsemigroups_pybind11 import ToString
>>> words.alphabet_size(1).min(0).max(10)
<WordRange of length 10 with letters in [0, 1) in shortlex order>
>>> strings = words | ToString("a")
>>> list(strings)
['', 'a', 'aa', 'aaa', 'aaaa', 'aaaaa', 'aaaaaa', 'aaaaaaa', 'aaaaaaaa', 'aaaaaaaaa']
Contents
Class for generating words in a given range and in a particular order. |
|
Overloaded function. |
|
Check if the range object is exhausted. |
|
Copy a |
|
The actual size of the range. |
|
Overloaded function. |
|
Get the current value. |
|
Initialize an existing |
|
Overloaded function. |
|
Set one past the last word in the range by length. |
|
Set the first word in the range by length. |
|
Advance to the next value. |
|
Overloaded function. |
|
The possible size of the range. |
|
Overloaded function. |
|
Returns whether or not the settings have been changed since the last time either next or get has been called. |
Full API
- class WordRange
- __init__(self: WordRange) None
Default constructor.
Constructs an empty range with:
WordRange.min()equal to0;WordRange.max()equal to0;WordRange.order()equal toOrder.shortlex;WordRange.first()equal to the empty word;WordRange.last()equal to the empty word;WordRange.upper_bound()equal to0;WordRange.alphabet_size()equal to0.
- alphabet_size(self: WordRange, n: int) WordRange
Overloaded function.
- at_end(self: WordRange) bool
Check if the range object is exhausted.
Returns
Trueif aWordRangeobject is exhausted, andFalseif not.- Returns:
Whether the range object is exhausted.
- Return type:
- count(self: WordRange) int
The actual size of the range.
Returns the number of words in a
WordRangeobject. IfWordRange.order()isOrder.shortlex, thenWordRange.size_hint()is used. IfWordRange.order()is notOrder.shortlex, then a copy of the range may have to be looped over in order to find the return value of this function.- Returns:
The size of the range.
- Return type:
- first(self: WordRange, frst: list[int]) WordRange
Overloaded function.
- first(self: WordRange) list[int]
The current first word in the range.
Returns the first word in a
WordRangeobject.See also
- first(self: WordRange, frst: list[int]) WordRange
Set the first word in the range.
Sets the first word in a
WordRangeobject to be frst. This function performs no checks on its arguments. If frst contains letters greater thanWordRange.alphabet_size(), then theWordRangeobject will be empty. Similarly, ifWordRange.first()is greater thanWordRange.last()with respect toWordRange.order(), then the object will be empty.See also
- get(self: WordRange) list[int]
Get the current value.
Returns the current word in a
WordRangeobject.
- init(self: WordRange) WordRange
Initialize an existing
WordRangeobject.This function puts a
WordRangeobject back into the same state as if it had been newly default constructed, and returns that object.- Returns:
self.
- Return type:
- last(self: WordRange, lst: list[int]) WordRange
Overloaded function.
- last(self: WordRange, lst: list[int]) WordRange
Set one past the last word in the range.
Sets one past the last word in a
WordRangeobject to belst. This function performs no checks on its arguments. Iflstcontains letters greater thanWordRange.alphabet_size(), then theWordRangeobject will be empty.See also
- max(self: WordRange, val: int) WordRange
Set one past the last word in the range by length.
Sets one past the last word in a
WordRangeobject to bewords.pow(0_w, val)(the word consisting of val letters equal to0).
- min(self: WordRange, val: int) WordRange
Set the first word in the range by length.
Sets the first word in a
WordRangeobject to bepow(0_w, val)(the word consisting of val letters equal to0).
- next(self: WordRange) None
Advance to the next value.
Advances a
WordRangeobject to the next value (if any).See also
- order(*args, **kwargs)
Overloaded function.
- order(self: WordRange) Order
The current order of the words in the range.
Returns the current order of the words in a
WordRangeobject.- Returns:
The current order.
- Return type:
- order(self: WordRange, val: Order) WordRange
Set the order of the words in the range.
Sets the order of the words in a
WordRangeobject to val.- Parameters:
val (Order) – the order.
- Returns:
self.
- Return type:
- Raises:
LibsemigroupsError – if val is not
Order.shortlexorOrder.lex.
- size_hint(self: WordRange) int
The possible size of the range.
Returns the number of words in a
WordRangeobject ifWordRange.order()isOrder.shortlex. IfWordRange.order()is notOrder.shortlex, then the return value of this function is meaningless.- Returns:
A value of type
int.- Return type:
- upper_bound(self: WordRange, n: int) WordRange
Overloaded function.
- upper_bound(self: WordRange) int
The current upper bound on the length of a word in the range.
Returns the current upper bound on the length of a word in a
WordRangeobject. This setting is only used ifWordRange.order()isOrder.lex.
- valid(self: WordRange) bool
Returns whether or not the settings have been changed since the last time either next or get has been called.
Other than by calling
WordRange.next(), the value returned byWordRange.get()may be altered by a call to one of the following:order(Order)alphabet_size(int)min(int)max(int)first(list[int])last(list[int])upper_bound(int)
This function returns
Trueif none of the above settings have been changed since the last timeWordRange.next()orWordRange.get()is called, andFalseotherwise.- Returns:
Whether or not the settings have been changed.
- Return type: