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

StringRange

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

WordRange

Class for generating words in a given range and in a particular order.

WordRange.alphabet_size(…)

Overloaded function.

WordRange.at_end(…)

Check if the range object is exhausted.

WordRange.copy(…)

Copy a WordRange object.

WordRange.count(…)

The actual size of the range.

WordRange.first(…)

Overloaded function.

WordRange.get(…)

Get the current value.

WordRange.init(…)

Initialize an existing WordRange object.

WordRange.last(…)

Overloaded function.

WordRange.max(…)

Set one past the last word in the range by length.

WordRange.min(…)

Set the first word in the range by length.

WordRange.next(…)

Advance to the next value.

WordRange.order(…)

Overloaded function.

WordRange.size_hint(…)

The possible size of the range.

WordRange.upper_bound(…)

Overloaded function.

WordRange.valid(…)

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:

alphabet_size(self: WordRange, n: int) WordRange

Overloaded function.

alphabet_size(self: WordRange) int

The current number of letters in the alphabet.

Returns the current number of letters in a WordRange object.

Returns:

The current number of letters.

Return type:

int

alphabet_size(self: WordRange, n: int) WordRange

Set the number of letters in the alphabet.

Sets the number of letters in a WordRange object to n.

Parameters:

n (int) – the number of letters.

Returns:

self.

Return type:

WordRange

at_end(self: WordRange) bool

Check if the range object is exhausted.

Returns True if a WordRange object is exhausted, and False if not.

Returns:

Whether the range object is exhausted.

Return type:

bool

copy(self: WordRange) WordRange

Copy a WordRange object.

Returns:

A copy.

Return type:

WordRange

count(self: WordRange) int

The actual size of the range.

Returns the number of words in a WordRange object. If WordRange.order() is Order.shortlex , then WordRange.size_hint() is used. If WordRange.order() is not Order.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:

int

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 WordRange object.

Returns:

The first word in the range.

Return type:

list[int]

See also

WordRange.min

first(self: WordRange, frst: list[int]) WordRange

Set the first word in the range.

Sets the first word in a WordRange object to be frst. This function performs no checks on its arguments. If frst contains letters greater than WordRange.alphabet_size(), then the WordRange object will be empty. Similarly, if WordRange.first() is greater than WordRange.last() with respect to WordRange.order(), then the object will be empty.

Parameters:

frst (list[int]) – the first word.

Returns:

self.

Return type:

WordRange

See also

WordRange.min

get(self: WordRange) list[int]

Get the current value.

Returns the current word in a WordRange object.

Returns:

The current word.

Return type:

list[int]

init(self: WordRange) WordRange

Initialize an existing WordRange object.

This function puts a WordRange object back into the same state as if it had been newly default constructed, and returns that object.

Returns:

self.

Return type:

WordRange

last(self: WordRange, lst: list[int]) WordRange

Overloaded function.

last(self: WordRange) list[int]

Returns the one past the last word in a WordRange object.

Returns:

One past the last word.

Return type:

list[int]

See also

WordRange.max

last(self: WordRange, lst: list[int]) WordRange

Set one past the last word in the range.

Sets one past the last word in a WordRange object to be lst. This function performs no checks on its arguments. If lst contains letters greater than WordRange.alphabet_size(), then the WordRange object will be empty.

Parameters:

lst (list[int]) – one past the last word.

Returns:

self.

Return type:

WordRange

See also

WordRange.max

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 WordRange object to be words.pow(0_w, val) (the word consisting of val letters equal to 0 ).

Parameters:

val (int) – the exponent.

Returns:

self.

Return type:

WordRange

min(self: WordRange, val: int) WordRange

Set the first word in the range by length.

Sets the first word in a WordRange object to be pow(0_w, val) (the word consisting of val letters equal to 0 ).

Parameters:

val (int) – the exponent.

Returns:

self.

Return type:

WordRange

next(self: WordRange) None

Advance to the next value.

Advances a WordRange object to the next value (if any).

See also

WordRange.at_end

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 WordRange object.

Returns:

The current order.

Return type:

Order

order(self: WordRange, val: Order) WordRange

Set the order of the words in the range.

Sets the order of the words in a WordRange object to val.

Parameters:

val (Order) – the order.

Returns:

self.

Return type:

WordRange

Raises:

LibsemigroupsError – if val is not Order.shortlex or Order.lex.

size_hint(self: WordRange) int

The possible size of the range.

Returns the number of words in a WordRange object if WordRange.order() is Order.shortlex. If WordRange.order() is not Order.shortlex, then the return value of this function is meaningless.

Returns:

A value of type int.

Return type:

int

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 WordRange object. This setting is only used if WordRange.order() is Order.lex.

Returns:

A value of type int.

Return type:

int

upper_bound(self: WordRange, n: int) WordRange

Set an upper bound for the length of a word in the range.

Sets an upper bound for the length of a word in a WordRange object. This setting is only used if WordRange.order() is Order.lex.

Parameters:

n (int) – the upper bound.

Returns:

self.

Return type:

WordRange

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 by WordRange.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 True if none of the above settings have been changed since the last time WordRange.next() or WordRange.get() is called, and False otherwise.

Returns:

Whether or not the settings have been changed.

Return type:

bool