Skip to content

Commit 943eb1e

Browse files
Use proper class for KnuthBendix
1 parent 09630b7 commit 943eb1e

File tree

19 files changed

+282
-294
lines changed

19 files changed

+282
-294
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ letters of the type of word specified in *Return*.
159159

160160
.. _knuth-bendix-to-presentation:
161161

162-
Converting a :any:`KnuthBendixStringRewriteTrie` to a :any:`PresentationStrings`
162+
Converting a :any:`KnuthBendix` to a :any:`PresentationStrings`
163163
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164164

165165
To construct a :any:`PresentationStrings` from a
166-
:any:`KnuthBendixStringRewriteTrie`, specify the following values for
166+
:any:`KnuthBendix`, specify the following values for
167167
*args*:
168168

169-
* **kb** (:any:`KnuthBendixStringRewriteTrie`) -- the
170-
:any:`KnuthBendixStringRewriteTrie` from which to obtain the rules.
169+
* **kb** (:any:`KnuthBendix`) -- the
170+
:any:`KnuthBendix` from which to obtain the rules.
171171

172172
Additionally, specify the following for *Return*:
173173

@@ -186,7 +186,7 @@ this function.
186186

187187
.. seealso::
188188

189-
* :any:`KnuthBendixStringRewriteTrie.active_rules`; and
189+
* :any:`KnuthBendix.active_rules`; and
190190
* :any:`Runner.run`.
191191

192192
.. doctest:: Python

docs/source/main-algorithms/froidure-pin/to-froidure-pin.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ This function throws a :any:`LibsemigroupsError` if the
130130

131131
.. _knuth-bendix-to-froidure-pin:
132132

133-
Converting a :any:`KnuthBendixStringRewriteTrie` to a :any:`FroidurePinPBR`
133+
Converting a :any:`KnuthBendix` to a :any:`FroidurePinPBR`
134134
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135135

136-
To construct a :any:`FroidurePinPBR` from a :any:`KnuthBendixStringRewriteTrie`,
136+
To construct a :any:`FroidurePinPBR` from a :any:`KnuthBendix`,
137137
specify the following values for *args*:
138138

139-
* **kb** (:any:`KnuthBendixStringRewriteTrie`) -- the
140-
:any:`KnuthBendixStringRewriteTrie` object being converted.
139+
* **kb** (:any:`KnuthBendix`) -- the
140+
:any:`KnuthBendix` object being converted.
141141

142142
Additionally, specify the following for *Return*:
143143

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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
55
The full license is in the file LICENSE, distributed with this software.
66
7-
.. currentmodule:: _libsemigroups_pybind11
7+
.. currentmodule:: libsemigroups_pybind11
88

99
The KnuthBendix class
1010
=====================
1111

12-
.. autoclass:: KnuthBendixStringRewriteTrie
12+
.. autoclass:: KnuthBendix
1313
:doc-only:
1414
:class-doc-from: class
1515

@@ -25,35 +25,35 @@ Contents
2525
.. autosummary::
2626
:signatures: short
2727

