Skip to content

Commit 33f2de4

Browse files
presentation: add add_cyclic_conjugates
1 parent ce48fed commit 33f2de4

4 files changed

Lines changed: 67 additions & 0 deletions

File tree

docs/source/data-structures/presentations/present-helpers.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Contents
3434
.. autosummary::
3535
:signatures: short
3636

37+
add_cyclic_conjugates
3738
add_identity_rules
3839
add_inverse_rules
3940
add_rule

src/libsemigroups_pybind11/presentation/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
presentation_throw_if_bad_inverses as _throw_if_bad_inverses,
5454
presentation_to_gap_string as _to_gap_string,
5555
presentation_balance as _balance,
56+
presentation_add_cyclic_conjugates as _add_cyclic_conjugates,
5657
)
5758

5859
from libsemigroups_pybind11.detail.cxx_wrapper import (
@@ -265,3 +266,4 @@ def __init__(self: _Self, *args, **kwargs) -> None:
265266
throw_if_bad_inverses = _wrap_cxx_free_fn(_throw_if_bad_inverses)
266267
to_gap_string = _wrap_cxx_free_fn(_to_gap_string)
267268
balance = _wrap_cxx_free_fn(_balance)
269+
add_cyclic_conjugates = _wrap_cxx_free_fn(_add_cyclic_conjugates)

src/present.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,34 @@ appended to the front of the right-hand side.
13691369
actually inverses for the values in *letters*, and balances the relations
13701370
as described above.
13711371
)pbdoc");
1372+
1373+
m.def(
1374+
"presentation_add_cyclic_conjugates",
1375+
[](Presentation<Word>& p, Word const& relator) {
1376+
presentation::add_cyclic_conjugates(p, relator);
1377+
},
1378+
py::arg("p"),
1379+
py::arg("relator"),
1380+
R"pbdoc(
1381+
:sig=(p: Presentation, relator: Word) -> None:
1382+
:only-document-once:
1383+
1384+
Add all cyclic permutations of a word as relators in a presentation.
1385+
1386+
This function adds one rule with left-hand side ``w`` and right-hand side the
1387+
empty word to the presentation *p*, for every cyclic permutation ``w`` of
1388+
*relator*.
1389+
1390+
:param p: the presentation.
1391+
:type p: Presentation
1392+
1393+
:param relator: the word.
1394+
:type relator: :ref:`Word<pseudo_word_type_helper>`
1395+
1396+
:raises LibsemigroupsError:
1397+
if *relator* contains any letters not belonging to ``p.alphabet()``.
1398+
1399+
:raises LibsemigroupsError: if *p* does not contain the empty word.)pbdoc");
13721400
} // bind_present
13731401

13741402
template <typename Word>

tests/test_present.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,3 +2156,39 @@ def test_presentation_balance_3_arg():
21562156
"cacacaccacacbbbb",
21572157
"accacbabbbcbcab",
21582158
]
2159+
2160+
2161+
def test_presentation_add_cyclic_conjugates():
2162+
p = Presentation("abc")
2163+
p.contains_empty_word(True)
2164+
2165+
presentation.add_cyclic_conjugates(p, "abcaabbcc")
2166+
assert p.rules == [
2167+
"abcaabbcc",
2168+
"",
2169+
"bcaabbcca",
2170+
"",
2171+
"caabbccab",
2172+
"",
2173+
"aabbccabc",
2174+
"",
2175+
"abbccabca",
2176+
"",
2177+
"bbccabcaa",
2178+
"",
2179+
"bccabcaab",
2180+
"",
2181+
"ccabcaabb",
2182+
"",
2183+
"cabcaabbc",
2184+
"",
2185+
"abcaabbcc",
2186+
"",
2187+
]
2188+
p.rules = []
2189+
p.contains_empty_word(False)
2190+
2191+
with pytest.raises(LibsemigroupsError):
2192+
presentation.add_cyclic_conjugates(p, "abcaabbcc")
2193+
with pytest.raises(LibsemigroupsError):
2194+
presentation.add_cyclic_conjugates(p, "dadadad")

0 commit comments

Comments
 (0)