Skip to content

Commit a1ac5c8

Browse files
The bindings of Stephen (#224)
1 parent 8ee4714 commit a1ac5c8

File tree

11 files changed

+2318
-14
lines changed

11 files changed

+2318
-14
lines changed

docs/source/libsemigroups.bib

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,10 @@ @misc{Abram2024aa
636636
title = {Power Quotients of Plactic-like Monoids},
637637
year = {2024}
638638
}
639+
@article{Stephen1987aa,
640+
title = {Applications of automata theory to presentations of monoids and inverse monoids},
641+
url = {https://digitalcommons.unl.edu/dissertations/AAI8803771},
642+
journal = {ETD collection for University of Nebraska-Lincoln},
643+
author = {Stephen, Joseph Buchanan},
644+
month = {01},
645+
year = {1987}}

docs/source/main-algorithms/stephen/index.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ Stephen
88
=======
99

1010
This page contains links to the functionality in ``libsemigroups_pybind11``
11-
related to Stephen's procedure for finitely presented semigroups.
11+
related to Stephen's procedure :cite:`Stephen1987aa` for finitely presented
12+
semigroups.
1213

1314
.. toctree::
1415
:maxdepth: 1
1516

1617
stephen
1718
stephen-helpers
18-
19-
Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. Copyright (c) 2022-2024 J. D. Mitchell
1+
.. Copyright (c) 2022-2025 R. Cirpons, J. D. Mitchell
22
33
Distributed under the terms of the GPL license version 3.
44
@@ -7,9 +7,34 @@
77
This file only exists because Breathe always displays all members when
88
documenting a namespace, and this is nicer for now.
99
10-
.. currentmodule:: _libsemigroups_pybind11
10+
Helpers functions for Stephen's procedure
11+
=========================================
1112

12-
Stephen helpers
13-
---------------
13+
This page contains the documentation for various helper functions for
14+
manipulating :any:`StephenPresentationWords` objects.
1415

15-
TODO
16+
Contents
17+
--------
18+
19+
.. currentmodule:: libsemigroups_pybind11.stephen
20+
21+
.. autosummary::
22+
:signatures: short
23+
24+
accepts
25+
dot
26+
is_left_factor
27+
left_factors
28+
number_of_left_factors
29+
number_of_words_accepted
30+
words_accepted
31+
32+
Full API
33+
--------
34+
35+
.. currentmodule:: libsemigroups_pybind11
36+
37+
.. automodule:: libsemigroups_pybind11.stephen
38+
:members:
39+
:exclude-members: Stephen
40+
:imported-members:
Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
1-
.. Copyright (c) 2022-2024 J. D. Mitchell
1+
.. Copyright (c) 2022-2025 R. Cirpons, J. D. Mitchell
22
33
Distributed under the terms of the GPL license version 3.
44
55
The full license is in the file LICENSE, distributed with this software.
66
77
.. currentmodule:: _libsemigroups_pybind11
88

9-
Stephen
10-
=======
9+
The Stephen class
10+
=====================
1111

12-
TODO
12+
.. autoclass:: StephenPresentationWords
13+
:doc-only:
14+
:class-doc-from: class
15+
16+
Contents
17+
--------
18+
19+
.. autosummary::
20+
:signatures: short
21+
22+
~StephenPresentationWords
23+
StephenPresentationWords.accept_state
24+
StephenPresentationWords.init
25+
StephenPresentationWords.is_word_set
26+
StephenPresentationWords.presentation
27+
StephenPresentationWords.set_word
28+
StephenPresentationWords.word
29+
StephenPresentationWords.word_graph
30+
StephenPresentationWords.initial_state
31+
32+
Full API
33+
--------
34+
35+
.. autoclass:: StephenPresentationWords
36+
:class-doc-from: init
37+
:members:

etc/replace-strings-in-doc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"PPerm1": "PPerm",
2828
"Perm1": "Perm",
2929
"PresentationStrings": "Presentation",
30+
"PresentationWords": "Presentation",
3031
"RightActionPPerm1List": "Action",
3132
"SchreierSimsPerm1": "SchreierSims",
3233
"ToddCoxeterImpl": "ToddCoxeter",
@@ -43,6 +44,7 @@
4344
r"SimsSettingsSims1": "SimsSettings",
4445
r"_libsemigroups_pybind11.": "",
4546
r"libsemigroups_pybind11\.": "",
47+
r"StephenPresentationWords": "Stephen",
4648
}
4749

4850
html_glob = "docs/_build/html/**/*.html"

libsemigroups_pybind11/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,7 @@
111111
from .froidure_pin import FroidurePin
112112
from .schreier_sims import SchreierSims
113113

114+
from .stephen import Stephen
115+
114116
from .to import to
115117
from .konieczny import Konieczny

libsemigroups_pybind11/stephen.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,63 @@
1414
"""
1515

1616
from _libsemigroups_pybind11 import (
17+
PresentationWords as _PresentationWords,
18+
InversePresentationWords as _InversePresentationWords,
19+
StephenPresentationWords as _StephenPresentationWords,
20+
StephenInversePresentationWords as _StephenInversePresentationWords,
1721
accepts,
22+
dot,
1823
is_left_factor,
1924
left_factors,
2025
number_of_left_factors,
2126
number_of_words_accepted,
2227
words_accepted,
2328
)
29+
30+
31+
# TODO(2): Make this work with string presentations once it works
32+
# TODO(0): Change this to a proper class similar to what's done with Kambites
33+
# (once the proper classes PR is merged)
34+
def Stephen(*args): # pylint: disable=invalid-name
35+
"""Construct a Stephen instance of the type specified by its arguments.
36+
37+
Options for calling this function are:
38+
1 Stephen(presentation: PresentationWords)
39+
2 Stephen(presentation: InversePresentationWords)
40+
3 Stephen(presentation: StephenPresentationWords)
41+
4 Stephen(presentation: StephenInversePresentationWords)
42+
43+
In cases 1 and 2 a new Stephen object is constructed with the given
44+
presentation. In cases 3 and 4 the Stephen object is constructed by copying
45+
an existing Stephen object. In cases 1 and 3 a StephenPresentationWords
46+
object is returned. In cases 2 and 4 a StephenInversePresentationWords
47+
object is returned.
48+
"""
49+
50+
if len(args) != 1:
51+
raise ValueError(f"expected 1 argument, but got {len(args)}")
52+
53+
presentation_or_stephen = args[0]
54+
# Order important here due to inheritance
55+
if isinstance(
56+
presentation_or_stephen,
57+
(_InversePresentationWords, _StephenInversePresentationWords),
58+
):
59+
PresentationType = _InversePresentationWords
60+
elif isinstance(
61+
presentation_or_stephen, (_PresentationWords, _StephenPresentationWords)
62+
):
63+
PresentationType = _PresentationWords
64+
else:
65+
raise TypeError(
66+
f"expected first argument to have type in {{PresentationWords, "
67+
f"InversePresentationWords, StephenPresentationWords, "
68+
f"StephenInversePresentationWords}}, but found {type(presentation_or_stephen)}"
69+
)
70+
71+
cpp_type = {
72+
_PresentationWords: _StephenPresentationWords,
73+
_InversePresentationWords: _StephenInversePresentationWords,
74+
}
75+
76+
return cpp_type[PresentationType](presentation_or_stephen)

src/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ The valid values are:
152152
m.attr("LIBSEMIGROUPS_EIGEN_ENABLED")
153153
= static_cast<bool>(LIBSEMIGROUPS_EIGEN_ENABLED);
154154
#else
155-
m.attr("LIBSEMIGROUPS_EIGEN_ENABLED") = false;
155+
m.attr("LIBSEMIGROUPS_EIGEN_ENABLED") = false;
156156
#endif
157157

158158
#ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED
@@ -218,6 +218,7 @@ The valid values are:
218218
init_inverse_present(m);
219219
init_to_present(m);
220220
init_sims(m);
221+
init_stephen(m);
221222
init_transf(m);
222223
init_ranges(m);
223224
init_words(m);
@@ -246,7 +247,7 @@ The valid values are:
246247
#ifdef VERSION_INFO
247248
m.attr("__version__") = VERSION_INFO;
248249
#else
249-
m.attr("__version__") = "dev";
250+
m.attr("__version__") = "dev";
250251
#endif
251252

252253
////////////////////////////////////////////////////////////////////////

src/main.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace libsemigroups {
5454
void init_ranges(py::module&);
5555
void init_reporter(py::module&);
5656
void init_runner(py::module&);
57+
void init_stephen(py::module&);
5758
void init_schreier_sims(py::module&);
5859
void init_sims(py::module&);
5960
void init_to_congruence(py::module&);

0 commit comments

Comments
 (0)