Skip to content

Commit 7ee5436

Browse files
james-d-mitchellJoseph-Edwards
authored andcommitted
to function: add support for reduction order
1 parent 14374c8 commit 7ee5436

11 files changed

Lines changed: 206 additions & 49 deletions

File tree

src/froidure-pin.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,15 @@ This function returns the element of *fp* obtained by evaluating *w*.
13161316
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<word_type, LenLexTrie>>>(
13171317
m, "KBEWordLenLexTrie");
13181318

1319+
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<std::string, RPOSet>>>(
1320+
m, "KBEStringRPOSet");
1321+
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<std::string, RPOTrie>>>(
1322+
m, "KBEStringRPOTrie");
1323+
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<word_type, RPOSet>>>(
1324+
m, "KBEWordRPOSet");
1325+
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<word_type, RPOTrie>>>(
1326+
m, "KBEWordRPOTrie");
1327+
13191328
bind_froidure_pin_stateful<detail::KE<std::string>>(m, "KEString");
13201329
bind_froidure_pin_stateful<detail::KE<detail::MultiView<std::string>>>(
13211330
m, "KEMultiViewString");

src/kbe.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ namespace libsemigroups {
7878
using RPOTrie = detail::RewritingSystemTrie<RecursivePathCompare>;
7979
using RPOSet = detail::RewritingSystemSet<RecursivePathCompare>;
8080

81+
// LenLex
8182
using KBEStringLenLexTrie
8283
= detail::KBE<KnuthBendix<std::string, LenLexTrie>>;
8384
using KBEWordLenLexTrie = detail::KBE<KnuthBendix<word_type, LenLexTrie>>;
@@ -88,5 +89,16 @@ namespace libsemigroups {
8889
bind_kbe<KBEWordLenLexTrie>(m, "KBEWordLenLexTrie");
8990
bind_kbe<KBEStringLenLexSet>(m, "KBEStringLenLexSet");
9091
bind_kbe<KBEWordLenLexSet>(m, "KBEWordLenLexSet");
92+
93+
// RPO
94+
using KBEStringRPOTrie = detail::KBE<KnuthBendix<std::string, RPOTrie>>;
95+
using KBEWordRPOTrie = detail::KBE<KnuthBendix<word_type, RPOTrie>>;
96+
using KBEStringRPOSet = detail::KBE<KnuthBendix<std::string, RPOSet>>;
97+
using KBEWordRPOSet = detail::KBE<KnuthBendix<word_type, RPOSet>>;
98+
99+
bind_kbe<KBEStringRPOTrie>(m, "KBEStringRPOTrie");
100+
bind_kbe<KBEWordRPOTrie>(m, "KBEWordRPOTrie");
101+
bind_kbe<KBEStringRPOSet>(m, "KBEStringRPOSet");
102+
bind_kbe<KBEWordRPOSet>(m, "KBEWordRPOSet");
91103
}
92104
} // namespace libsemigroups

