Skip to content

Commit e0135bf

Browse files
Make options a nested class of KnuthBendix
1 parent 3ddb601 commit e0135bf

File tree

8 files changed

+57
-57
lines changed

8 files changed

+57
-57
lines changed

docs/source/main-algorithms/knuth-bendix/class.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ Full API
4747
.. autoclass:: KnuthBendixRewriteTrie
4848
:class-doc-from: init
4949
:members:
50+
:exclude-members: options

docs/source/main-algorithms/knuth-bendix/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ in ``libsemigroups_pybind11``.
1616

1717
class
1818
helpers
19-
overlap
19+
nested
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.. Copyright (c) 2024 J. D. Mitchell
2+
3+
Distributed under the terms of the GPL license version 3.
4+
5+
The full license is in the file LICENSE, distributed with this software.
6+
7+
.. currentmodule:: libsemigroups_pybind11
8+
9+
The options nested class
10+
========================
11+
12+
This page contains documentation for the nested class
13+
:any:`KnuthBendixRewriteTrie.options` which holds various values that can be used
14+
to control the behaviour of Knuth-Bendix.
15+
16+
.. autoclass:: _libsemigroups_pybind11::KnuthBendixRewriteTrie.options
17+
:members:
18+
:exclude-members: name

docs/source/main-algorithms/knuth-bendix/overlap.rst

Lines changed: 0 additions & 15 deletions
This file was deleted.

libsemigroups_pybind11/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
lexicographical_compare,
4848
recursive_path_compare,
4949
shortlex_compare,
50-
overlap,
5150
to_presentation,
5251
to_inverse_presentation,
5352
LibsemigroupsError,

libsemigroups_pybind11/knuth_bendix.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,21 @@ def KnuthBendix(*args, rewriter="RewriteTrie"): # pylint: disable=invalid-name
8484
return result
8585

8686

87-
# The next function (non_trivial_classes) is documented here not in the cpp
88-
# file because we add the additional kwarg Word.
87+
KnuthBendix.options = _KnuthBendixRewriteTrie.options
8988

9089

90+
# The next function (non_trivial_classes) is documented here not in the cpp
91+
# file because we add the additional kwarg Word.
9192
@_template_params_as_kwargs(
9293
Word={
9394
str: _knuth_bendix_str_non_trivial_classes,
9495
List[int]: _knuth_bendix_word_non_trivial_classes,
9596
}
9697
)
9798
def non_trivial_classes(
98-
kb1: KnuthBendix, kb2: KnuthBendix, **kwargs
99+
kb1: KnuthBendix,
100+
kb2: KnuthBendix,
101+
**kwargs, # pylint: disable=unused-argument
99102
) -> List[List[str | List[int]]]:
100103
r"""
101104
Find the non-trivial classes of the quotient of one KnuthBendix instance in
@@ -173,7 +176,7 @@ def non_trivial_classes(
173176
List[int]: _knuth_bendix_word_normal_forms,
174177
}
175178
)
176-
def normal_forms(kb: KnuthBendix, **kwargs) -> Iterator[str | List[int]]:
179+
def normal_forms(kb: KnuthBendix, **kwargs) -> Iterator[str | List[int]]: # pylint: disable=unused-argument
177180
r"""
178181
Returns an iterator yielding normal forms.
179182