28-
~KnuthBendixStringRewriteTrie
29-
KnuthBendixStringRewriteTrie.active_rules
30-
KnuthBendixStringRewriteTrie.check_confluence_interval
31-
KnuthBendixStringRewriteTrie.confluent
32-
KnuthBendixStringRewriteTrie.confluent_known
33-
KnuthBendixStringRewriteTrie.contains
34-
KnuthBendixStringRewriteTrie.copy
35-
KnuthBendixStringRewriteTrie.currently_contains
36-
KnuthBendixStringRewriteTrie.generating_pairs
37-
KnuthBendixStringRewriteTrie.gilman_graph
38-
KnuthBendixStringRewriteTrie.gilman_graph_node_labels
39-
KnuthBendixStringRewriteTrie.max_overlap
40-
KnuthBendixStringRewriteTrie.max_pending_rules
41-
KnuthBendixStringRewriteTrie.max_rules
42-
KnuthBendixStringRewriteTrie.number_of_active_rules
43-
KnuthBendixStringRewriteTrie.number_of_classes
44-
KnuthBendixStringRewriteTrie.number_of_inactive_rules
45-
KnuthBendixStringRewriteTrie.overlap_policy
46-
KnuthBendixStringRewriteTrie.presentation
47-
KnuthBendixStringRewriteTrie.reduce
48-
KnuthBendixStringRewriteTrie.reduce_no_run
49-
KnuthBendixStringRewriteTrie.total_rules
28+
~KnuthBendix
29+
KnuthBendix.active_rules
30+
KnuthBendix.check_confluence_interval
31+
KnuthBendix.confluent
32+
KnuthBendix.confluent_known
33+
KnuthBendix.contains
34+
KnuthBendix.copy
35+
KnuthBendix.currently_contains
36+
KnuthBendix.generating_pairs
37+
KnuthBendix.gilman_graph
38+
KnuthBendix.gilman_graph_node_labels
39+
KnuthBendix.max_overlap
40+
KnuthBendix.max_pending_rules
41+
KnuthBendix.max_rules
42+
KnuthBendix.number_of_active_rules
43+
KnuthBendix.number_of_classes
44+
KnuthBendix.number_of_inactive_rules
45+
KnuthBendix.overlap_policy
46+
KnuthBendix.presentation
47+
KnuthBendix.reduce
48+
KnuthBendix.reduce_no_run
49+
KnuthBendix.total_rules
5050

5151
Full API
5252
--------
5353

54-
.. autoclass:: KnuthBendixStringRewriteTrie
54+
.. autoclass:: KnuthBendix
5555
:class-doc-from: init
5656
:members:
5757
:inherited-members:
5858
:exclude-members:
59-
options, run_for, run_until, run, finished, stopped, current_state, dead, internal_generating_pairs, kill, kind, last_report, report, report_every, report_prefix, report_why_we_stopped, reset_last_report, reset_start_time, running, running_for, running_until, start_time, started, state, stopped_by_predicate, success, timed_out, number_of_generating_pairs
59+
options, run_for, run_until, run, finished, stopped, current_state, dead, internal_generating_pairs, kill, kind, last_report, report, report_every, report_prefix, report_why_we_stopped, reset_last_report, reset_start_time, running, running_for, running_until, start_time, started, state, stopped_by_predicate, success, timed_out

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Knuth-Bendix helpers
1010
====================
1111

1212
This page contains the documentation for various helper functions for
13-
manipulating :any:`KnuthBendixStringRewriteTrie` objects. All such functions are
13+
manipulating :any:`KnuthBendix` objects. All such functions are
1414
contained in the submodule ``libsemigroups_pybind11.knuth_bendix``.
1515

1616
.. seealso::

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
77
.. currentmodule:: libsemigroups_pybind11
88

9-
Converting to a KnuthBendixStringRewriteTrie
9+
Converting to a KnuthBendix
1010
============================================
1111

1212
This page contains documentation relating to converting
13-
``libsemigroups_pybind11`` objects into :any:`KnuthBendixStringRewriteTrie`
13+
``libsemigroups_pybind11`` objects into :any:`KnuthBendix`
1414
instances using the :any:`to` function.
1515

1616
.. seealso::
@@ -23,7 +23,7 @@ Various uses
2323

2424
Recall that the signature for the :any:`to` function is ``to(*args, Return)``.
2525
In what follows, we explain how different values of *args* and *Return* may
26-
be used to construct :any:`KnuthBendixStringRewriteTrie` objects. The following
26+
be used to construct :any:`KnuthBendix` objects. The following
2727
options are possible:
2828

2929
* :ref:`todd-coxeter-to-knuth-bendix-default`;
@@ -32,10 +32,10 @@ options are possible:
3232

3333
.. _todd-coxeter-to-knuth-bendix-default:
3434

35-
Converting a :any:`ToddCoxeterWord` to a :any:`KnuthBendixStringRewriteTrie` (default rewriter)
35+
Converting a :any:`ToddCoxeterWord` to a :any:`KnuthBendix` (default rewriter)
3636
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3737

38-
To construct a :any:`KnuthBendixStringRewriteTrie` from a
38+
To construct a :any:`KnuthBendix` from a
3939
:any:`ToddCoxeterWord` using the default rewriter, specify all of the following
4040
values for *args*:
4141