src/libsemigroups_pybind11/froidure_pin.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@
2828
FroidurePinIntMat as _FroidurePinIntMat,
2929
FroidurePinKBEStringLenLexSet as _FroidurePinKBEStringLenLexSet,
3030
FroidurePinKBEStringLenLexTrie as _FroidurePinKBEStringLenLexTrie,
31+
FroidurePinKBEStringRPOSet as _FroidurePinKBEStringRPOSet,
32+
FroidurePinKBEStringRPOTrie as _FroidurePinKBEStringRPOTrie,
3133
FroidurePinKBEWordLenLexSet as _FroidurePinKBEWordLenLexSet,
3234
FroidurePinKBEWordLenLexTrie as _FroidurePinKBEWordLenLexTrie,
35+
FroidurePinKBEWordRPOSet as _FroidurePinKBEWordRPOSet,
36+
FroidurePinKBEWordRPOTrie as _FroidurePinKBEWordRPOTrie,
3337
FroidurePinKEMultiViewString as _FroidurePinKEMultiViewString,
3438
FroidurePinKEString as _FroidurePinKEString,
3539
FroidurePinKEWord as _FroidurePinKEWord,
@@ -53,8 +57,12 @@
5357
IntMat as _IntMat,
5458
KBEStringLenLexSet as _KBEStringLenLexSet,
5559
KBEStringLenLexTrie as _KBEStringLenLexTrie,
60+
KBEStringRPOSet as _KBEStringRPOSet,
61+
KBEStringRPOTrie as _KBEStringRPOTrie,
5662
KBEWordLenLexSet as _KBEWordLenLexSet,
5763
KBEWordLenLexTrie as _KBEWordLenLexTrie,
64+
KBEWordRPOSet as _KBEWordRPOSet,
65+
KBEWordRPOTrie as _KBEWordRPOTrie,
5866
MaxPlusMat as _MaxPlusMat,
5967
MaxPlusTruncMat as _MaxPlusTruncMat,
6068
MinPlusMat as _MinPlusMat,
@@ -149,6 +157,10 @@ class FroidurePin(_CxxWrapper):
149157
(_KBEStringLenLexSet,): _FroidurePinKBEStringLenLexSet,
150158
(_KBEWordLenLexTrie,): _FroidurePinKBEWordLenLexTrie,
151159
(_KBEWordLenLexSet,): _FroidurePinKBEWordLenLexSet,
160+
(_KBEStringRPOTrie,): _FroidurePinKBEStringRPOTrie,
161+
(_KBEStringRPOSet,): _FroidurePinKBEStringRPOSet,
162+
(_KBEWordRPOTrie,): _FroidurePinKBEWordRPOTrie,
163+
(_KBEWordRPOSet,): _FroidurePinKBEWordRPOSet,
152164
} | (
153165
{
154166
(_HPCombiPTransf16,): _FroidurePinHPCombiPTransf16,

src/libsemigroups_pybind11/knuth_bendix.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
from _libsemigroups_pybind11 import (
1515
KnuthBendixStringLenLexSet as _KnuthBendixStringLenLexSet,
1616
KnuthBendixStringLenLexTrie as _KnuthBendixStringLenLexTrie,
17-
KnuthBendixWordLenLexSet as _KnuthBendixWordLenLexSet,
18-
KnuthBendixWordLenLexTrie as _KnuthBendixWordLenLexTrie,
1917
KnuthBendixStringRPOSet as _KnuthBendixStringRPOSet,
2018
KnuthBendixStringRPOTrie as _KnuthBendixStringRPOTrie,
19+
KnuthBendixWordLenLexSet as _KnuthBendixWordLenLexSet,
20+
KnuthBendixWordLenLexTrie as _KnuthBendixWordLenLexTrie,
2121
KnuthBendixWordRPOSet as _KnuthBendixWordRPOSet,
2222
KnuthBendixWordRPOTrie as _KnuthBendixWordRPOTrie,
2323
Order as _Order,
@@ -84,8 +84,9 @@ def __init__(self, *args, rewriting_system="Trie", order=_Order.shortlex, **kwar
8484
2,
8585
)
8686
if kwargs["rewriter"] not in ("RewriteFromLeft", "RewriteTrie"):
87+
rewriter = kwargs["rewriter"]
8788
raise TypeError(
88-
f'expected the keyword argument "rewriter" to be '
89+
'expected the keyword argument "rewriter" to be '
8990
f'"RewriteFromLeft" or "RewriteTrie", but found "{rewriter}"'
9091
)
9192
if kwargs["rewriter"] == "RewriteFromLeft":

src/libsemigroups_pybind11/to.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from typing import _GenericAlias
1212

1313
from _libsemigroups_pybind11 import (
14+
Order as _Order,
1415
to_congruence_string as _to_congruence_string,
1516
to_congruence_word as _to_congruence_word,
1617
to_froidure_pin as _to_froidure_pin,
@@ -20,10 +21,16 @@
2021
to_knuth_bendix as _to_knuth_bendix,
2122
to_knuth_bendix_LenLexSet as _to_knuth_bendix_LenLexSet,
2223
to_knuth_bendix_LenLexTrie as _to_knuth_bendix_LenLexTrie,
24+
to_knuth_bendix_RPOSet as _to_knuth_bendix_RPOSet,
25+
to_knuth_bendix_RPOTrie as _to_knuth_bendix_RPOTrie,
2326
to_knuth_bendix_string_LenLexSet as _to_knuth_bendix_string_LenLexSet,
2427
to_knuth_bendix_string_LenLexTrie as _to_knuth_bendix_string_LenLexTrie,
28+
to_knuth_bendix_string_RPOSet as _to_knuth_bendix_string_RPOSet,
29+
to_knuth_bendix_string_RPOTrie as _to_knuth_bendix_string_RPOTrie,
2530
to_knuth_bendix_word_LenLexSet as _to_knuth_bendix_word_LenLexSet,
2631
to_knuth_bendix_word_LenLexTrie as _to_knuth_bendix_word_LenLexTrie,
32+
to_knuth_bendix_word_RPOSet as _to_knuth_bendix_word_RPOSet,
33+
to_knuth_bendix_word_RPOTrie as _to_knuth_bendix_word_RPOTrie,
2734
to_presentation as _to_presentation,
2835
to_presentation_string as _to_presentation_string,
2936
to_presentation_word as _to_presentation_word,
@@ -69,12 +76,18 @@ def _nice_name(type_list):
6976
(_InversePresentation, list[int]): _to_inverse_presentation_word,
7077
(_InversePresentation, str): _to_inverse_presentation_string,
7178
(_KnuthBendix,): _to_knuth_bendix,
72-
(_KnuthBendix, "LenLexTrie"): _to_knuth_bendix_LenLexTrie,
73-
(_KnuthBendix, "LenLexSet"): _to_knuth_bendix_LenLexSet,
74-
(_KnuthBendix, list[int], "LenLexSet"): _to_knuth_bendix_word_LenLexSet,
75-
(_KnuthBendix, list[int], "LenLexTrie"): _to_knuth_bendix_word_LenLexTrie,
76-
(_KnuthBendix, str, "LenLexSet"): _to_knuth_bendix_string_LenLexSet,
77-
(_KnuthBendix, str, "LenLexTrie"): _to_knuth_bendix_string_LenLexTrie,
79+
(_KnuthBendix, "Set", _Order.shortlex): _to_knuth_bendix_LenLexSet,
80+
(_KnuthBendix, "Trie", _Order.shortlex): _to_knuth_bendix_LenLexTrie,
81+
(_KnuthBendix, list[int], "Set", _Order.shortlex): _to_knuth_bendix_word_LenLexSet,
82+
(_KnuthBendix, list[int], "Trie", _Order.shortlex): _to_knuth_bendix_word_LenLexTrie,
83+
(_KnuthBendix, str, "Set", _Order.shortlex): _to_knuth_bendix_string_LenLexSet,
84+
(_KnuthBendix, str, "Trie", _Order.shortlex): _to_knuth_bendix_string_LenLexTrie,
85+
(_KnuthBendix, "Set", _Order.recursive): _to_knuth_bendix_RPOSet,
86+
(_KnuthBendix, "Trie", _Order.recursive): _to_knuth_bendix_RPOTrie,
87+
(_KnuthBendix, list[int], "Set", _Order.recursive): _to_knuth_bendix_word_RPOSet,
88+
(_KnuthBendix, list[int], "Trie", _Order.recursive): _to_knuth_bendix_word_RPOTrie,
89+
(_KnuthBendix, str, "Set", _Order.recursive): _to_knuth_bendix_string_RPOSet,
90+
(_KnuthBendix, str, "Trie", _Order.recursive): _to_knuth_bendix_string_RPOTrie,
7891
(_Presentation,): _to_presentation,
7992
(_Presentation, str): _to_presentation_string,
8093
(_Presentation, list[int]): _to_presentation_word,

src/to-froidure-pin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ namespace libsemigroups {
7272
bind_to_froidure_pin<KnuthBendix<word_type, LenLexSet>>(m);
7373
bind_to_froidure_pin<KnuthBendix<word_type, LenLexTrie>>(m);
7474

75+
bind_to_froidure_pin<KnuthBendix<std::string, RPOSet>>(m);
76+
bind_to_froidure_pin<KnuthBendix<std::string, RPOTrie>>(m);
77+
bind_to_froidure_pin<KnuthBendix<word_type, RPOSet>>(m);
78+
bind_to_froidure_pin<KnuthBendix<word_type, RPOTrie>>(m);
79+
7580
// ToddCoxeter
7681
bind_to_froidure_pin<ToddCoxeter<std::string>>(m);
7782
bind_to_froidure_pin<ToddCoxeter<word_type>>(m);

src/to-knuth-bendix.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,21 @@ namespace libsemigroups {
7979
"word_LenLexSet");
8080
bind_froidure_pin_to_knuth_bendix<word_type, LenLexTrie>(m,
8181
"word_LenLexTrie");
82+
bind_froidure_pin_to_knuth_bendix<std::string, RPOSet>(m, "string_RPOSet");
83+
bind_froidure_pin_to_knuth_bendix<std::string, RPOTrie>(m,
84+
"string_RPOTrie");
85+
bind_froidure_pin_to_knuth_bendix<word_type, RPOSet>(m, "word_RPOSet");
86+
bind_froidure_pin_to_knuth_bendix<word_type, RPOTrie>(m, "word_RPOTrie");
8287

8388
// ToddCoxeter + rewriter
8489
bind_todd_coxeter_to_knuth_bendix<std::string, LenLexSet>(m, "LenLexSet");
8590
bind_todd_coxeter_to_knuth_bendix<word_type, LenLexSet>(m, "LenLexSet");
8691
bind_todd_coxeter_to_knuth_bendix<std::string, LenLexTrie>(m, "LenLexTrie");
8792
bind_todd_coxeter_to_knuth_bendix<word_type, LenLexTrie>(m, "LenLexTrie");
93+
bind_todd_coxeter_to_knuth_bendix<std::string, RPOSet>(m, "RPOSet");
94+
bind_todd_coxeter_to_knuth_bendix<word_type, RPOSet>(m, "RPOSet");
95+
bind_todd_coxeter_to_knuth_bendix<std::string, RPOTrie>(m, "RPOTrie");
96+
bind_todd_coxeter_to_knuth_bendix<word_type, RPOTrie>(m, "RPOTrie");
8897

8998
// ToddCoxeter
9099
bind_todd_coxeter_to_knuth_bendix_default<std::string>(m);

src/to-presentation.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ namespace libsemigroups {
227227
bind_kb_to_pres_with_word<word_type, word_type, LenLexSet>(m, "word");
228228
bind_kb_to_pres_with_word<word_type, word_type, LenLexTrie>(m, "word");
229229

230+
bind_kb_to_pres<std::string, RPOSet>(m);
231+
bind_kb_to_pres<std::string, RPOTrie>(m);
232+
bind_kb_to_pres<word_type, RPOSet>(m);
233+
bind_kb_to_pres<word_type, RPOTrie>(m);
234+
235+
bind_kb_to_pres_with_word<std::string, std::string, RPOSet>(m, "string");
236+
bind_kb_to_pres_with_word<std::string, std::string, RPOTrie>(m, "string");
237+
bind_kb_to_pres_with_word<word_type, std::string, RPOSet>(m, "string");
238+
bind_kb_to_pres_with_word<word_type, std::string, RPOTrie>(m, "string");
239+
bind_kb_to_pres_with_word<std::string, word_type, RPOSet>(m, "word");
240+
bind_kb_to_pres_with_word<std::string, word_type, RPOTrie>(m, "word");
241+
bind_kb_to_pres_with_word<word_type, word_type, RPOSet>(m, "word");
242+
bind_kb_to_pres_with_word<word_type, word_type, RPOTrie>(m, "word");
243+
230244
// From FroidurePin
231245
bind_fp_to_pres<std::string>(m, "string");
232246
bind_fp_to_pres<word_type>(m, "word");

src/to-todd-coxeter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ namespace libsemigroups {
6262
bind_to_todd_coxeter_kb<word_type, LenLexSet>(m);
6363
bind_to_todd_coxeter_kb<word_type, LenLexTrie>(m);
6464

65+
bind_to_todd_coxeter_kb<std::string, RPOSet>(m);
66+
bind_to_todd_coxeter_kb<std::string, RPOTrie>(m);
67+
bind_to_todd_coxeter_kb<word_type, RPOSet>(m);
68+
bind_to_todd_coxeter_kb<word_type, RPOTrie>(m);
69+
6570
// WordGraph
6671
m.def("to_todd_coxeter_word",
6772
[](congruence_kind knd,

tests/test_knuth_bendix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
from _libsemigroups_pybind11 import Runner
1616
from libsemigroups_pybind11 import (
17-
KnuthBendix,
1817
LIMIT_MAX,
18+
POSITIVE_INFINITY,
19+
KnuthBendix,
1920
LibsemigroupsError,
2021
Order,
21-
POSITIVE_INFINITY,
2222
Presentation,
2323
ReportGuard,
2424
StringRange,

0 commit comments

Comments
 (0)