Knuth-Bendix¶
On this page we describe the functionality relating to the Knuth-Bendix
algorithm for semigroups and monoids that is available in
libsemigroups_pybind11. This page contains a details of the methods
of the class KnuthBendix. This class is used to represent a
string rewriting system defining a finitely presented
monoid or semigroup.
>>> from libsemigroups_pybind11 import KnuthBendix
>>> kb = KnuthBendix()
>>> kb.set_alphabet("abc")
>>> kb.add_rule("aaaa", "a")
>>> kb.add_rule("bbbb", "b")
>>> kb.add_rule("cccc", "c")
>>> kb.add_rule("abab", "aaa")
>>> kb.add_rule("bcbc", "bbb")
>>> not kb.confluent()
True
>>> kb.run()
>>> kb.number_of_active_rules()
31
>>> kb.confluent()
True
Default constructor. |
|
Returns a copy of the active rules of the KnuthBendix instance. |
|
Overloaded function. |
|
Overloaded function. |
|
Overloaded function. |
|
Convert a single letter |
|
Set the interval at which confluence is checked. |
|
Check if the KnuthBendix instance is confluent. |
|
Returns whether or not the empty string belongs to the finitely presented semigroup represented by this. |
|
Check if the runner is dead. |
|
Overloaded function. |
|
Check if the main algorithm, implemented in this class, has been run to completion or not. |
|
Returns a |
|
Returns the associated Gilman digraph (or automata). |
|
Returns |
|
Returns the identity of this, or raises an exception if there isn't one. |
|
Returns the inverses of this, or raises an exception if there aren't any. |
|
Return |
|
Returns |
|
Stop running the main algorithm(s) (thread-safe). |
|
Run the Knuth-Bendix algorithm by overlap length. |
|
Set the maximum length of overlaps to be considered. |
|
Set the maximum number of rules. |
|
Overloaded function. |
|
Returns an iterator to the normal forms with length in the given range. |
|
Returns an iterator to the normal forms of the congruence using the specified alphabet, and with length in the given range. |
|
Returns the current number of active rules in the KnuthBendix instance. |
|
Returns the number of normal forms with length in a given range. |
|
Returns the number of rules of the finitely presented semigroup. |
|
Values for specifying how to measure the length of an overlap. |
|
Set the overlap policy. |
|
Check if it is time to report. |
|
Set the minimum elapsed time between reports. |
|
Report why we stopped. |
|
Returns an iterator to the generating pairs of the congruence. |
|
Check if currently running. |
|
Run the algorithm until it finishes. |
|
Run for a specified amount of time. |
|
Run until a nullary predicate returns |
|
Overloaded function. |
|
Overloaded function. |
|
Set the inverses of letters in alphabet(). |
|
Returns the size of the finitely presented semigroup. |
|
Check if |
|
Check if the main algorithm was, or should be, stopped by the nullary predicate passed as first argument to |
|
Convert a string to a list of |
|
Check if the main algorithm has or should timed out. |
|
Returns a string containing GAP commands for defining a finitely presented semigroup equal to that represented by this. |
|
Convert an |
|
Overloaded function. |
|
Overloaded function. |
|
Convert a list of |
- class KnuthBendix(self: _libsemigroups_pybind11.KnuthBendix)¶
Default constructor.
- active_rules(self: _libsemigroups_pybind11.KnuthBendix) List[Tuple[str, str]]¶
Returns a copy of the active rules of the KnuthBendix instance.
- Parameters
None
- Returns
A copy of the currently active rules.
- add_rule(*args, **kwargs)¶
Overloaded function.
add_rule(self: _libsemigroups_pybind11.KnuthBendix, u: str, v: str) -> None
Add a rule.
- Parameters
u (str) - the left-hand side of the rule being added.
v (str) - the right-hand side of the rule being added.
- Returns
None
add_rule(self: _libsemigroups_pybind11.KnuthBendix, u: List[int], v: List[int]) -> None
Add a rule.
- Parameters
u (List[int]) - the left-hand side of the rule.
v (List[int]) - the right-hand side of the rule.
- Returns
None
add_rule(self: _libsemigroups_pybind11.KnuthBendix, rel: Tuple[str, str]) -> None
Add a rule.
- Parameters
rel (Tuple[str, str]) - the rule being added.
- Returns
None
- add_rules(*args, **kwargs)¶
Overloaded function.
add_rules(self: _libsemigroups_pybind11.KnuthBendix, rels: List[Tuple[str, str]]) -> None
Add the rules in a list.
- Parameters
rels (List[Tuple[str, str]]) - list of rules to add.
- Returns
None
add_rules(self: _libsemigroups_pybind11.KnuthBendix, rels: libsemigroups::FroidurePinBase) -> None
Add the rules in a
FroidurePininstance.- Parameters
rels (FroidurePin) - the instance.
- Returns
None
- alphabet(*args, **kwargs)¶
Overloaded function.
alphabet(self: _libsemigroups_pybind11.KnuthBendix) -> str
Returns the alphabet.
- Parameters
None
- Returns
A string.
alphabet(self: _libsemigroups_pybind11.KnuthBendix, i: int) -> str
Returns the i-th letter of the alphabet of the finitely presented semigroup represented by this.
- Parameters
i (int) - the index of the letter.
- Returns
A string.
- char_to_uint(self: _libsemigroups_pybind11.KnuthBendix, a: str) int¶
Convert a single letter
stringto aintrepresenting the same generator.- Parameters
a (str) -- the string to convert.
- Returns
an
int.
- check_confluence_interval(self: _libsemigroups_pybind11.KnuthBendix, val: int) _libsemigroups_pybind11.KnuthBendix¶
Set the interval at which confluence is checked.
- Parameters
val (int) -- the new value of the interval.
- Returns
self.
- confluent(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Check if the KnuthBendix instance is confluent.
- Parameters
None
- Returns
Trueif the KnuthBendix instance is confluent andFalseif it is not.
- contains_empty_string(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Returns whether or not the empty string belongs to the finitely presented semigroup represented by this.
- Returns
A
bool.
- dead(self: libsemigroups::Runner) bool¶
Check if the runner is dead.
- Parameters
None
- Returns
A
bool.
- equal_to(*args, **kwargs)¶
Overloaded function.
equal_to(self: _libsemigroups_pybind11.KnuthBendix, u: str, v: str) -> bool
Check if two words represent the same element.
- Parameters
u (str) - first word for comparison.
v (str) - second word for comparison.
- Returns
Trueif the stringsuandvrepresent the same element of the finitely presented semigroup, andFalseotherwise.
equal_to(self: _libsemigroups_pybind11.KnuthBendix, u: List[int], v: List[int]) -> bool
Check if two words represent the same element.
- Parameters
u (List[int]) - first word for comparison.
v (List[int]) - second word for comparison.
- Returns
Trueif the wordsuandvrepresent the same element of the finitely presented semigroup, andFalseotherwise.
- finished(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Check if the main algorithm, implemented in this class, has been run to completion or not.
- Parameters
None
- Returns
A
bool.
- froidure_pin(self: _libsemigroups_pybind11.KnuthBendix) libsemigroups::FroidurePinBase¶
Returns a
FroidurePininstance isomorphic to the finitely presented semigroup defined by this.- Parameters
None
- Returns
A
FroidurePin.
- gilman_digraph(self: _libsemigroups_pybind11.KnuthBendix) _libsemigroups_pybind11.ActionDigraph¶
Returns the associated Gilman digraph (or automata).
- Parameters
None
- Returns
A copy of an
ActionDigraph.
- has_froidure_pin(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Returns
Trueif aFroidurePininstance isomorphic to the finitely presented semigroup defined by this has already been computed, andFalseif not.- Parameters
None
- Returns
A
bool.
- identity(self: _libsemigroups_pybind11.KnuthBendix) str¶
Returns the identity of this, or raises an exception if there isn't one.
- Parameters
None
- Returns
A string of length 1.
- inverses(self: _libsemigroups_pybind11.KnuthBendix) str¶
Returns the inverses of this, or raises an exception if there aren't any.
- Parameters
None
- Returns
A
str.
- is_obviously_finite(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Return
Trueif the finitely presented semigroup represented by this is obviously finite, andFalseif it is not obviously finite.- Returns
A
bool.
- is_obviously_infinite(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Returns
Trueif the finitely presented semigroup represented by this is obviously infinite, andFalseif it is not obviously infinite.- Returns
A bool.
- kill(self: libsemigroups::Runner) None¶
Stop running the main algorithm(s) (thread-safe).
- Parameters
None
- Returns
(None).
- knuth_bendix_by_overlap_length(self: _libsemigroups_pybind11.KnuthBendix) None¶
Run the Knuth-Bendix algorithm by overlap length.
- Parameters
None
- Returns
None
- max_overlap(self: _libsemigroups_pybind11.KnuthBendix, val: int) _libsemigroups_pybind11.KnuthBendix¶
Set the maximum length of overlaps to be considered.
- Parameters
val (int) -- the new value of the maximum overlap length.
- Returns
self.
- max_rules(self: _libsemigroups_pybind11.KnuthBendix, val: int) _libsemigroups_pybind11.KnuthBendix¶
Set the maximum number of rules.
- Parameters
val (int) -- the maximum number of rules.
- Returns
self.
- normal_form(*args, **kwargs)¶
Overloaded function.
normal_form(self: _libsemigroups_pybind11.KnuthBendix, w: str) -> str
Returns a normal form for a string.
- Parameters
w (str) - the word whose normal form we want to find.
- Returns
A
str.
normal_form(self: _libsemigroups_pybind11.KnuthBendix, w: List[int]) -> List[int]
Returns a normal form for a word.
- Parameters
w (List[int]) - the word whose normal form we want to find.
- Returns
The normal form of the parameter
w.
- normal_forms(self: _libsemigroups_pybind11.KnuthBendix, mn: int, mx: int) Iterator¶
Returns an iterator to the normal forms with length in the given range.
- normal_forms_alphabet(self: _libsemigroups_pybind11.KnuthBendix, lphbt: str, mn: int, mx: int) Iterator¶
Returns an iterator to the normal forms of the congruence using the specified alphabet, and with length in the given range.
- number_of_active_rules(self: _libsemigroups_pybind11.KnuthBendix) int¶
Returns the current number of active rules in the KnuthBendix instance.
- Parameters
None
- Returns
An
int.
- number_of_normal_forms(self: _libsemigroups_pybind11.KnuthBendix, min: int, max: int) int¶
Returns the number of normal forms with length in a given range.
- number_of_rules(self: _libsemigroups_pybind11.KnuthBendix) int¶
Returns the number of rules of the finitely presented semigroup.
- Parameters
None
- Returns
A
int.
- class overlap(self: _libsemigroups_pybind11.KnuthBendix.overlap, value: int)¶
Values for specifying how to measure the length of an overlap.
The values in this enum determine how a
KnuthBendixinstance measures the length \(d(AB, BC)\) of the overlap of two words \(AB\) and \(BC\).See also
overlap_policy()Members:
- ABC :
\(d(AB, BC) = |A| + |B| + |C|\)
- AB_BC :
\(d(AB, BC) = |AB| + |BC|\)
- MAX_AB_BC :
\(d(AB, BC) = max(|AB|, |BC|)\)
- property name¶
- overlap_policy(self: _libsemigroups_pybind11.KnuthBendix, val: _libsemigroups_pybind11.KnuthBendix.overlap) _libsemigroups_pybind11.KnuthBendix¶
Set the overlap policy.
- Parameters
val (int) -- the maximum number of rules.
- Returns
self.
- report(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Check if it is time to report.
- Parameters
None
- Returns
A
bool.
- report_every(self: _libsemigroups_pybind11.KnuthBendix, t: datetime.timedelta) None¶
Set the minimum elapsed time between reports.
- Parameters
t (datetime.timedelta) -- the amount of time between reports.
- Returns
(None)
- report_why_we_stopped(self: _libsemigroups_pybind11.KnuthBendix) None¶
Report why we stopped.
- Parameters
None
- Returns
(None)
- rewrite(self: _libsemigroups_pybind11.KnuthBendix, arg0: str) str¶
Rewrite a word.
Rewrites a copy of the string
wrewritten according to the current rules in theKnuthBendixinstance.- Parameters
w (str) -- the word to rewrite.
- Returns
A copy of the argument
wafter it has been rewritten.
- rules(self: _libsemigroups_pybind11.KnuthBendix) Iterator¶
Returns an iterator to the generating pairs of the congruence.
- run(self: _libsemigroups_pybind11.KnuthBendix) None¶
Run the algorithm until it finishes. :Parameters: None
- Returns
(None)
- run_for(self: _libsemigroups_pybind11.KnuthBendix, t: datetime.timedelta) None¶
Run for a specified amount of time.
- Parameters
t (datetime.timedelta) -- the time to run for.
- Returns
(None)
>>> from datetime import timedelta >>> from libsemigroups_pybind11 import ToddCoxeter, congruence_kind >>> tc = ToddCoxeter(congruence_kind.twosided) >>> tc.set_number_of_generators(1) >>> tc.add_pair([0] * 1000, [0] * 999) >>> tc.run_for(timedelta(microseconds=10))
- run_until(self: _libsemigroups_pybind11.KnuthBendix, func: Callable[[], bool]) None¶
Run until a nullary predicate returns
Trueorfinished().- Parameters
func (Callable[], bool) -- a function.
- Returns
(None)
- running(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Check if currently running.
- Parameters
(None)
- Returns
Trueifrun()is in the process of running andFalseif it is not.
See also
- set_alphabet(*args, **kwargs)¶
Overloaded function.
set_alphabet(self: _libsemigroups_pybind11.KnuthBendix, a: str) -> None
Set the alphabet of the finitely presented semigroup.
- Parameters
a (str) - the alphabet.
- Returns
None
set_alphabet(self: _libsemigroups_pybind11.KnuthBendix, n: int) -> None
Set the size of the alphabet.
- Parameters
n (int) - the number of letters.
- Returns
None
- set_identity(*args, **kwargs)¶
Overloaded function.
set_identity(self: _libsemigroups_pybind11.KnuthBendix, id: int) -> None
Set a character in alphabet() to be the identity using its index.
- Parameters
id (int) - the index of the character to be the identity.
- Returns
None
set_identity(self: _libsemigroups_pybind11.KnuthBendix, id: str) -> None
Set a character in alphabet() to be the identity.
- Parameters
id (str) - a string containing the character to be the identity.
- Returns
None
- set_inverses(self: _libsemigroups_pybind11.KnuthBendix, a: str) None¶
Set the inverses of letters in alphabet().
- Parameters
a (str) -- a string containing the inverses of the generators.
- Returns
None
- size(self: _libsemigroups_pybind11.KnuthBendix) int¶
Returns the size of the finitely presented semigroup.
- Parameters
None
- Returns
A
intorPOSITIVE_INFINITY.
- started(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Check if
run()has been called at least once before.Returns
Trueifrun()has started to run (it can be running or not).- Parameters
(None)
- Returns
A
bool.
See also
- stopped(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Check if the runner is stopped.
This function can be used to check whether or not
run()has been stopped for whatever reason. In other words, it checks iftimed_out(),finished(), ordead().- Parameters
None
- Returns
A
bool.
- stopped_by_predicate(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Check if the main algorithm was, or should be, stopped by the nullary predicate passed as first argument to
run_until().- Parameters
None
- Returns
A
bool.
- string_to_word(self: _libsemigroups_pybind11.KnuthBendix, w: str) List[int]¶
Convert a string to a list of
intrepresenting the same element of the finitely presented semigroup represented by this.- Parameters
w (str) -- the string to convert.
- Returns
a
List[int].
- timed_out(self: _libsemigroups_pybind11.KnuthBendix) bool¶
Check if the main algorithm has or should timed out.
- Parameters
None
- Returns
A
bool.
- to_gap_string(self: _libsemigroups_pybind11.KnuthBendix) str¶
Returns a string containing GAP commands for defining a finitely presented semigroup equal to that represented by this.
- Parameters
None
- Returns
A string.
- uint_to_char(self: _libsemigroups_pybind11.KnuthBendix, a: int) str¶
Convert an
intto acharrepresenting the same generator of the finitely presented semigroup represented by this.- Parameters
a (int) -- the letter to convert.
- Returns
A
str.
- validate_letter(*args, **kwargs)¶
Overloaded function.
validate_letter(self: _libsemigroups_pybind11.KnuthBendix, c: str) -> None
Validates a letter.
- Parameters
c (str) - the letter to validate.
- Returns
None
validate_letter(self: _libsemigroups_pybind11.KnuthBendix, c: int) -> None
Validates a letter.
- Parameters
c (int) - the letter to validate.
- Returns
None
- validate_word(*args, **kwargs)¶
Overloaded function.
validate_word(self: _libsemigroups_pybind11.KnuthBendix, w: str) -> None
Validates a word.
- Parameters
w (str) - the word to validate.
- Returns
None
validate_word(self: _libsemigroups_pybind11.KnuthBendix, w: List[int]) -> None
Validates a word.
This function checks that the word
wis defined over the same alphabet as an instance ofKnuthBendix.- Parameters
w (List[int]) - the word to validate.
- Returns
None
- word_to_string(self: _libsemigroups_pybind11.KnuthBendix, w: List[int]) str¶
Convert a list of
intto a string representing the same element of the finitely presented semigroup represented by this.- Parameters
w (List[int]) -- the list to convert.
- Returns
A string.