@@ -46,15 +46,15 @@ values for *args*:
4646

4747
Additionally, specify the following for *Return*:
4848

49-
* ``KnuthBendix`` for constructing a :any:`KnuthBendixStringRewriteTrie`
49+
* ``KnuthBendix`` for constructing a :any:`KnuthBendix`
5050
with the default rewriter.
5151

5252
This function converts a :any:`ToddCoxeterWord` object *tc* to a
53-
:any:`KnuthBendixStringRewriteTrie` object using
53+
:any:`KnuthBendix` object using
5454
:any:`ToddCoxeterWord.presentation`. This is equivalent to specifying
5555
``(KnuthBendix, 'RewriteTrie')`` as described below.
5656

57-
This returned :any:`KnuthBendixStringRewriteTrie` object represents the trivial
57+
This returned :any:`KnuthBendix` object represents the trivial
5858
congruence over the semigroup defined by *tc*.
5959

6060
.. doctest:: Python
@@ -87,10 +87,10 @@ congruence over the semigroup defined by *tc*.
8787

8888
.. _todd-coxeter-to-knuth-bendix:
8989

90-
Converting a :any:`ToddCoxeterWord` to a :any:`KnuthBendixStringRewriteTrie`
90+
Converting a :any:`ToddCoxeterWord` to a :any:`KnuthBendix`
9191
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9292

93-
To construct a :any:`KnuthBendixStringRewriteTrie` from a
93+
To construct a :any:`KnuthBendix` from a
9494
:any:`ToddCoxeterWord`, specify all of the following values for *args*:
9595

9696
* **knd** (:any:`congruence_kind`) -- the kind of the congruence being
@@ -101,17 +101,17 @@ To construct a :any:`KnuthBendixStringRewriteTrie` from a
101101
Additionally, specify one of the following for *Return*:
102102

103103
* ``(KnuthBendix, 'RewriteTrie')`` for constructing a
104-
:any:`KnuthBendixStringRewriteTrie` with the the ``RewriteTrie'``
104+
:any:`KnuthBendix` with the the ``RewriteTrie'``
105105
rewriter.
106106
* ``(KnuthBendix, 'RewriteFromLeft')`` for constructing a
107-
:any:`KnuthBendixStringRewriteTrie` with the the ``RewriteFromLeft'``
107+
:any:`KnuthBendix` with the the ``RewriteFromLeft'``
108108
rewriter.
109109

110110
This function converts a :any:`ToddCoxeterWord` object *tc* to a
111-
:any:`KnuthBendixStringRewriteTrie` object with the rewriter as specified above,
111+
:any:`KnuthBendix` object with the rewriter as specified above,
112112
using :any:`ToddCoxeterWord.presentation`.
113113

114-
This returned :any:`KnuthBendixStringRewriteTrie` object represents the trivial
114+
This returned :any:`KnuthBendix` object represents the trivial
115115
congruence over the semigroup defined by *tc*.
116116

117117
.. doctest:: Python
@@ -144,10 +144,10 @@ congruence over the semigroup defined by *tc*.
144144

145145
.. _froidure-pin-to-knuth-bendix:
146146

147-
Converting a :any:`FroidurePinPBR` to a :any:`KnuthBendixStringRewriteTrie`
147+
Converting a :any:`FroidurePinPBR` to a :any:`KnuthBendix`
148148
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
149149

150-
To construct a :any:`KnuthBendixStringRewriteTrie` from a
150+
To construct a :any:`KnuthBendix` from a
151151
:any:`FroidurePinPBR`, specify all of the following values for *args*:
152152

153153
* **knd** (:any:`congruence_kind`) -- the kind of the congruence being
@@ -158,26 +158,26 @@ To construct a :any:`KnuthBendixStringRewriteTrie` from a
158158
Additionally, specify one of the following for *Return*:
159159

