Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/present.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1581,16 +1581,18 @@ modified version.
* :any:`is_strongly_compressible`

)pbdoc");

m.def(
"presentation_to_gap_string",
[](Presentation_ const& p, std::string const& var_name) {
return presentation::to_gap_string(p, var_name);
},
py::arg("p"),
py::arg("var_name"),
py::arg("var_name") = "S",
R"pbdoc(
:sig=(p: Presentation, var_name: str) -> str:
:only-document-once:

Return the code that would create *p* in GAP.

This function returns the string of GAP code that could be used to create an
Expand All @@ -1600,12 +1602,26 @@ are created by taking quotients of free semigroups or monoids.
:param p: the presentation.
:type p: Presentation

:param var_name: the name of the variable to be used in GAP.
:param var_name: the name of the variable to be used in GAP (defaults to ``"S"``).
:type var_name: str

:returns: The GAP string.
:rtype: str

.. doctest::

>>> from libsemigroups_pybind11 import Presentation, presentation
>>> p = Presentation("ab")
>>> presentation.add_rule(p, "ab", "ba")
>>> print(presentation.to_gap_string(p), end="")
F := FreeSemigroup("a", "b");
AssignGeneratorVariables(F);;
R := [
[a * b, b * a]
];
S := F / R;
)pbdoc");

m.def(
"presentation_to_ace_string",
[](Presentation_ const& p) { return presentation::to_ace_string(p); },
Expand Down
37 changes: 37 additions & 0 deletions tests/test_present.py
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,38 @@ def check_to_ace_string(W):
)


def check_to_gap_string(W):
p = Presentation(W([0, 1]))
presentation.add_rule(p, W([0, 1]), W([1, 0]))

a, b = ("s0", "s1") if W is to_word else ("a", "b")
assert (
presentation.to_gap_string(p)
== f"""F := FreeSemigroup("{a}", "{b}");
AssignGeneratorVariables(F);;
R := [
[{a} * {b}, {b} * {a}]
];
S := F / R;
"""
)

a, b = ("m0", "m1") if W is to_word else ("a", "b")
p.contains_empty_word(True)
presentation.add_rule(p, W([0, 0]), W([]))
assert (
presentation.to_gap_string(p, "M")
== f"""F := FreeMonoid("{a}", "{b}");
AssignGeneratorVariables(F);;
R := [
[{a} * {b}, {b} * {a}],
[{a} * {a}, One(F)]
];
M := F / R;
"""
)


###############################################################################
# Test functions begin
###############################################################################
Expand Down Expand Up @@ -1780,3 +1812,8 @@ def test_add_idempotent_rules():
def test_to_ace_string():
check_to_ace_string(to_word)
check_to_ace_string(to_string)


def test_to_gap_string():
check_to_gap_string(to_word)
check_to_gap_string(to_string)
Loading