Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality for ToddCoxeter function to_gap_string #118

Merged
Merged
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
1 change: 1 addition & 0 deletions docs/source/api/toddcoxeter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ of (any version of) the Todd-Coxeter algorithm.
ToddCoxeter.strategy_options
ToddCoxeter.timed_out
ToddCoxeter.word_to_class_index
ToddCoxeter.to_gap_string

.. autoclass:: ToddCoxeter
:members:
17 changes: 13 additions & 4 deletions src/todd-coxeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ namespace libsemigroups {
Randomly shuffle all existing generating pairs.
)pbdoc")
.def("report_every",
(void (congruence::ToddCoxeter::*)(std::chrono::nanoseconds))
(void(congruence::ToddCoxeter::*)(std::chrono::nanoseconds))
& Runner::report_every,
py::arg("t"),
runner_doc_strings::report_every)
Expand All @@ -418,12 +418,12 @@ namespace libsemigroups {
.def("kill", &congruence::ToddCoxeter::kill, runner_doc_strings::kill)
.def("run", &congruence::ToddCoxeter::run, runner_doc_strings::run)
.def("run_for",
(void (congruence::ToddCoxeter::*)(std::chrono::nanoseconds))
(void(congruence::ToddCoxeter::*)(std::chrono::nanoseconds))
& Runner::run_for,
py::arg("t"),
runner_doc_strings::run_for)
.def("run_until",
(void (congruence::ToddCoxeter::*)(std::function<bool()>&))
(void(congruence::ToddCoxeter::*)(std::function<bool()>&))
& Runner::run_until,
py::arg("func"),
runner_doc_strings::run_until)
Expand Down Expand Up @@ -560,6 +560,15 @@ namespace libsemigroups {
R"pbdoc(
Returns an iterator to the normal forms of the congruence
represented by an instance of :py:class:`ToddCoxeter`.
)pbdoc");
)pbdoc")
.def("to_gap_string",
&congruence::ToddCoxeter::to_gap_string,
R"pbdoc(
Returns a string containing a GAP definition of the finitely presented semigroup represented by a ``ToddCoxeter`` instance.

:parameters: None

:returns: A string
)pbdoc");
}
} // namespace libsemigroups
27 changes: 27 additions & 0 deletions tests/test_todd_coxeter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@

import pytest

from libsemigroups_pybind11.tools import (
libsemigroups_version,
compare_version_numbers,
)

from libsemigroups_pybind11 import (
FroidurePin,
KnuthBendix,
Expand Down Expand Up @@ -345,3 +350,25 @@ def test_096():
assert copy.number_of_classes() == 1
assert copy.complete()
assert copy.compatible()


def test_to_gap_string():
ReportGuard(False)
tc = ToddCoxeter(congruence_kind.twosided)
tc.set_number_of_generators(2)
tc.add_pair([0, 1], [1, 0])
assert len(tc.to_gap_string()) > 0

tc = ToddCoxeter(congruence_kind.left)
tc.set_number_of_generators(2)
tc.add_pair([0, 1], [1, 0])
if compare_version_numbers(libsemigroups_version(), "2.6.0"):
with pytest.raises(RuntimeError):
tc.to_gap_string()

tc = ToddCoxeter(congruence_kind.right)
tc.set_number_of_generators(2)
tc.add_pair([0, 1], [1, 0])
if compare_version_numbers(libsemigroups_version(), "2.6.0"):
with pytest.raises(RuntimeError):
tc.to_gap_string()