The StringRange class

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

The StringRange class implements a range object for strings and produces the same output as WordRange() | ToString("ab") , but is more convenient in some cases.

The order and range of the words in a StringRange instance can be set using the member functions:

See also

WordRange

Example

>>> from libsemigroups_pybind11 import StringRange, Order
>>> strings = StringRange();
>>> strings.order(Order.shortlex) \
...        .alphabet("ba") \
...        .min(1) \
...        .max(5)
<StringRange of length 30 in shortlex order>
>>> strings.order()
<Order.shortlex: 1>

>>> from libsemigroups_pybind11 import ToWord
>>> strings.alphabet("a").min(0).max(10)
<StringRange of length 10 in shortlex order>

>>> wrds = strings | ToWord("a")
>>> list(wrds)
[[], [0], [0, 0], [0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]

Contents

StringRange

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

StringRange.alphabet(…)

Overloaded function.

StringRange.at_end(…)

Check if the range object is exhausted.

StringRange.copy(…)

Copy a StringRange object.

StringRange.count(…)

The actual size of the range.

StringRange.first(…)

Overloaded function.

StringRange.get(…)

Get the current value.

StringRange.init(…)

Initialize an existing StringRange object.

StringRange.last(…)

Overloaded function.

StringRange.max(…)

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

StringRange.min(…)

Set the first string in the range by length.

StringRange.next(…)

Advance to the next value.

StringRange.order(…)

Overloaded function.

StringRange.size_hint(…)

The possible size of the range.

StringRange.upper_bound(…)

Overloaded function.

Full API

class StringRange
__init__(self: StringRange) None

Default constructor. Constructs an empty range with:

alphabet(*args, **kwargs)

Overloaded function.

alphabet(self: StringRange) str

The current alphabet.

Returns the current alphabet in a StringRange object.

Returns:

The current alphabet.

Return type:

str

alphabet(self: StringRange, x: str) StringRange

Set the alphabet.

Sets the alphabet in a StringRange object.

Parameters:

x (str) – the alphabet.

Returns:

self.

Return type:

StringRange

Raises:

LibsemigroupsError – if x contains repeated letters.

at_end(self: StringRange) bool

Check if the range object is exhausted.

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

Returns:

Whether the object is exhausted.

Return type:

bool

copy(self: StringRange) StringRange

Copy a StringRange object.

Returns:

A copy.

Return type:

StringRange

count(self: StringRange) int

The actual size of the range.

Returns the number of strings in the range object. If StringRange.order() is Order.shortlex , then StringRange.size_hint() is used. If 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(*args, **kwargs)

Overloaded function.

first(self: StringRange) str

The current first string in the range.

Returns the first string in a StringRange object.

Returns:

The first string.

Return type:

str

See also

min

first(self: StringRange, frst: str) StringRange

Set the first string in the range.

Sets the first string in a StringRange object to be frst.

Parameters:

frst (str) – the first string.

Returns:

self.

Return type:

StringRange

See also

min

get(self: StringRange) str

Get the current value.

Returns the current string in a StringRange object.

Returns:

The current value.

Return type:

str

init(self: StringRange) StringRange

Initialize an existing StringRange object.

This function puts a StringRange object back into the same state as if it had been newly default constructed.

Returns:

self.

Return type:

StringRange

last(*args, **kwargs)

Overloaded function.

last(self: StringRange) str

The current one past the last string in the range.

Returns one past the last string in a StringRange object.

Returns:

One past the last string.

Return type:

str

See also

max

last(self: StringRange, lst: str) StringRange

Set one past the last string in the range.

Sets one past the last string in a StringRange object to be lst.

Parameters:

lst (str) – the first string.

Returns:

self.

Return type:

StringRange

Raises:

LibsemigroupsError – if lst contains letters not belonging to StringRange.alphabet().

See also

max

max(self: StringRange, val: int) StringRange

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

Sets one past the last string in a StringRange object to be \(\alpha^n\) where \(\alpha\) is the first letter of StringRange.alphabet (or "a" if the alphabet is empty) and \(n\) corresponds to val.

Parameters:

val (int) – the exponent.

Returns:

self.

Return type:

StringRange

min(self: StringRange, val: int) StringRange

Set the first string in the range by length.

Sets the first string in a StringRange object to be \(\alpha^n\) where \(\alpha\) is the first letter of StringRange.alphabet (or "a" if the alphabet is empty) and \(n\) corresponds to val.

Parameters:

val (int) – the exponent.

Returns:

self.

Return type:

StringRange

next(self: StringRange) None

Advance to the next value.

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

See also

at_end

order(*args, **kwargs)

Overloaded function.

order(self: StringRange) Order

The current order of the strings in the range.

Returns the current order of the strings in a StringRange object.

Returns:

The current order.

Return type:

Order

order(self: StringRange, val: Order) StringRange

Set the order of the strings in the range.

Sets the order of the strings in a StringRange object to val.

Parameters:

val (Order) – the order.

Returns:

self.

Return type:

StringRange

Raises:

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

size_hint(self: StringRange) int

The possible size of the range.

Returns the number of words in a StringRange object if StringRange.order() is Order.shortlex. If 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: StringRange, n: int) StringRange

Overloaded function.

upper_bound(self: StringRange) int

The current upper bound on the length of a string in the range.

Returns the current upper bound on the length of a string in a StringRange object. This setting is only used if StringRange.order() is Order.lex.

Returns:

A value of type int.

Return type:

int

upper_bound(self: StringRange, n: int) StringRange

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

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

Parameters:

n (int) – the upper bound.

Returns:

self.

Return type:

StringRange