src/knuth-bendix.cpp

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ This class is used to represent a `string rewriting system
247247
presented monoid or semigroup.
248248
249249
:any:`KnuthBendixRewriteTrie` inherits from :any:`Runner` and
250-
:any:`CongruenceInterface`.
250+
:any:`CongruenceInterface`; and has the nested class
251+
:any:`KnuthBendixRewriteTrie.options`.
251252
252253
.. doctest::
253254
@@ -269,6 +270,33 @@ presented monoid or semigroup.
269270
True
270271
)pbdoc");
271272

273+
py::class_<typename KnuthBendix<Rewriter>::options> options(kb,
274+
"options",
275+
R"pbdoc(
276+
This class containing various options that can be used to control the
277+
behaviour of Knuth-Bendix.)pbdoc");
278+
279+
py::enum_<typename KnuthBendix<Rewriter>::options::overlap>(options,
280+
"overlap",
281+
R"pbdoc(
282+
Values for specifying how to measure the length of an overlap.
283+
284+
The values in this enum determine how a :any:`KnuthBendixRewriteTrie`
285+
instance measures the length :math:`d(AB, BC)` of the overlap of
286+
two words :math:`AB` and :math:`BC`.
287+
288+
.. seealso:: :any:`KnuthBendixRewriteTrie.overlap_policy`
289+
)pbdoc")
290+
.value("ABC",
291+
KnuthBendix<Rewriter>::options::overlap::ABC,
292+
R"pbdoc(:math:`d(AB, BC) = |A| + |B| + |C|`)pbdoc")
293+
.value("AB_BC",
294+
KnuthBendix<Rewriter>::options::overlap::AB_BC,
295+
R"pbdoc(:math:`d(AB, BC) = |AB| + |BC|`)pbdoc")
296+
.value("MAX_AB_BC",
297+
KnuthBendix<Rewriter>::options::overlap::MAX_AB_BC,
298+
R"pbdoc(:math:`d(AB, BC) = max(|AB|, |BC|)`)pbdoc");
299+
272300
kb.def("__repr__", [](KnuthBendix<Rewriter>& kb) {
273301
return to_human_readable_repr(kb);
274302
});
@@ -902,38 +930,6 @@ semigroup or monoid defined by the :py:class:`KnuthBendixRewriteTrie` object
902930
} // namespace
903931

904932
void init_knuth_bendix(py::module& m) {
905-
// TODO better repr?
906-
// TODO(1) this isn't done properly since there's not options object
907-
// registered, so referring to "options.overlap" doesn't work
908-
py::enum_<KnuthBendix<>::options::overlap>(m,
909-
"overlap",
910-
R"pbdoc(
911-
Values for specifying how to measure the length of an overlap.
912-
913-
The values in this enum determine how a :any:`KnuthBendixRewriteTrie`
914-
instance measures the length :math:`d(AB, BC)` of the overlap of
915-
two words :math:`AB` and :math:`BC`.
916-
917-
.. seealso:: :any:`KnuthBendixRewriteTrie.overlap_policy`
918-
)pbdoc")
919-
.value("ABC",
920-
KnuthBendix<>::options::overlap::ABC,
921-
R"pbdoc(
922-
923-
:math:`d(AB, BC) = |A| + |B| + |C|`
924-
)pbdoc")
925-
.value("AB_BC",
926-
KnuthBendix<>::options::overlap::AB_BC,
927-
R"pbdoc(
928-
929-
:math:`d(AB, BC) = |AB| + |BC|`
930-
)pbdoc")
931-
.value("MAX_AB_BC",
932-
KnuthBendix<>::options::overlap::MAX_AB_BC,
933-
R"pbdoc(
934-
935-
:math:`d(AB, BC) = max(|AB|, |BC|)`
936-
)pbdoc");
937933
bind_knuth_bendix<detail::RewriteFromLeft>(m, "KnuthBendixRewriteFromLeft");
938934
bind_knuth_bendix<detail::RewriteTrie>(m, "KnuthBendixRewriteTrie");
939935
}

tests/test_knuth_bendix.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
presentation,
2424
LibsemigroupsError,
2525
POSITIVE_INFINITY,
26-
overlap,
2726
is_obviously_infinite,
2827
)
2928

@@ -119,8 +118,7 @@ def test_attributes():
119118
assert kb.check_confluence_interval() == 4096
120119
assert kb.max_overlap() == POSITIVE_INFINITY
121120
assert kb.max_rules() == POSITIVE_INFINITY
122-
assert isinstance(kb.overlap_policy(), overlap)
123-
assert kb.overlap_policy() == overlap.ABC
121+
assert kb.overlap_policy() == kb.options.overlap.ABC
124122
assert kb.presentation().alphabet() == "abBe"
125123
assert kb.number_of_active_rules() == 12
126124
assert kb.number_of_inactive_rules() == 0

0 commit comments

Comments
 (0)