The Presentation class
Presentations for semigroups and monoids.
This class can be used to construction presentations for semigroups or monoids
and is intended to be used as the input to other algorithms in
libsemigroups_pybind11
. The idea is to provide a shallow wrapper around a
collection of words of type Word. We refer to
this list of words as the rules of the presentation. The Presentation
class also provides some checks that the rules really define a presentation,
(i.e. it’s consistent with its alphabet), and some related functionality is
available in the module libsemigroups_pybind11.presentation
.
Types
In what follows, we use the following pseudo-types:
Letter
forstr | int
Word
forstr | list[int]
Recall that, once a presentation has been constructed, the type of its letters and words are fixed.
Contents
Presentations for semigroups and monoids. |
|
Overloaded function. |
|
Overloaded function. |
|
Set the alphabet to be the letters in the rules. |
|
Overloaded function. |
|
Copy a |
|
Check if a letter belongs to the alphabet or not. |
|
Return the index of a letter in the alphabet. |
|
Remove the alphabet and all rules. |
|
Get a letter in the alphabet by index. |
|
Remove the letter x as a generator. |
|
Data member holding the rules of the presentation. |
|
Check if the alphabet is valid. |
|
Check if the alphabet and rules are valid. |
|
Check if every rule consists of letters belonging to the alphabet. |
|
Overloaded function. |
Full API
- class Presentation
- __init__(*args, **kwargs)
Overloaded function.
- __init__(self: Presentation, word: type) None
Default constructor.
This function default constructs an uninitialised
Presentation
instance.- Keyword Arguments:
word (type) – the type of words to use. Must be either
str
orlist[int]
.
- __init__(self: Presentation, alphabet: str | list[int]) None
Construct a presentation from an alphabet.
This function constructs a
Presentation
instance with the alphabet specified by alphabet.- Parameters:
alphabet (str | list[int]) – the alphabet of the presentation.
- Raises:
LibsemigroupsError – if there are duplicate letters in alphabet.
- add_generator(*args, **kwargs)
Overloaded function.
- add_generator(self: Presentation) Letter
Add a generator.
Add the first letter not in the alphabet as a generator, and return this letter.
- Returns:
the letter added to the alphabet.
- Return type:
- add_generator(self: Presentation, x: Letter) Presentation
Add the letter x as a generator.
- Parameters:
x (Letter) – the letter to add as a generator.
- Returns:
self.
- Return type:
- Raises:
LibsemigroupsError – if x is in
alphabet()
.
- alphabet(*args, **kwargs)
Overloaded function.
- alphabet(self: Presentation) Word
Return the alphabet of the presentation.
- Returns:
The alphabet of the presentation.
- Return type:
- Complexity:
Constant.
- alphabet(self: Presentation, n: int) Presentation
Set the alphabet by size.
Sets the alphabet to the the first \(n\) values with type Letter. For
str
-types, we assume the order of letters to be a-zA-Z0-9.- Parameters:
n (int) – the size of the alphabet.
- Returns:
self
- Return type:
- Raises:
LibsemigroupsError – if the value of n is greater than the maximum number of letters supported by Letter.
- alphabet(self: Presentation, lphbt: Word) Presentation
Set the alphabet.
Sets the alphabet to be the letters in lphbt.
- Parameters:
lphbt (Word) – the alphabet.
- Returns:
self
- Return type:
- Raises:
LibsemigroupsError – if there are duplicate letters in lphbt.
See also
:any:throw_if_bad_alphabet_or_rules
- alphabet_from_rules(self: Presentation) Presentation
Set the alphabet to be the letters in the rules.
- Returns:
self
- Return type:
- Complexity:
At most \(O(mn)\) where \(m\) is the number of rules, and \(n\) is the length of the longest rule.
See also
:any:throw_if_bad_alphabet_or_rules
- contains_empty_word(*args, **kwargs)
Overloaded function.
- contains_empty_word(self: Presentation) bool
Return whether the empty word is a valid relation word.
Returns
True
if the empty word is a valid relation word, andFalse
if the empty word is not a valid relation word.If the presentation is not allowed to contain the empty word (according to this function), the presentation may still be isomorphic to a monoid, but is not given as a quotient of a free monoid.
- Returns:
whether the presentation can contain the empty word.
- Return type:
- Complexity:
Constant.
- contains_empty_word(self: Presentation, val: bool) Presentation
Set whether whether the empty word is a valid relation word.
Specify whether the empty word should be a valid relation word (corresponding to val being
True
), or not (corresponding to val beingFalse
).If the presentation is not allowed to contain the empty word (according to the value specified here), the presentation may still be isomorphic to a monoid, but is not given as a quotient of a free monoid.
- Parameters:
val (bool) – whether the presentation can contain the empty word.
- Returns:
self
- Return type:
- Complexity:
Constant
- copy(self: Presentation) Presentation
Copy a
Presentation
object.- Returns:
A copy.
- Return type:
- in_alphabet(self: Presentation, val: Letter) bool
Check if a letter belongs to the alphabet or not.
- index(self: Presentation, val: Letter) int
Return the index of a letter in the alphabet.
After checking that val is in the the alphabet, get the index of a letter in the alphabet
- Parameters:
val (Letter) – the letter.
- Returns:
the index.
- Return type:
- Raises:
LibsemigroupsError – if val does not belong to the alphabet.
- Complexity:
Constant.
- init(self: Presentation) Presentation
Remove the alphabet and all rules.
This function clears the alphabet and all rules from the presentation, putting it back into the state it would be in if it was newly constructed.
- Returns:
self.
- Return type:
- letter(self: Presentation, i: int) Letter
Get a letter in the alphabet by index.
After checking that i is in the range \([0, n)\), where \(n\) is the length of the alphabet, this function returns the letter of the alphabet in position i.
- Parameters:
i (int) – the index.
- Returns:
the letter
- Return type:
- Raises:
LibsemigroupsError – if i is not in the range \([0, n)\).
- remove_generator(self: Presentation, x: Letter) Presentation
Remove the letter x as a generator.
- Parameters:
x (Letter) – the letter to remove as a generator.
- Returns:
self.
- Return type:
- Raises:
LibsemigroupsError – if x is not in p.alphabet().
- Complexity:
Average case: linear in the length of the alphabet, worst case: quadratic in the length of the alphabet.
- property rules: list[list[int] | str]
Data member holding the rules of the presentation.
The rules can be altered using the member functions of
list
, and the presentation can be checked for validity usingthrow_if_bad_alphabet_or_rules
.
- throw_if_alphabet_has_duplicates(self: Presentation) None
Check if the alphabet is valid.
- Raises:
LibsemigroupsError – if there are duplicate letters in the alphabet.
- Complexity:
Linear in the length of the alphabet.
- throw_if_bad_alphabet_or_rules(self: Presentation) None
Check if the alphabet and rules are valid.
- Raises:
LibsemigroupsError – if
throw_if_alphabet_has_duplicates
orthrow_if_bad_rules
does.- Complexity:
Worst case \(O(mnp)\) where \(m\) is the length of length of the word, \(n\) is the size of the alphabet and \(p\) is the number of rules.
- throw_if_bad_rules(self: Presentation) None
Check if every rule consists of letters belonging to the alphabet.
- Raises:
LibsemigroupsError – if any word contains a letter not in the alphabet.
- Complexity:
Worst case \(O(mnt)\) where \(m\) is the length of the longest word, \(n\) is the size of the alphabet and \(t\) is the number of rules.
- throw_if_letter_not_in_alphabet(*args, **kwargs)
Overloaded function.
- throw_if_letter_not_in_alphabet(self: Presentation, c: Letter) None
Check if a letter belongs to the alphabet or not.
- Parameters:
c (Letter) – the letter to check.
- Raises:
LibsemigroupsError – if c does not belong to the alphabet.
- Complexity:
Constant on average, worst case linear in the size of the alphabet.
- throw_if_letter_not_in_alphabet(self: Presentation, w: Word) None
Check if every letter in a word belongs to the alphabet or not.
- Parameters:
w (Word) – the word to check.
- Raises:
LibsemigroupsError – if any letter in w does not belong to the alphabet.