Stephen helpers
This page contains the documentation for various helper functions for
manipulating Stephen
objects.
Contents
|
Check if a word is accepted by a |
|
Return a |
Check if a word is a left factor of |
|
|
Returns a |
Returns the number of left factors with length in a given range. |
|
Returns the number of words accepted with length in a given range. |
|
Returns a |
Full API
This page contains the documentation for various helper functions for
manipulating Stephen
objects. All such functions
are contained in the submodule stephen
.
- stephen.accepts(s: Stephen, w: list[int]) bool
Check if a word is accepted by a
Stephen
instance.This function triggers the algorithm implemented in this class (if it hasn’t been triggered already), and then returns
True
if the input word w labels a path inStephen.word_graph
with source0
and targetStephen.accept_state
.For a
Stephen
instance constructed from aPresentation
, a word w is accepted if and only if w is equivalent toStephen.word
in the semigroup defined byStephen.presentation
.For a
Stephen
instance constructed from aInversePresentation
, a word w is accepted if and only if \(uu^{-1}w\) is equivalent to \(u\) in the semigroup defined byStephen.presentation
, where \(u\) is the value ofStephen.word
.- Parameters:
- Returns:
A
bool
.- Return type:
- Raises:
LibsemigroupsError – if no presentation was set at the construction of s or with
Stephen.init
or if no word was set withStephen.set_word
.
Warning
Termination of the Stephen algorithm is undecidable in general, and this function may never terminate.
- stephen.dot(s: Stephen) Dot
Return a
Dot
object representing the underlying word graph of theStephen
object s.
- stephen.is_left_factor(s: Stephen, w: list[int]) bool
Check if a word is a left factor of
Stephen.word
.This function triggers the algorithm implemented in this class (if it hasn’t been triggered already), and then returns
True
if the input word w is a left factor ofStephen.word
in the semigroup defined byStephen.presentation
. A word is a left factor ofStephen.word
if it labels a path inStephen.word_graph
with source0
.- Parameters:
- Returns:
A
bool
.- Return type:
- Raises:
LibsemigroupsError – if no presentation was set at the construction of s or with
Stephen.init
or if no word was set withStephen.set_word
.
Warning
Termination of the Stephen algorithm is undecidable in general, and this function may never terminate.
- stephen.left_factors(s: Stephen) Paths
Returns a
Paths
object containing all the words (in short-lex order) that are left factors ofStephen.word
.This function triggers the algorithm implemented in this class (if it hasn’t been triggered already).
- Parameters:
s (Stephen) – the Stephen instance
- Returns:
A
Paths
object containing all the words (in short-lex order) that are left factors ofStephen.word
.- Return type:
- Raises:
LibsemigroupsError – if no presentation was set at the construction of s or with
Stephen.init
or if no word was set withStephen.set_word
.
Warning
Termination of the Stephen algorithm is undecidable in general, and this function may never terminate.
- stephen.number_of_left_factors(s: Stephen, min: int = 0, max: int | PositiveInfinity = POSITIVE_INFINITY) int | PositiveInfinity
Returns the number of left factors with length in a given range.
This function returns the number of left factors of the
Stephen.word
in the instance s with length between min and max. This is the same as the number of paths inStephen.word_graph
(if the inheritedRunner.run
method of s has been called) with source0
and length in the range min to max.- Parameters:
s (Stephen) – the Stephen instance.
min (int) – the minimum length of a word (default: 0).
max (int | PositiveInfinity) – one more than the maximum length of a word (default:
POSITIVE_INFINITY
).
- Returns:
An
int
orPOSITIVE_INFINITY
.- Return type:
- Raises:
LibsemigroupsError – if no presentation was set at the construction of s or with
Stephen.init
or if no word was set withStephen.set_word
.
Warning
Termination of the Stephen algorithm is undecidable in general, and this function may never terminate.
- stephen.number_of_words_accepted(s: Stephen, min: int = 0, max: int | PositiveInfinity = POSITIVE_INFINITY) int | PositiveInfinity
Returns the number of words accepted with length in a given range.
This function triggers the algorithm implemented in this class (if it hasn’t been triggered already) and then returns the the number of paths in
Stephen.word_graph
with source0
, targetStephen.accept_state
, and length in the range min to max.For a
Stephen
instance constructed from aPresentation
this is the same as the number of words that are equivalent toStephen.word
with length between min and max.For a
Stephen
instance constructed from aInversePresentation
, this is the same as the number of words w such that \(uu^{-1}w\) is equivalent to \(u\) in the semigroup defined byStephen.presentation
, where \(u\) is the value ofStephen.word
.- Parameters:
s (Stephen) – the Stephen instance.
min (int) – the minimum length of a word (default:
0
).max (int | PositiveInfinity) – one more than the maximum length of a word (default:
POSITIVE_INFINITY
).
- Returns:
The number of words accepted.
- Return type:
- Raises:
LibsemigroupsError – if no presentation was set at the construction of s or with
Stephen.init
or if no word was set withStephen.set_word
.
Warning
Termination of the Stephen algorithm is undecidable in general, and this function may never terminate.
- stephen.words_accepted(s: Stephen) Paths
Returns a
Paths
object containing all words accepted by a Stephen instance in short-lex order.This function triggers the algorithm implemented in this class (if it hasn’t been triggered already).
- Parameters:
s (Stephen) – the Stephen instance
- Returns:
A
Paths
object containing all words equivalent toStephen.word
in short-lex order.- Return type:
- Raises:
LibsemigroupsError – if no presentation was set at the construction of s or with
Stephen.init
or if no word was set withStephen.set_word
.
Warning
Termination of the Stephen algorithm is undecidable in general, and this function may never terminate.