Stephen¶
On this page we describe the functionality in libsemigroups_pybind11
relating to Stephen’s procedure for finitely presented semigroups. This class
implements Stephen’s procedure for (possibly) constructing the word graph
(ActionDigraph
) corresponding to the left factors of a word in a
finitely presented semigroup. The algorithm implemented in this class is
closely related to the Todd-Coxeter algorithm (as implemented in
ToddCoxeter
) and originates in Applications of automata theory to
presentations of monoids and inverse monoids by J. B. Stephen.
>>> from libsemigroups_pybind11 import Presentation, presentation, Stephen, action_digraph_helper, UNDEFINED
>>> p = Presentation([0, 1])
>>> presentation.add_rule_and_check(p, [0, 0, 0], [0])
>>> presentation.add_rule_and_check(p, [1, 1, 1], [1])
>>> presentation.add_rule_and_check(p, [0, 1, 0, 1], [0, 0])
>>> s = Stephen(p)
>>> s.set_word([1, 1, 0, 1]).run()
>>> s.word_graph().number_of_nodes()
7
>>> s.word_graph() == action_digraph_helper.make(
... 7,
... [
... [UNDEFINED, 1],
... [UNDEFINED, 2],
... [3, 1],
... [4, 5],
... [3, 6],
... [6, 3],
... [5, 4],
... ])
True
Methods¶
Overloaded function. |
|
Overloaded function. |
|
The accept state of the word graph. |
|
The input presentation. |
|
Set the word. |
|
The word. |
|
The word graph. |
Methods inherited from Runner¶
Check if the runner is dead. |
|
Check if the main algorithm, implemented in this class, has been run to completion or not. |
|
Stop running the main algorithm(s) (thread-safe). |
|
Check if it is time to report. |
|
Set the minimum elapsed time between reports. |
|
Report why we stopped. |
|
Run the algorithm until it finishes. |
|
Run for a specified amount of time. |
|
Run until a nullary predicate returns |
|
Check if currently running. |
|
Check if |
|
Check if the runner is stopped. |
|
Check if the main algorithm was, or should be, stopped by the nullary predicate passed as first argument to |
|
Check if the main algorithm has or should timed out. |
- class Stephen(*args, **kwargs)¶
Overloaded function.
__init__(self: _libsemigroups_pybind11.Stephen, p: _libsemigroups_pybind11.PresentationWords) -> None
Construct from a presentation with relation words given by lists of integers.
- Parameters
p (Presentation) - the presentation.
- Raises
RunTimeError
ifp.validate()
raises.- Raises
RunTimeError
ifp.alphabet().size()
is0
.
__init__(self: _libsemigroups_pybind11.Stephen, p: _libsemigroups_pybind11.PresentationStrings) -> None
Construct from a presentation with relation words given by strings.
- Parameters
p (Presentation) - the presentation.
- Raises
RunTimeError
ifp.validate()
raises.- Raises
RunTimeError
ifp.alphabet().size()
is0
.
__init__(self: _libsemigroups_pybind11.Stephen, s: _libsemigroups_pybind11.Stephen) -> None
Copy a
Stephen
instance.
- accept_state(self: _libsemigroups_pybind11.Stephen) int ¶
The accept state of the word graph.
This function triggers the algorithm implemented in this class (if it hasn't been triggered already), and then returns the accept state of the produced word graph.
- Returns
the accept state
- Return type
- Raises
RuntimeError -- if no presentation was set at the construction of
s
or withStephen.init()
.- Warning
The problem of determining whether two words are equal in a finitely presented semigroup is undecidable in general, and this function may never terminate.
- dead(self: libsemigroups::Runner) bool ¶
Check if the runner is dead.
- Parameters
None
- Returns
A
bool
.
- finished(self: _libsemigroups_pybind11.Stephen) bool ¶
Check if the main algorithm, implemented in this class, has been run to completion or not.
- Parameters
None
- Returns
A
bool
.
- init(*args, **kwargs)¶
Overloaded function.
init(self: _libsemigroups_pybind11.Stephen, p: _libsemigroups_pybind11.PresentationWords) -> _libsemigroups_pybind11.Stephen
Initialize from a presentation with relation words given by lists of integers.
Replaces the current value (if any) returned by
Stephen.presentation()
by the argument, and the state of the object is the same as if it had been newly constructed from the presentationp
.- Parameters
p (Presentation) - the presentation.
- Returns
self
.- Raises
RunTimeError
ifp.validate()
raises.- Raises
RunTimeError
ifp.alphabet().size()
is0
.
init(self: _libsemigroups_pybind11.Stephen, p: _libsemigroups_pybind11.PresentationStrings) -> _libsemigroups_pybind11.Stephen
Initialize from a presentation with relation words given by strings.
Replaces the current value (if any) returned by
Stephen.presentation()
by the argument, and the state of the object is the same as if it had been newly constructed from the presentationp
.- Parameters
p (Presentation) - the presentation.
- Returns
self
.- Raises
RunTimeError
ifp.validate()
raises.- Raises
RunTimeError
ifp.alphabet().size()
is0
.
- kill(self: libsemigroups::Runner) None ¶
Stop running the main algorithm(s) (thread-safe).
- Parameters
None
- Returns
(None).
- presentation(self: _libsemigroups_pybind11.Stephen) _libsemigroups_pybind11.PresentationWords ¶
The input presentation.
- Returns
the input presentation
- Return type
- report(self: _libsemigroups_pybind11.Stephen) bool ¶
Check if it is time to report.
- Parameters
None
- Returns
A
bool
.
- report_every(self: _libsemigroups_pybind11.Stephen, 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.Stephen) None ¶
Report why we stopped.
- Parameters
None
- Returns
(None)
- run(self: _libsemigroups_pybind11.Stephen) None ¶
Run the algorithm until it finishes. :Parameters: None
- Returns
(None)
- run_for(self: _libsemigroups_pybind11.Stephen, 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.Stephen, func: Callable[[], bool]) None ¶
Run until a nullary predicate returns
True
orfinished()
.- Parameters
func (Callable[], bool) -- a function.
- Returns
(None)
- running(self: libsemigroups::Runner) bool ¶
Check if currently running.
- Parameters
(None)
- Returns
True
ifrun()
is in the process of running andFalse
if it is not.
See also
- set_word(self: _libsemigroups_pybind11.Stephen, w: List[int]) _libsemigroups_pybind11.Stephen ¶
Set the word.
- Parameters
w (List[int]) - the input word
- Returns
self
.
- started(self: _libsemigroups_pybind11.Stephen) bool ¶
Check if
run()
has been called at least once before.Returns
True
ifrun()
has started to run (it can be running or not).- Parameters
(None)
- Returns
A
bool
.
See also
- stopped(self: _libsemigroups_pybind11.Stephen) 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.Stephen) 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
.
- timed_out(self: _libsemigroups_pybind11.Stephen) bool ¶
Check if the main algorithm has or should timed out.
- Parameters
None
- Returns
A
bool
.
- word(self: _libsemigroups_pybind11.Stephen) List[int] ¶
The word.
- Returns
The word used to initialise the current instance of
Stephen()
.
- word_graph(self: _libsemigroups_pybind11.Stephen) _libsemigroups_pybind11.ActionDigraph ¶
The word graph.
Returns the word graph in its present state. The algorithm implemented in this class is not triggered by calls to this function.
- Returns
The underlying word graph.
- Return type