160160
* ``(KnuthBendix, str, 'RewriteTrie')`` for constructing a
161-
:any:`KnuthBendixStringRewriteTrie` on words with type ``str`` using the
161+
:any:`KnuthBendix` on words with type ``str`` using the
162162
``RewriteTrie'`` rewriter.
163163
* ``(KnuthBendix, List[int], 'RewriteTrie')`` for constructing a
164-
:any:`KnuthBendixStringRewriteTrie` on words with type ``List[int]`` using
164+
:any:`KnuthBendix` on words with type ``List[int]`` using
165165
the ``RewriteTrie'`` rewriter.
166166
* ``(KnuthBendix, str, 'RewriteFromLeft')`` for constructing a
167-
:any:`KnuthBendixStringRewriteTrie` on words with type ``str`` using the
167+
:any:`KnuthBendix` on words with type ``str`` using the
168168
``RewriteFromLeft'`` rewriter.
169169
* ``(KnuthBendix, List[int], 'RewriteFromLeft')`` for constructing a
170-
:any:`KnuthBendixStringRewriteTrie` on words with type ``List[int]`` using
170+
:any:`KnuthBendix` on words with type ``List[int]`` using
171171
the ``RewriteFromLeft'`` rewriter.
172172

173173

174174
This function converts a :any:`FroidurePinPBR` object *fpb* to a
175-
:any:`KnuthBendixStringRewriteTrie` object with the word type and rewriter as
175+
:any:`KnuthBendix` object with the word type and rewriter as
176176
specified above. This is done using the presentation obtained from
177177
``to(fpb, Return=(Presentation, Word)`` where ``Word`` is either ``str`` or
178178
``List[int]``.
179179

180-
This returned :any:`KnuthBendixStringRewriteTrie` object represents the trivial
180+
This returned :any:`KnuthBendix` object represents the trivial
181181
congruence over the semigroup defined by *fpb*.
182182

183183
.. doctest:: Python

docs/source/main-algorithms/todd-coxeter/class/common.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Common methods
1111

1212
This page contains documentation of the methods of :any:`ToddCoxeterWord` that
1313
are implemented in all of the classes :any:`Congruence`,
14-
:any:`Kambites`, :any:`KnuthBendixStringRewriteTrie`, and
15-
:any:`ToddCoxeterWord`.
14+
:any:`Kambites`, :any:`KnuthBendix`, and :any:`ToddCoxeterWord`.
1615

1716
.. automethod:: ToddCoxeterWord.add_generating_pair
1817
.. automethod:: ToddCoxeterWord.contains

docs/source/main-algorithms/todd-coxeter/to-todd-coxeter.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,23 @@ This will throw a :any:`LibsemigroupsError` if *wg* is not the
9191

9292
.. _knuth-bendix-to-todd-coxeter:
9393

94-
Converting a :any:`KnuthBendixStringRewriteTrie` to a :any:`ToddCoxeterWord`
94+
Converting a :any:`KnuthBendix` to a :any:`ToddCoxeterWord`
9595
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9696

9797
To construct a :any:`ToddCoxeterWord` from a
98-
:any:`KnuthBendixStringRewriteTrie` specify all of the following values for
98+
:any:`KnuthBendix` specify all of the following values for
9999
*args*:
100100

101101
* **knd** (:any:`congruence_kind`) -- the kind of the congruence being
102102
constructed.
103-
* **kb** (:any:`KnuthBendixStringRewriteTrie`) -- the
104-
:any:`KnuthBendixStringRewriteTrie` object being converted.
103+
* **kb** (:any:`KnuthBendix`) -- the
104+
:any:`KnuthBendix` object being converted.
105105

106106
Additionally, specify the following for *Return*:
107107

108108
* ``ToddCoxeter`` for constructing a :any:`ToddCoxeterWord`.
109109

110-
This function converts the :any:`KnuthBendixStringRewriteTrie` object *kb* into
110+
This function converts the :any:`KnuthBendix` object *kb* into
111111
a :any:`ToddCoxeterWord` object using the right Cayley graph of the semigroup
112112
represented by *kb*.
113113

libsemigroups_pybind11/congruence.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from .detail.decorators import (
3636
may_return_positive_infinity as _may_return_positive_infinity,
3737
copydoc as _copydoc,
38-
returns_self as _returns_self,
3938
)
4039

4140
from .detail import cong_intf
@@ -95,8 +94,7 @@ def get(self: Self, t: type):
9594
9695
:param t:
9796
The type of object being sought (must be
98-
:any:`Kambites`,
99-
:any:`KnuthBendixStringRewriteTrie`, or :any:`ToddCoxeterWord`).
97+
:any:`Kambites`, :any:`KnuthBendix`, or :any:`ToddCoxeterWord`).
10098
:type t: type
10199
102100
:returns: A copy of the instance of type *t*.
@@ -105,7 +103,7 @@ def get(self: Self, t: type):
105103
if there is no object of type *t* within *self*.
106104
"""
107105
if t is _KnuthBendix:
108-
return self._get_knuth_bendix()
106+
return _KnuthBendix(self._get_knuth_bendix())
109107
if t is _ToddCoxeter:
110108
return self._get_todd_coxeter()
111109
if t is _Kambites:
@@ -124,7 +122,7 @@ def has(self: Self, t: type) -> bool:
124122
125123
:param t:
126124
The type of object being sought (must be :any:`Kambites`,
127-
:any:`KnuthBendixStringRewriteTrie`, or :any:`ToddCoxeterWord`).
125+
:any:`KnuthBendix`, or :any:`ToddCoxeterWord`).
128126
:type t: type
129127
130128
:returns: Whether or not there is an object of type *t* in *self*.
@@ -137,20 +135,10 @@ def has(self: Self, t: type) -> bool:
137135
return self._has_kambites()
138136
return False
139137

140-
@_copydoc(_CongruenceWord.add_generating_pair)
141-
@_returns_self
142-
def add_generating_pair(self: Self, *args) -> Self:
143-
return _to_cxx(self).add_generating_pair(*args)
144-
145138
@_copydoc(_CongruenceWord.copy)
146139
def copy(self: Self) -> Self:
147140
return Congruence(_to_cxx(self).copy())
148141

149-
@_copydoc(_CongruenceWord.init)
150-
@_returns_self
151-
def init(self: Self, *args) -> Self:
152-
return _to_cxx(self).init(*args)
153-
154142
@_copydoc(_CongruenceWord._number_of_classes)
155143
@_may_return_positive_infinity
156144
def number_of_classes(self: Self) -> int:

libsemigroups_pybind11/detail/cxx_wrapper.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ def __getattr__(self: Self, meth_name: str):
9595
def cxx_fn_wrapper(*args) -> Any:
9696
if len(args) == 1 and isinstance(args[0], list):
9797
args = args[0]
98-
return getattr(self._cxx_obj, meth_name)(
99-
[to_cxx(x) for x in args]
100-
)
98+
return getattr(self._cxx_obj, meth_name)([to_cxx(x) for x in args])
10199
return getattr(self._cxx_obj, meth_name)(*(to_cxx(x) for x in args))
102100

103101
return cxx_fn_wrapper
@@ -158,9 +156,10 @@ def _cxx_obj_type_from(self: Self, samples=(), types=()) -> Any:
158156
# TODO proper annotations
159157
def wrap_cxx_mem_fn(cxx_mem_fn: pybind11_type) -> Callable:
160158
def cxx_mem_fn_wrapper(self, *args):
161-
return getattr(self._cxx_obj, cxx_mem_fn.__name__)(
162-
*(to_cxx(x) for x in args)
163-
)
159+
result = getattr(self._cxx_obj, cxx_mem_fn.__name__)(*(to_cxx(x) for x in args))
160+
if isinstance(result, type(self._cxx_obj)):
161+
return self
162+
return result
164163

165164
update_wrapper(cxx_mem_fn_wrapper, cxx_mem_fn)
166165
return cxx_mem_fn_wrapper
@@ -181,9 +180,7 @@ def copy_cxx_mem_fns(cxx_class: pybind11_type, py_class: CxxWrapper) -> None:
181180
that call the cxx member function on the _cxx_obj.
182181
"""
183182
for py_meth_name in dir(cxx_class):
184-
if not py_meth_name.startswith("_") and py_meth_name not in dir(
185-
py_class
186-
):
183+
if not py_meth_name.startswith("_") and py_meth_name not in dir(py_class):
187184
setattr(
188185
py_class,
189186
py_meth_name,

0 commit comments

Comments
 (0)