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
129 changes: 129 additions & 0 deletions docs/pictures/stephen-inverse-word-graph-default.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
224 changes: 224 additions & 0 deletions docs/pictures/stephen-inverse-word-graph.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Contents
greedy_reduce_length
greedy_reduce_length_and_number_of_gens
index_rule
inverse_alphabet
is_normalized
is_rule
is_strongly_compressible
Expand Down
1 change: 1 addition & 0 deletions docs/source/data-structures/visualisation/dot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Contents
Dot.name
Dot.node
Dot.nodes
Dot.rm_node
Dot.subgraphs
Dot.to_string

Expand Down
29 changes: 29 additions & 0 deletions src/dot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,35 @@ the represented graph and ``False`` otherwise.
:returns: Whether or not *name* is the name of a node.
:rtype: bool
)pbdoc");

dot.def(
"rm_node",
[](Dot& self, std::string const& name) { self.rm_node(name); },
py::arg("name"),
R"pbdoc(
:sig=(self: Dot, name: str) -> None:

Remove a node from the represented graph.

This function removes the node named *name*.

:param name: the name of the node to remove.
:type name: str

:raises LibsemigroupsError: if there is no node named *name*.

.. doctest::

>>> from libsemigroups_pybind11 import Dot
>>> graph = Dot()
>>> node = graph.add_node("a")
>>> graph.is_node("a")
True
>>> graph.rm_node("a")
>>> graph.is_node("a")
False
)pbdoc");

dot.def("kind",
py::overload_cast<Dot::Kind>(&Dot::kind),
py::arg("val"),
Expand Down
3 changes: 3 additions & 0 deletions src/libsemigroups_pybind11/presentation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
presentation_greedy_reduce_length as _greedy_reduce_length,
presentation_greedy_reduce_length_and_number_of_gens as _greedy_reduce_length_and_num_of_gens,
presentation_index_rule as _index_rule,
presentation_inverse_alphabet as _inverse_alphabet,
presentation_is_normalized as _is_normalized,
presentation_is_rule as _is_rule,
presentation_is_strongly_compressible as _is_strongly_compressible,
Expand Down Expand Up @@ -249,6 +250,7 @@ def __init__(self: _Self, *args, **kwargs) -> None:
first_unused_letter = _wrap_cxx_free_fn(_first_unused_letter)
greedy_reduce_length = _wrap_cxx_free_fn(_greedy_reduce_length)
greedy_reduce_length_and_number_of_gens = _wrap_cxx_free_fn(_greedy_reduce_length_and_num_of_gens)
inverse_alphabet = _wrap_cxx_free_fn(_inverse_alphabet)
is_strongly_compressible = _wrap_cxx_free_fn(_is_strongly_compressible)
length = _wrap_cxx_free_fn(_length)
longest_rule = _wrap_cxx_free_fn(_longest_rule)
Expand Down Expand Up @@ -299,6 +301,7 @@ def __init__(self: _Self, *args, **kwargs) -> None:
"first_unused_letter",
"greedy_reduce_length",
"greedy_reduce_length_and_number_of_gens",
"inverse_alphabet",
"is_strongly_compressible",
"length",
"longest_rule",
Expand Down
62 changes: 55 additions & 7 deletions src/present.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,25 +1216,68 @@ identity, then this generator is returned.

:raises LibsemigroupsError: if :any:`replace_word` or
:any:`add_identity_rules` does.
)pbdoc");
m.def("presentation_inverse_alphabet",
&presentation::inverse_alphabet<Word>,
py::arg("p"),
R"pbdoc(
:sig=(p: InversePresentation) -> Word:
:only-document-once:

Return an inverse semigroup generating set.

This function returns an inverse semigroup generating set of the semigroup
defined by an inverse presentation. More specifically, for every letter
:math:`x` in the alphabet of *p*, the returned word contains precisely one of
:math:`x` and :math:`x^{-1}`.

:param p: the inverse presentation.
:type p: InversePresentation

:returns: The inverse semigroup generating set.
:rtype: :ref:`Word<pseudo_word_type_helper>`

:raises LibsemigroupsError:
if :any:`InversePresentation.throw_if_bad_alphabet_rules_or_inverses` raises
an exception.

.. doctest::

>>> from libsemigroups_pybind11 import InversePresentation, presentation
>>> p = InversePresentation("abcABC").inverses("ABCabc")
>>> presentation.inverse_alphabet(p)
'abc'
)pbdoc");
m.def("presentation_normalize_alphabet",
&presentation::normalize_alphabet<Word>,
py::overload_cast<Presentation_&>(
&presentation::normalize_alphabet<Word>),
py::arg("p"),
R"pbdoc(
:sig=(p: Presentation) -> None:
:sig=(p: Presentation | InversePresentation) -> None:
:only-document-once:
Normalize the alphabet to :math:`\{0, \ldots, n - 1\}`.

Modify the presentation in-place so that the alphabet is :math:`\{0, \ldots,
n - 1\}` (or equivalent) and rewrites the rules to use this alphabet. If the
alphabet is already normalized, then no changes are made to the presentation.
n - 1\}` (or equivalent) and rewrites the rules to use this alphabet. For an
:any:`InversePresentation`, the inverses are also rewritten. If the alphabet is
already normalized, then no changes are made to the presentation.

:param p: the presentation.
:type p: Presentation
:type p: Presentation | InversePresentation

:raises LibsemigroupsError:
if :any:`Presentation.throw_if_bad_alphabet_or_rules` raises an exception on
the initial presentation.)pbdoc");
if the relevant presentation validity check raises an exception on the
initial presentation.

.. doctest::

>>> from libsemigroups_pybind11 import InversePresentation, presentation
>>> p = InversePresentation("xXyY").inverses("XxYy")
>>> p.rules = ["xyX", "Yx"]
>>> presentation.normalize_alphabet(p)
>>> p.alphabet(), p.rules, p.inverses()
('abcd', ['acb', 'da'], 'badc')
)pbdoc");
m.def("presentation_reduce_complements",
&presentation::reduce_complements<Word>,
py::arg("p"),
Expand Down Expand Up @@ -2102,6 +2145,11 @@ defined in the alphabet, and that the inverses act as semigroup inverses.
* :any:`Presentation.throw_if_bad_alphabet_or_rules`
* :any:`presentation.throw_if_bad_inverses`
)pbdoc");
m.def("presentation_normalize_alphabet",
py::overload_cast<InversePresentation_&>(
&presentation::normalize_alphabet<Word>),
py::arg("p"),
py::prepend());
} // bind_inverse_present
} // namespace

Expand Down
Loading
Loading