Skip to content

Commit 4677d17

Browse files
presentation: add is_normalized
1 parent 3d14e86 commit 4677d17

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Contents
4848
greedy_reduce_length
4949
greedy_reduce_length_and_number_of_gens
5050
index_rule
51+
is_normalized
5152
is_strongly_compressible
5253
length
5354
longest_rule

src/libsemigroups_pybind11/presentation/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
presentation_balance as _balance,
5555
presentation_add_cyclic_conjugates as _add_cyclic_conjugates,
5656
presentation_index_rule as _index_rule,
57+
presentation_is_normalized as _is_normalized,
5758
)
5859

5960
from libsemigroups_pybind11.detail.cxx_wrapper import (
@@ -270,3 +271,4 @@ def __init__(self: _Self, *args, **kwargs) -> None:
270271
balance = _wrap_cxx_free_fn(_balance)
271272
add_cyclic_conjugates = _wrap_cxx_free_fn(_add_cyclic_conjugates)
272273
index_rule = _wrap_cxx_free_fn(_index_rule)
274+
is_normalized = _wrap_cxx_free_fn(_is_normalized)

src/present.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,27 @@ This function returns the minimum index ``i`` of *lhs* such that ``p.rules[i +
14311431
14321432
:raises LibsemigroupsError: if ``p.throw_if_bad_alphabet_or_rules()`` throws.
14331433
)pbdoc");
1434+
1435+
m.def(
1436+
"presentation_is_normalized",
1437+
[](Presentation<Word>& p) { return presentation::is_normalized(p); },
1438+
py::arg("p"),
1439+
R"pbdoc(
1440+
:sig=(p: Presentation) -> bool:
1441+
:only-document-once:
1442+
1443+
Check if the presentation is normalized.
1444+
1445+
This function returns ``True`` if the :any:`Presentation.alphabet` of *p* is
1446+
``0`` to ``p.alphabet().size() - 1`` and ``False`` otherwise.
1447+
1448+
:param p: the presentation to check.
1449+
:type p: Presentation
1450+
1451+
:returns: Whether or not the presentation *p* is normalized.
1452+
:rtype: bool
1453+
)pbdoc");
1454+
14341455
} // bind_present
14351456

14361457
template <typename Word>

tests/test_present.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# pylint: disable=missing-function-docstring, invalid-name
1313
# pylint: disable=comparison-with-callable, too-many-lines
1414

15-
1615
import copy
1716
import pytest
1817
from libsemigroups_pybind11 import (
@@ -2200,3 +2199,17 @@ def test_presentation_index_rule():
22002199

22012200
assert presentation.index_rule(p, "aaaa", "") == 0
22022201
assert presentation.index_rule(p, "a", "") == UNDEFINED
2202+
2203+
2204+
def test_presentation_is_normalized():
2205+
p = Presentation("abc")
2206+
p.contains_empty_word(True)
2207+
p.rules = ["aaaa", ""]
2208+
assert not presentation.is_normalized(p)
2209+
p.alphabet("bac")
2210+
assert not presentation.is_normalized(p)
2211+
2212+
p = Presentation([0, 1, 2])
2213+
p.contains_empty_word(True)
2214+
p.rules = [[0] * 4, []]
2215+
assert presentation.is_normalized(p)

0 commit comments

Comments
 (0)