From 28ba9923313d3891b4c7befd4021b04b6697b8ac Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Mon, 8 Jun 2026 08:52:08 +0100 Subject: [PATCH 1/6] Remove deprecated test --- tests/test_knuth_bendix.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_knuth_bendix.py b/tests/test_knuth_bendix.py index 89fdfc250..155bcec31 100644 --- a/tests/test_knuth_bendix.py +++ b/tests/test_knuth_bendix.py @@ -93,7 +93,6 @@ def test_attributes(): ] ) assert kb.max_pending_rules() == 128 - assert kb.check_confluence_interval() == 4096 assert kb.max_overlap() == POSITIVE_INFINITY assert kb.max_rules() == POSITIVE_INFINITY assert kb.overlap_policy() == kb.options.overlap.ABC From 07f621920b27b14dc04f6c867c2911053669ab3c Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Mon, 8 Jun 2026 09:23:26 +0100 Subject: [PATCH 2/6] to-knuth-bendix: rewriters.hpp -> rewriting-system.hpp --- src/to-knuth-bendix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/to-knuth-bendix.cpp b/src/to-knuth-bendix.cpp index 3297aed91..fb04a408a 100644 --- a/src/to-knuth-bendix.cpp +++ b/src/to-knuth-bendix.cpp @@ -26,7 +26,7 @@ #include // for ToddCoxeter #include // for word_type -#include // for detail::RewriteTrie +#include // for detail::RewriteTrie // pybind11.... #include From f8d8ebc27aaec63a34174ab450108e3a41180717 Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Mon, 8 Jun 2026 12:32:17 +0100 Subject: [PATCH 3/6] Rename things from upstream --- build_tools/__init__.py | 1 + src/cong-common.cpp | 264 ++++++++++----------- src/froidure-pin.cpp | 25 +- src/kbe.cpp | 28 ++- src/knuth-bendix-impl.cpp | 13 +- src/knuth-bendix.cpp | 41 ++-- src/libsemigroups_pybind11/froidure_pin.py | 24 +- src/libsemigroups_pybind11/knuth_bendix.py | 42 ++-- src/libsemigroups_pybind11/to.py | 24 +- src/to-froidure-pin.cpp | 13 +- src/to-knuth-bendix.cpp | 35 ++- src/to-presentation.cpp | 41 ++-- src/to-todd-coxeter.cpp | 13 +- tests/test_knuth_bendix.py | 6 +- tests/test_to.py | 70 +++--- 15 files changed, 324 insertions(+), 316 deletions(-) diff --git a/build_tools/__init__.py b/build_tools/__init__.py index 2732eb1c0..3babec7da 100644 --- a/build_tools/__init__.py +++ b/build_tools/__init__.py @@ -11,4 +11,5 @@ def minimum_libsemigroups_version(): """Returns the minimum required version of libsemigroups required to build libsemigroups_pybind11. """ + # TODO update to 3.7 return "3.6.1" diff --git a/src/cong-common.cpp b/src/cong-common.cpp index b74f593fe..ed493a20f 100644 --- a/src/cong-common.cpp +++ b/src/cong-common.cpp @@ -40,19 +40,19 @@ namespace libsemigroups { namespace py = pybind11; - using RewriteTrie = detail::RewriteTrie; - using RewriteFromLeft = detail::RewriteFromLeft; + using LenLexTrie = detail::RewritingSystemTrie; + using LenLexSet = detail::RewritingSystemSet; + using RPOTrie = detail::RewritingSystemTrie; + using RPOSet = detail::RewritingSystemSet; template using MultiView = detail::MultiView; // Alias required because macros don't play well with commas. - using KnuthBendixStringRewriteTrie = KnuthBendix; - using KnuthBendixStringRewriteFromLeft - = KnuthBendix; - using KnuthBendixWordRewriteTrie = KnuthBendix; - using KnuthBendixWordRewriteFromLeft - = KnuthBendix; + using KnuthBendixStringLenLexTrie = KnuthBendix; + using KnuthBendixStringLenLexSet = KnuthBendix; + using KnuthBendixWordLenLexTrie = KnuthBendix; + using KnuthBendixWordLenLexSet = KnuthBendix; //////////////////////////////////////////////////////////////////////// // Implementation helpers @@ -128,19 +128,19 @@ This function default constructs an uninitialised :any:`{name}` instance. detail::CongruenceCommon); DEF_CONSTRUCT_DEFAULT(Kambites, detail::CongruenceCommon); - DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl, + DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl, + DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_CONSTRUCT_DEFAULT(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_CONSTRUCT_DEFAULT(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_CONSTRUCT_DEFAULT(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_CONSTRUCT_DEFAULT(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_CONSTRUCT_DEFAULT(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_DEFAULT(KnuthBendixStringLenLexSet, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_DEFAULT(KnuthBendixWordLenLexTrie, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_DEFAULT(KnuthBendixWordLenLexSet, + detail::KnuthBendixImpl); DEF_CONSTRUCT_DEFAULT(Congruence, detail::CongruenceCommon); DEF_CONSTRUCT_DEFAULT(Congruence, detail::CongruenceCommon); @@ -188,19 +188,19 @@ have been in if it had just been newly default constructed. DEF_INIT_DEFAULT(Kambites>, detail::CongruenceCommon); DEF_INIT_DEFAULT(Kambites, detail::CongruenceCommon); - DEF_INIT_DEFAULT(detail::KnuthBendixImpl, + DEF_INIT_DEFAULT(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_INIT_DEFAULT(detail::KnuthBendixImpl, + DEF_INIT_DEFAULT(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_INIT_DEFAULT(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_INIT_DEFAULT(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_INIT_DEFAULT(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_INIT_DEFAULT(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_INIT_DEFAULT(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_INIT_DEFAULT(KnuthBendixStringLenLexSet, + detail::KnuthBendixImpl); + DEF_INIT_DEFAULT(KnuthBendixWordLenLexTrie, + detail::KnuthBendixImpl); + DEF_INIT_DEFAULT(KnuthBendixWordLenLexSet, + detail::KnuthBendixImpl); DEF_INIT_DEFAULT(Congruence, detail::CongruenceCommon); DEF_INIT_DEFAULT(Congruence, detail::CongruenceCommon); @@ -262,19 +262,19 @@ of kind *knd* over the semigroup or monoid defined by the presentation *p*. DEF_CONSTRUCT_KIND_PRESENTATION(Kambites, detail::CongruenceCommon); - DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl, + DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl, + DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringLenLexSet, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordLenLexTrie, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordLenLexSet, + detail::KnuthBendixImpl); DEF_CONSTRUCT_KIND_PRESENTATION(Congruence, detail::CongruenceCommon); @@ -339,19 +339,19 @@ had been newly constructed from *knd* and *p*. detail::CongruenceCommon); DEF_INIT_KIND_PRESENTATION(Kambites, detail::CongruenceCommon); - DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl, + DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl, + DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_INIT_KIND_PRESENTATION(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_INIT_KIND_PRESENTATION(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_INIT_KIND_PRESENTATION(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_INIT_KIND_PRESENTATION(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_INIT_KIND_PRESENTATION(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_INIT_KIND_PRESENTATION(KnuthBendixStringLenLexSet, + detail::KnuthBendixImpl); + DEF_INIT_KIND_PRESENTATION(KnuthBendixWordLenLexTrie, + detail::KnuthBendixImpl); + DEF_INIT_KIND_PRESENTATION(KnuthBendixWordLenLexSet, + detail::KnuthBendixImpl); DEF_INIT_KIND_PRESENTATION(Congruence, detail::CongruenceCommon); DEF_INIT_KIND_PRESENTATION(Congruence, detail::CongruenceCommon); @@ -396,15 +396,13 @@ Copy a :any:`{name}` object. DEF_COPY(Kambites>, detail::CongruenceCommon); DEF_COPY(Kambites, detail::CongruenceCommon); - DEF_COPY(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_COPY(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_COPY(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_COPY(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_COPY(KnuthBendixStringRewriteTrie, detail::KnuthBendixImpl); - DEF_COPY(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_COPY(KnuthBendixWordRewriteTrie, detail::KnuthBendixImpl); - DEF_COPY(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixStringLenLexTrie, detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixStringLenLexSet, detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); DEF_COPY(Congruence, detail::CongruenceCommon); DEF_COPY(Congruence, detail::CongruenceCommon); @@ -457,9 +455,9 @@ number of classes in the congruence represented by a :any:`{name}` instance. detail::CongruenceCommon); DEF_NUMBER_OF_CLASSES(Kambites, detail::CongruenceCommon); - DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl, + DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl, + DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl, detail::CongruenceCommon); DEF_NUMBER_OF_CLASSES(Congruence, detail::CongruenceCommon); @@ -531,19 +529,19 @@ This function adds a generating pair to the congruence represented by a detail::CongruenceCommon); DEF_ADD_GENERATING_PAIR(Kambites, detail::CongruenceCommon); - DEF_ADD_GENERATING_PAIR(detail::KnuthBendixImpl, + DEF_ADD_GENERATING_PAIR(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_ADD_GENERATING_PAIR(detail::KnuthBendixImpl, + DEF_ADD_GENERATING_PAIR(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_ADD_GENERATING_PAIR(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_ADD_GENERATING_PAIR(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_ADD_GENERATING_PAIR(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_ADD_GENERATING_PAIR(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_ADD_GENERATING_PAIR(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_ADD_GENERATING_PAIR(KnuthBendixStringLenLexSet, + detail::KnuthBendixImpl); + DEF_ADD_GENERATING_PAIR(KnuthBendixWordLenLexTrie, + detail::KnuthBendixImpl); + DEF_ADD_GENERATING_PAIR(KnuthBendixWordLenLexSet, + detail::KnuthBendixImpl); DEF_ADD_GENERATING_PAIR(Congruence, detail::CongruenceCommon); DEF_ADD_GENERATING_PAIR(Congruence, detail::CongruenceCommon); @@ -614,19 +612,19 @@ contained in the congruence, but that this is not currently known. detail::CongruenceCommon); DEF_CURRENTLY_CONTAINS(Kambites, detail::CongruenceCommon); - DEF_CURRENTLY_CONTAINS(detail::KnuthBendixImpl, + DEF_CURRENTLY_CONTAINS(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_CURRENTLY_CONTAINS(detail::KnuthBendixImpl, + DEF_CURRENTLY_CONTAINS(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_CURRENTLY_CONTAINS(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_CURRENTLY_CONTAINS(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_CURRENTLY_CONTAINS(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_CURRENTLY_CONTAINS(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_CURRENTLY_CONTAINS(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_CURRENTLY_CONTAINS(KnuthBendixStringLenLexSet, + detail::KnuthBendixImpl); + DEF_CURRENTLY_CONTAINS(KnuthBendixWordLenLexTrie, + detail::KnuthBendixImpl); + DEF_CURRENTLY_CONTAINS(KnuthBendixWordLenLexSet, + detail::KnuthBendixImpl); DEF_CURRENTLY_CONTAINS(Congruence, detail::CongruenceCommon); DEF_CURRENTLY_CONTAINS(Congruence, detail::CongruenceCommon); @@ -690,18 +688,14 @@ congruence represented by a :py:class:`{name}` instance. DEF_CONTAINS(Kambites>, detail::CongruenceCommon); DEF_CONTAINS(Kambites, detail::CongruenceCommon); - DEF_CONTAINS(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_CONTAINS(detail::KnuthBendixImpl, - detail::CongruenceCommon); + DEF_CONTAINS(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_CONTAINS(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_CONTAINS(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_CONTAINS(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_CONTAINS(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_CONTAINS(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixStringLenLexSet, detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); DEF_CONTAINS(Congruence, detail::CongruenceCommon); DEF_CONTAINS(Congruence, detail::CongruenceCommon); @@ -762,19 +756,19 @@ normal form for the input word *w*. DEF_REDUCE_NO_RUN(Kambites>, detail::CongruenceCommon); DEF_REDUCE_NO_RUN(Kambites, detail::CongruenceCommon); - DEF_REDUCE_NO_RUN(detail::KnuthBendixImpl, + DEF_REDUCE_NO_RUN(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_REDUCE_NO_RUN(detail::KnuthBendixImpl, + DEF_REDUCE_NO_RUN(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_REDUCE_NO_RUN(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_REDUCE_NO_RUN(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_REDUCE_NO_RUN(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_REDUCE_NO_RUN(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_REDUCE_NO_RUN(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_REDUCE_NO_RUN(KnuthBendixStringLenLexSet, + detail::KnuthBendixImpl); + DEF_REDUCE_NO_RUN(KnuthBendixWordLenLexTrie, + detail::KnuthBendixImpl); + DEF_REDUCE_NO_RUN(KnuthBendixWordLenLexSet, + detail::KnuthBendixImpl); DEF_REDUCE_NO_RUN(Congruence, detail::CongruenceCommon); DEF_REDUCE_NO_RUN(Congruence, detail::CongruenceCommon); @@ -836,17 +830,13 @@ input word. DEF_REDUCE(Kambites>, detail::CongruenceCommon); DEF_REDUCE(Kambites, detail::CongruenceCommon); - DEF_REDUCE(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_REDUCE(detail::KnuthBendixImpl, - detail::CongruenceCommon); + DEF_REDUCE(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_REDUCE(detail::KnuthBendixImpl, detail::CongruenceCommon); - DEF_REDUCE(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_REDUCE(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_REDUCE(KnuthBendixWordRewriteTrie, detail::KnuthBendixImpl); - DEF_REDUCE(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixStringLenLexTrie, detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixStringLenLexSet, detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); DEF_REDUCE(Congruence, detail::CongruenceCommon); DEF_REDUCE(Congruence, detail::CongruenceCommon); @@ -897,14 +887,14 @@ This function returns the generating pairs of the congruence as added via detail::CongruenceCommon); DEF_GENERATING_PAIRS(Kambites, detail::CongruenceCommon); - DEF_GENERATING_PAIRS(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_GENERATING_PAIRS(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_GENERATING_PAIRS(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_GENERATING_PAIRS(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_GENERATING_PAIRS(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_GENERATING_PAIRS(KnuthBendixStringLenLexSet, + detail::KnuthBendixImpl); + DEF_GENERATING_PAIRS(KnuthBendixWordLenLexTrie, + detail::KnuthBendixImpl); + DEF_GENERATING_PAIRS(KnuthBendixWordLenLexSet, + detail::KnuthBendixImpl); DEF_GENERATING_PAIRS(Congruence, detail::CongruenceCommon); DEF_GENERATING_PAIRS(Congruence, detail::CongruenceCommon); @@ -956,14 +946,14 @@ presentation, then this presentation is returned by this function. DEF_PRESENTATION(Kambites>, detail::CongruenceCommon); DEF_PRESENTATION(Kambites, detail::CongruenceCommon); - DEF_PRESENTATION(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_PRESENTATION(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_PRESENTATION(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_PRESENTATION(KnuthBendixWordRewriteFromLeft, - detail::KnuthBendixImpl); + DEF_PRESENTATION(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_PRESENTATION(KnuthBendixStringLenLexSet, + detail::KnuthBendixImpl); + DEF_PRESENTATION(KnuthBendixWordLenLexTrie, + detail::KnuthBendixImpl); + DEF_PRESENTATION(KnuthBendixWordLenLexSet, + detail::KnuthBendixImpl); DEF_PRESENTATION(Congruence, detail::CongruenceCommon); DEF_PRESENTATION(Congruence, detail::CongruenceCommon); @@ -1028,10 +1018,10 @@ triggers a full enumeration of *{var}*. DEF_PARTITION(Kambites>); DEF_PARTITION(Kambites); - DEF_PARTITION(KnuthBendixStringRewriteTrie); - DEF_PARTITION(KnuthBendixStringRewriteFromLeft); - DEF_PARTITION(KnuthBendixWordRewriteTrie); - DEF_PARTITION(KnuthBendixWordRewriteFromLeft); + DEF_PARTITION(KnuthBendixStringLenLexTrie); + DEF_PARTITION(KnuthBendixStringLenLexSet); + DEF_PARTITION(KnuthBendixWordLenLexTrie); + DEF_PARTITION(KnuthBendixWordLenLexSet); DEF_PARTITION(Congruence); DEF_PARTITION(Congruence); @@ -1095,10 +1085,10 @@ instance *{var}*. DEF_NON_TRIVIAL_CLASSES(Kambites>); DEF_NON_TRIVIAL_CLASSES(Kambites); - DEF_NON_TRIVIAL_CLASSES(KnuthBendixStringRewriteTrie); - DEF_NON_TRIVIAL_CLASSES(KnuthBendixStringRewriteFromLeft); - DEF_NON_TRIVIAL_CLASSES(KnuthBendixWordRewriteTrie); - DEF_NON_TRIVIAL_CLASSES(KnuthBendixWordRewriteFromLeft); + DEF_NON_TRIVIAL_CLASSES(KnuthBendixStringLenLexTrie); + DEF_NON_TRIVIAL_CLASSES(KnuthBendixStringLenLexSet); + DEF_NON_TRIVIAL_CLASSES(KnuthBendixWordLenLexTrie); + DEF_NON_TRIVIAL_CLASSES(KnuthBendixWordLenLexSet); DEF_NON_TRIVIAL_CLASSES(Congruence); DEF_NON_TRIVIAL_CLASSES(Congruence); @@ -1158,10 +1148,10 @@ the congruence represented by an instance of :any:`{name}`. DEF_NORMAL_FORMS(Kambites>); DEF_NORMAL_FORMS(Kambites); - DEF_NORMAL_FORMS(KnuthBendixStringRewriteTrie); - DEF_NORMAL_FORMS(KnuthBendixStringRewriteFromLeft); - DEF_NORMAL_FORMS(KnuthBendixWordRewriteTrie); - DEF_NORMAL_FORMS(KnuthBendixWordRewriteFromLeft); + DEF_NORMAL_FORMS(KnuthBendixStringLenLexTrie); + DEF_NORMAL_FORMS(KnuthBendixStringLenLexSet); + DEF_NORMAL_FORMS(KnuthBendixWordLenLexTrie); + DEF_NORMAL_FORMS(KnuthBendixWordLenLexSet); // TODO(1) uncomment when implemented in libsemigroups // DEF_NORMAL_FORMS(Congruence); diff --git a/src/froidure-pin.cpp b/src/froidure-pin.cpp index bd61e0f12..0dbbb3560 100644 --- a/src/froidure-pin.cpp +++ b/src/froidure-pin.cpp @@ -1269,9 +1269,14 @@ This function returns the element of *fp* obtained by evaluating *w*. }); } } // bind_froidure_pin_stateful - } // namespace + } // namespace void init_froidure_pin(py::module& m) { + using LenLexTrie = detail::RewritingSystemTrie; + using LenLexSet = detail::RewritingSystemSet; + using RPOTrie = detail::RewritingSystemTrie; + using RPOSet = detail::RewritingSystemSet; + bind_froidure_pin_stateless>(m, "Transf1"); bind_froidure_pin_stateless>(m, "Transf2"); bind_froidure_pin_stateless>(m, "Transf4"); @@ -1301,17 +1306,15 @@ This function returns the element of *fp* obtained by evaluating *w*. bind_froidure_pin_stateless>(m, "NTPMat"); bind_froidure_pin_stateful< - detail::KBE>>( - m, "KBEStringRewriteFromLeft"); - bind_froidure_pin_stateful< - detail::KBE>>( - m, "KBEStringRewriteTrie"); - bind_froidure_pin_stateful< - detail::KBE>>( - m, "KBEWordRewriteFromLeft"); + detail::KBE>>(m, + "KBEStringLenLexSet"); bind_froidure_pin_stateful< - detail::KBE>>( - m, "KBEWordRewriteTrie"); + detail::KBE>>( + m, "KBEStringLenLexTrie"); + bind_froidure_pin_stateful>>( + m, "KBEWordLenLexSet"); + bind_froidure_pin_stateful>>( + m, "KBEWordLenLexTrie"); bind_froidure_pin_stateful>(m, "KEString"); bind_froidure_pin_stateful>>( diff --git a/src/kbe.cpp b/src/kbe.cpp index 4e4d02c86..f936ede25 100644 --- a/src/kbe.cpp +++ b/src/kbe.cpp @@ -73,18 +73,20 @@ namespace libsemigroups { } void init_kbe(py::module& m) { - using KBEStringTrie - = detail::KBE>; - using KBEWordTrie - = detail::KBE>; - using KBEStringFromLeft - = detail::KBE>; - using KBEWordFromLeft - = detail::KBE>; - - bind_kbe(m, "KBEStringTrie"); - bind_kbe(m, "KBEWordTrie"); - bind_kbe(m, "KBEStringFromLeft"); - bind_kbe(m, "KBEWordFromLeft"); + using LenLexTrie = detail::RewritingSystemTrie; + using LenLexSet = detail::RewritingSystemSet; + using RPOTrie = detail::RewritingSystemTrie; + using RPOSet = detail::RewritingSystemSet; + + using KBEStringLenLexTrie + = detail::KBE>; + using KBEWordLenLexTrie = detail::KBE>; + using KBEStringLenLexSet = detail::KBE>; + using KBEWordLenLexSet = detail::KBE>; + + bind_kbe(m, "KBEStringLenLexTrie"); + bind_kbe(m, "KBEWordLenLexTrie"); + bind_kbe(m, "KBEStringLenLexSet"); + bind_kbe(m, "KBEWordLenLexSet"); } } // namespace libsemigroups diff --git a/src/knuth-bendix-impl.cpp b/src/knuth-bendix-impl.cpp index a6a9d01c5..59a6dda4a 100644 --- a/src/knuth-bendix-impl.cpp +++ b/src/knuth-bendix-impl.cpp @@ -507,9 +507,14 @@ infinite; ``False`` is returned if it is not. } // namespace detail void init_detail_knuth_bendix_impl(py::module& m) { - detail::bind_detail_knuth_bendix_impl( - m, "KnuthBendixImplRewriteFromLeft"); - detail::bind_detail_knuth_bendix_impl( - m, "KnuthBendixImplRewriteTrie"); + using LenLexTrie = detail::RewritingSystemTrie; + using LenLexSet = detail::RewritingSystemSet; + using RPOTrie = detail::RewritingSystemTrie; + using RPOSet = detail::RewritingSystemSet; + + detail::bind_detail_knuth_bendix_impl( + m, "KnuthBendixImplLenLexSet"); + detail::bind_detail_knuth_bendix_impl( + m, "KnuthBendixImplLenLexTrie"); } } // namespace libsemigroups diff --git a/src/knuth-bendix.cpp b/src/knuth-bendix.cpp index b5f9fa488..e40a58a6a 100644 --- a/src/knuth-bendix.cpp +++ b/src/knuth-bendix.cpp @@ -87,6 +87,7 @@ nested class :any:`KnuthBendix.options`. def_construct_default( thing, "KnuthBendix", + // TODO update doc{.extra_kwargs = ", rewriter: str", .extra_kwargs_doc = R"pbdoc( * **rewriter** (*str*) -- the type of rewriter to use, must be either ``"RewriteTrie"`` or ``"RewriteFromLeft"``.)pbdoc"sv}); @@ -386,7 +387,7 @@ Copy a :any:`NormalFormRange` object. }); thing.def("next", [](NormalFormRange& nfr) { nfr.next(); }); } // bind_normal_form_range - } // namespace + } // namespace template void bind_redundant_rule(py::module& m) { @@ -447,25 +448,25 @@ redundant in this way, then ``None`` is returned. } void init_knuth_bendix(py::module& m) { - using RewriteTrie = detail::RewriteTrie; - using RewriteFromLeft = detail::RewriteFromLeft; - - bind_knuth_bendix(m, "KnuthBendixWordRewriteTrie"); - bind_knuth_bendix( - m, "KnuthBendixWordRewriteFromLeft"); - bind_knuth_bendix(m, - "KnuthBendixStringRewriteTrie"); - bind_knuth_bendix( - m, "KnuthBendixStringRewriteFromLeft"); - - bind_normal_form_range( - m, "KnuthBendixNormalFormRangeWordRewriteTrie"); - bind_normal_form_range( - m, "KnuthBendixNormalFormRangeWordRewriteFromLeft"); - bind_normal_form_range( - m, "KnuthBendixNormalFormRangeStringRewriteTrie"); - bind_normal_form_range( - m, "KnuthBendixNormalFormRangeStringRewriteFromLeft"); + using LenLexTrie = detail::RewritingSystemTrie; + using LenLexSet = detail::RewritingSystemSet; + using RPOTrie = detail::RewritingSystemTrie; + using RPOSet = detail::RewritingSystemSet; + + bind_knuth_bendix(m, "KnuthBendixWordLenLexTrie"); + bind_knuth_bendix(m, "KnuthBendixWordLenLexSet"); + bind_knuth_bendix(m, + "KnuthBendixStringLenLexTrie"); + bind_knuth_bendix(m, "KnuthBendixStringLenLexSet"); + + bind_normal_form_range( + m, "KnuthBendixNormalFormRangeWordLenLexTrie"); + bind_normal_form_range( + m, "KnuthBendixNormalFormRangeWordLenLexSet"); + bind_normal_form_range( + m, "KnuthBendixNormalFormRangeStringLenLexTrie"); + bind_normal_form_range( + m, "KnuthBendixNormalFormRangeStringLenLexSet"); bind_redundant_rule(m); bind_redundant_rule(m); diff --git a/src/libsemigroups_pybind11/froidure_pin.py b/src/libsemigroups_pybind11/froidure_pin.py index 839c6de2e..4aaffcdae 100644 --- a/src/libsemigroups_pybind11/froidure_pin.py +++ b/src/libsemigroups_pybind11/froidure_pin.py @@ -26,10 +26,10 @@ FroidurePinBMat as _FroidurePinBMat, FroidurePinBMat8 as _FroidurePinBMat8, FroidurePinIntMat as _FroidurePinIntMat, - FroidurePinKBEStringRewriteFromLeft as _FroidurePinKBEStringRewriteFromLeft, - FroidurePinKBEStringRewriteTrie as _FroidurePinKBEStringRewriteTrie, - FroidurePinKBEWordRewriteFromLeft as _FroidurePinKBEWordRewriteFromLeft, - FroidurePinKBEWordRewriteTrie as _FroidurePinKBEWordRewriteTrie, + FroidurePinKBEStringLenLexSet as _FroidurePinKBEStringLenLexSet, + FroidurePinKBEStringLenLexTrie as _FroidurePinKBEStringLenLexTrie, + FroidurePinKBEWordLenLexSet as _FroidurePinKBEWordLenLexSet, + FroidurePinKBEWordLenLexTrie as _FroidurePinKBEWordLenLexTrie, FroidurePinKEMultiViewString as _FroidurePinKEMultiViewString, FroidurePinKEString as _FroidurePinKEString, FroidurePinKEWord as _FroidurePinKEWord, @@ -51,10 +51,10 @@ FroidurePinTransf2 as _FroidurePinTransf2, FroidurePinTransf4 as _FroidurePinTransf4, IntMat as _IntMat, - KBEStringFromLeft as _KBEStringFromLeft, - KBEStringTrie as _KBEStringTrie, - KBEWordFromLeft as _KBEWordFromLeft, - KBEWordTrie as _KBEWordTrie, + KBEStringLenLexSet as _KBEStringLenLexSet, + KBEStringLenLexTrie as _KBEStringLenLexTrie, + KBEWordLenLexSet as _KBEWordLenLexSet, + KBEWordLenLexTrie as _KBEWordLenLexTrie, MaxPlusMat as _MaxPlusMat, MaxPlusTruncMat as _MaxPlusTruncMat, MinPlusMat as _MinPlusMat, @@ -145,10 +145,10 @@ class FroidurePin(_CxxWrapper): (_Transf1,): _FroidurePinTransf1, (_Transf2,): _FroidurePinTransf2, (_Transf4,): _FroidurePinTransf4, - (_KBEStringTrie,): _FroidurePinKBEStringRewriteTrie, - (_KBEStringFromLeft,): _FroidurePinKBEStringRewriteFromLeft, - (_KBEWordTrie,): _FroidurePinKBEWordRewriteTrie, - (_KBEWordFromLeft,): _FroidurePinKBEWordRewriteFromLeft, + (_KBEStringLenLexTrie,): _FroidurePinKBEStringLenLexTrie, + (_KBEStringLenLexSet,): _FroidurePinKBEStringLenLexSet, + (_KBEWordLenLexTrie,): _FroidurePinKBEWordLenLexTrie, + (_KBEWordLenLexSet,): _FroidurePinKBEWordLenLexSet, } | ( { (_HPCombiPTransf16,): _FroidurePinHPCombiPTransf16, diff --git a/src/libsemigroups_pybind11/knuth_bendix.py b/src/libsemigroups_pybind11/knuth_bendix.py index ac2410d47..0e0a841d3 100644 --- a/src/libsemigroups_pybind11/knuth_bendix.py +++ b/src/libsemigroups_pybind11/knuth_bendix.py @@ -10,10 +10,10 @@ """ from _libsemigroups_pybind11 import ( - KnuthBendixStringRewriteFromLeft as _KnuthBendixStringRewriteFromLeft, - KnuthBendixStringRewriteTrie as _KnuthBendixStringRewriteTrie, - KnuthBendixWordRewriteFromLeft as _KnuthBendixWordRewriteFromLeft, - KnuthBendixWordRewriteTrie as _KnuthBendixWordRewriteTrie, + KnuthBendixStringLenLexSet as _KnuthBendixStringLenLexSet, + KnuthBendixStringLenLexTrie as _KnuthBendixStringLenLexTrie, + KnuthBendixWordLenLexSet as _KnuthBendixWordLenLexSet, + KnuthBendixWordLenLexTrie as _KnuthBendixWordLenLexTrie, knuth_bendix_by_overlap_length as _knuth_bendix_by_overlap_length, knuth_bendix_is_reduced as _knuth_bendix_is_reduced, knuth_bendix_non_trivial_classes as _knuth_bendix_non_trivial_classes, @@ -38,15 +38,15 @@ class KnuthBendix(_CongruenceCommon): - __doc__ = _KnuthBendixStringRewriteTrie.__doc__ + __doc__ = _KnuthBendixStringLenLexTrie.__doc__ _py_template_params_to_cxx_type = { - (list[int],): _KnuthBendixWordRewriteTrie, - (str,): _KnuthBendixStringRewriteTrie, - (list[int], "RewriteTrie"): _KnuthBendixWordRewriteTrie, - (str, "RewriteTrie"): _KnuthBendixStringRewriteTrie, - (list[int], "RewriteFromLeft"): _KnuthBendixWordRewriteFromLeft, - (str, "RewriteFromLeft"): _KnuthBendixStringRewriteFromLeft, + (list[int],): _KnuthBendixWordLenLexTrie, + (str,): _KnuthBendixStringLenLexTrie, + (list[int], "LenLexTrie"): _KnuthBendixWordLenLexTrie, + (str, "LenLexTrie"): _KnuthBendixStringLenLexTrie, + (list[int], "LenLexSet"): _KnuthBendixWordLenLexSet, + (str, "LenLexSet"): _KnuthBendixStringLenLexSet, } _cxx_type_to_py_template_params = dict( @@ -59,14 +59,14 @@ class KnuthBendix(_CongruenceCommon): _all_wrapped_cxx_types = {*_py_template_params_to_cxx_type.values()} - options = _KnuthBendixStringRewriteTrie.options + options = _KnuthBendixStringLenLexTrie.options - @_copydoc(_KnuthBendixStringRewriteTrie.__init__) - def __init__(self, *args, rewriter="RewriteTrie", **kwargs) -> None: - if rewriter not in ("RewriteFromLeft", "RewriteTrie"): + @_copydoc(_KnuthBendixStringLenLexTrie.__init__) + def __init__(self, *args, rewriter="LenLexTrie", **kwargs) -> None: + if rewriter not in ("LenLexSet", "LenLexTrie"): raise TypeError( f'expected the keyword argument "rewriter" to be ' - f'"RewriteFromLeft" or "RewriteTrie", but found "{rewriter}"' + f'"LenLexSet" or "LenLexTrie", but found "{rewriter}"' ) msg = f"""expected either: @@ -93,11 +93,11 @@ def __init__(self, *args, rewriter="RewriteTrie", **kwargs) -> None: # Copy mem fns from sample C++ type and register types ######################################################################## -_copy_cxx_mem_fns(_KnuthBendixStringRewriteTrie, KnuthBendix) -_register_cxx_wrapped_type(_KnuthBendixStringRewriteTrie, KnuthBendix) -_register_cxx_wrapped_type(_KnuthBendixWordRewriteTrie, KnuthBendix) -_register_cxx_wrapped_type(_KnuthBendixStringRewriteFromLeft, KnuthBendix) -_register_cxx_wrapped_type(_KnuthBendixWordRewriteFromLeft, KnuthBendix) +_copy_cxx_mem_fns(_KnuthBendixStringLenLexTrie, KnuthBendix) +_register_cxx_wrapped_type(_KnuthBendixStringLenLexTrie, KnuthBendix) +_register_cxx_wrapped_type(_KnuthBendixWordLenLexTrie, KnuthBendix) +_register_cxx_wrapped_type(_KnuthBendixStringLenLexSet, KnuthBendix) +_register_cxx_wrapped_type(_KnuthBendixWordLenLexSet, KnuthBendix) ######################################################################## # Helpers diff --git a/src/libsemigroups_pybind11/to.py b/src/libsemigroups_pybind11/to.py index b60915d5b..947ca213d 100644 --- a/src/libsemigroups_pybind11/to.py +++ b/src/libsemigroups_pybind11/to.py @@ -18,12 +18,12 @@ to_inverse_presentation_string as _to_inverse_presentation_string, to_inverse_presentation_word as _to_inverse_presentation_word, to_knuth_bendix as _to_knuth_bendix, - to_knuth_bendix_RewriteFromLeft as _to_knuth_bendix_RewriteFromLeft, - to_knuth_bendix_RewriteTrie as _to_knuth_bendix_RewriteTrie, - to_knuth_bendix_string_RewriteFromLeft as _to_knuth_bendix_string_RewriteFromLeft, - to_knuth_bendix_string_RewriteTrie as _to_knuth_bendix_string_RewriteTrie, - to_knuth_bendix_word_RewriteFromLeft as _to_knuth_bendix_word_RewriteFromLeft, - to_knuth_bendix_word_RewriteTrie as _to_knuth_bendix_word_RewriteTrie, + to_knuth_bendix_LenLexSet as _to_knuth_bendix_LenLexSet, + to_knuth_bendix_LenLexTrie as _to_knuth_bendix_LenLexTrie, + to_knuth_bendix_string_LenLexSet as _to_knuth_bendix_string_LenLexSet, + to_knuth_bendix_string_LenLexTrie as _to_knuth_bendix_string_LenLexTrie, + to_knuth_bendix_word_LenLexSet as _to_knuth_bendix_word_LenLexSet, + to_knuth_bendix_word_LenLexTrie as _to_knuth_bendix_word_LenLexTrie, to_presentation as _to_presentation, to_presentation_string as _to_presentation_string, to_presentation_word as _to_presentation_word, @@ -69,12 +69,12 @@ def _nice_name(type_list): (_InversePresentation, list[int]): _to_inverse_presentation_word, (_InversePresentation, str): _to_inverse_presentation_string, (_KnuthBendix,): _to_knuth_bendix, - (_KnuthBendix, "RewriteTrie"): _to_knuth_bendix_RewriteTrie, - (_KnuthBendix, "RewriteFromLeft"): _to_knuth_bendix_RewriteFromLeft, - (_KnuthBendix, list[int], "RewriteFromLeft"): _to_knuth_bendix_word_RewriteFromLeft, - (_KnuthBendix, list[int], "RewriteTrie"): _to_knuth_bendix_word_RewriteTrie, - (_KnuthBendix, str, "RewriteFromLeft"): _to_knuth_bendix_string_RewriteFromLeft, - (_KnuthBendix, str, "RewriteTrie"): _to_knuth_bendix_string_RewriteTrie, + (_KnuthBendix, "LenLexTrie"): _to_knuth_bendix_LenLexTrie, + (_KnuthBendix, "LenLexSet"): _to_knuth_bendix_LenLexSet, + (_KnuthBendix, list[int], "LenLexSet"): _to_knuth_bendix_word_LenLexSet, + (_KnuthBendix, list[int], "LenLexTrie"): _to_knuth_bendix_word_LenLexTrie, + (_KnuthBendix, str, "LenLexSet"): _to_knuth_bendix_string_LenLexSet, + (_KnuthBendix, str, "LenLexTrie"): _to_knuth_bendix_string_LenLexTrie, (_Presentation,): _to_presentation, (_Presentation, str): _to_presentation_string, (_Presentation, list[int]): _to_presentation_word, diff --git a/src/to-froidure-pin.cpp b/src/to-froidure-pin.cpp index 629754c44..d69fb51ff 100644 --- a/src/to-froidure-pin.cpp +++ b/src/to-froidure-pin.cpp @@ -52,6 +52,11 @@ namespace libsemigroups { } // namespace void init_to_froidure_pin(py::module& m) { + using LenLexTrie = detail::RewritingSystemTrie; + using LenLexSet = detail::RewritingSystemSet; + using RPOTrie = detail::RewritingSystemTrie; + using RPOSet = detail::RewritingSystemSet; + // Congruence bind_to_froidure_pin>(m); bind_to_froidure_pin>(m); @@ -62,10 +67,10 @@ namespace libsemigroups { bind_to_froidure_pin>(m); // KnuthBendix - bind_to_froidure_pin>(m); - bind_to_froidure_pin>(m); - bind_to_froidure_pin>(m); - bind_to_froidure_pin>(m); + bind_to_froidure_pin>(m); + bind_to_froidure_pin>(m); + bind_to_froidure_pin>(m); + bind_to_froidure_pin>(m); // ToddCoxeter bind_to_froidure_pin>(m); diff --git a/src/to-knuth-bendix.cpp b/src/to-knuth-bendix.cpp index fb04a408a..89dd0aa77 100644 --- a/src/to-knuth-bendix.cpp +++ b/src/to-knuth-bendix.cpp @@ -26,7 +26,7 @@ #include // for ToddCoxeter #include // for word_type -#include // for detail::RewriteTrie +#include // for detail::LenLexTrie // pybind11.... #include @@ -65,27 +65,26 @@ namespace libsemigroups { } // namespace void init_to_knuth_bendix(py::module& m) { - using RewriteFromLeft = detail::RewriteFromLeft; - using RewriteTrie = detail::RewriteTrie; + using LenLexTrie = detail::RewritingSystemTrie; + using LenLexSet = detail::RewritingSystemSet; + using RPOTrie = detail::RewritingSystemTrie; + using RPOSet = detail::RewritingSystemSet; // FroidurePin - bind_froidure_pin_to_knuth_bendix( - m, "string_RewriteFromLeft"); - bind_froidure_pin_to_knuth_bendix( - m, "string_RewriteTrie"); - bind_froidure_pin_to_knuth_bendix( - m, "word_RewriteFromLeft"); - bind_froidure_pin_to_knuth_bendix( - m, "word_RewriteTrie"); + bind_froidure_pin_to_knuth_bendix( + m, "string_LenLexSet"); + bind_froidure_pin_to_knuth_bendix( + m, "string_LenLexTrie"); + bind_froidure_pin_to_knuth_bendix(m, + "word_LenLexSet"); + bind_froidure_pin_to_knuth_bendix(m, + "word_LenLexTrie"); // ToddCoxeter + rewriter - bind_todd_coxeter_to_knuth_bendix( - m, "RewriteFromLeft"); - bind_todd_coxeter_to_knuth_bendix( - m, "RewriteFromLeft"); - bind_todd_coxeter_to_knuth_bendix(m, - "RewriteTrie"); - bind_todd_coxeter_to_knuth_bendix(m, "RewriteTrie"); + bind_todd_coxeter_to_knuth_bendix(m, "LenLexSet"); + bind_todd_coxeter_to_knuth_bendix(m, "LenLexSet"); + bind_todd_coxeter_to_knuth_bendix(m, "LenLexTrie"); + bind_todd_coxeter_to_knuth_bendix(m, "LenLexTrie"); // ToddCoxeter bind_todd_coxeter_to_knuth_bendix_default(m); diff --git a/src/to-presentation.cpp b/src/to-presentation.cpp index 894ce75c2..4ddd4aa43 100644 --- a/src/to-presentation.cpp +++ b/src/to-presentation.cpp @@ -190,6 +190,11 @@ namespace libsemigroups { } // namespace void init_to_present(py::module& m) { + using LenLexTrie = detail::RewritingSystemTrie; + using LenLexSet = detail::RewritingSystemSet; + using RPOTrie = detail::RewritingSystemTrie; + using RPOSet = detail::RewritingSystemSet; + //////////////////////////////////////////////////////////////////////////// // to //////////////////////////////////////////////////////////////////////////// @@ -207,28 +212,20 @@ namespace libsemigroups { bind_pres_func_to_pres(m, "string"); // From KnuthBendix - bind_kb_to_pres(m); - bind_kb_to_pres(m); - bind_kb_to_pres(m); - bind_kb_to_pres(m); - - bind_kb_to_pres_with_word(m, "string"); - bind_kb_to_pres_with_word( - m, "string"); - bind_kb_to_pres_with_word( - m, "string"); - bind_kb_to_pres_with_word( - m, "string"); - bind_kb_to_pres_with_word( - m, "word"); - bind_kb_to_pres_with_word( - m, "word"); - bind_kb_to_pres_with_word( - m, "word"); - bind_kb_to_pres_with_word( - m, "word"); + bind_kb_to_pres(m); + bind_kb_to_pres(m); + bind_kb_to_pres(m); + bind_kb_to_pres(m); + + bind_kb_to_pres_with_word(m, "string"); + bind_kb_to_pres_with_word(m, + "string"); + bind_kb_to_pres_with_word(m, "string"); + bind_kb_to_pres_with_word(m, "string"); + bind_kb_to_pres_with_word(m, "word"); + bind_kb_to_pres_with_word(m, "word"); + bind_kb_to_pres_with_word(m, "word"); + bind_kb_to_pres_with_word(m, "word"); // From FroidurePin bind_fp_to_pres(m, "string"); diff --git a/src/to-todd-coxeter.cpp b/src/to-todd-coxeter.cpp index ad7aabd3a..4a245d72f 100644 --- a/src/to-todd-coxeter.cpp +++ b/src/to-todd-coxeter.cpp @@ -51,11 +51,16 @@ namespace libsemigroups { } // namespace void init_to_todd_coxeter(py::module& m) { + using LenLexTrie = detail::RewritingSystemTrie; + using LenLexSet = detail::RewritingSystemSet; + using RPOTrie = detail::RewritingSystemTrie; + using RPOSet = detail::RewritingSystemSet; + // KnuthBendix - bind_to_todd_coxeter_kb(m); - bind_to_todd_coxeter_kb(m); - bind_to_todd_coxeter_kb(m); - bind_to_todd_coxeter_kb(m); + bind_to_todd_coxeter_kb(m); + bind_to_todd_coxeter_kb(m); + bind_to_todd_coxeter_kb(m); + bind_to_todd_coxeter_kb(m); // WordGraph m.def("to_todd_coxeter_word", diff --git a/tests/test_knuth_bendix.py b/tests/test_knuth_bendix.py index 155bcec31..19f5d08b4 100644 --- a/tests/test_knuth_bendix.py +++ b/tests/test_knuth_bendix.py @@ -32,7 +32,7 @@ def check_initialisation(*args): - for rewriter in ("RewriteFromLeft", "RewriteTrie"): + for rewriter in ("LenLexSet", "LenLexTrie"): kb = KnuthBendix(*args, rewriter=rewriter) kb.run() @@ -61,9 +61,9 @@ def test_initialisation(): kb2.run() with pytest.raises(TypeError): - KnuthBendix(kb, rewriter="RewriteFromLeft") + KnuthBendix(kb, rewriter="LenLexSet") - kb = KnuthBendix(kind, p, rewriter="RewriteFromLeft") + kb = KnuthBendix(kind, p, rewriter="LenLexSet") def test_attributes(): diff --git a/tests/test_to.py b/tests/test_to.py index d05c86d27..778088933 100644 --- a/tests/test_to.py +++ b/tests/test_to.py @@ -13,10 +13,10 @@ # TODO(1) be good to remove the imports from _libsemigroups_pybind11, but # couldn't immediately figure out how to. from _libsemigroups_pybind11 import ( - FroidurePinKBEStringRewriteFromLeft, - FroidurePinKBEStringRewriteTrie, - FroidurePinKBEWordRewriteFromLeft, - FroidurePinKBEWordRewriteTrie, + FroidurePinKBEStringLenLexSet, + FroidurePinKBEStringLenLexTrie, + FroidurePinKBEWordLenLexSet, + FroidurePinKBEWordLenLexTrie, FroidurePinKEMultiViewString, FroidurePinKEString, FroidurePinKEWord, @@ -230,23 +230,23 @@ def check_froidure_pin_to_congruence(Word): def test_to_FroidurePin_000(): - fp = check_cong_to_froidure_pin(KnuthBendix, str, rewriter="RewriteFromLeft") - assert isinstance(to_cxx(fp), FroidurePinKBEStringRewriteFromLeft) + fp = check_cong_to_froidure_pin(KnuthBendix, str, rewriter="LenLexSet") + assert isinstance(to_cxx(fp), FroidurePinKBEStringLenLexSet) def test_to_FroidurePin_001(): - fp = check_cong_to_froidure_pin(KnuthBendix, str, rewriter="RewriteTrie") - assert isinstance(to_cxx(fp), FroidurePinKBEStringRewriteTrie) + fp = check_cong_to_froidure_pin(KnuthBendix, str, rewriter="LenLexTrie") + assert isinstance(to_cxx(fp), FroidurePinKBEStringLenLexTrie) def test_to_FroidurePin_002(): - fp = check_cong_to_froidure_pin(KnuthBendix, int, rewriter="RewriteFromLeft") - assert isinstance(to_cxx(fp), FroidurePinKBEWordRewriteFromLeft) + fp = check_cong_to_froidure_pin(KnuthBendix, int, rewriter="LenLexSet") + assert isinstance(to_cxx(fp), FroidurePinKBEWordLenLexSet) def test_to_FroidurePin_003(): - fp = check_cong_to_froidure_pin(KnuthBendix, int, rewriter="RewriteTrie") - assert isinstance(to_cxx(fp), FroidurePinKBEWordRewriteTrie) + fp = check_cong_to_froidure_pin(KnuthBendix, int, rewriter="LenLexTrie") + assert isinstance(to_cxx(fp), FroidurePinKBEWordLenLexTrie) # From ToddCoxeter @@ -357,25 +357,25 @@ def test_to_FroidurePin_013(): def test_to_ToddCoxeter_014(): - tc = check_cong_to_todd_coxeter(KnuthBendix, str, rewriter="RewriteFromLeft") + tc = check_cong_to_todd_coxeter(KnuthBendix, str, rewriter="LenLexSet") assert isinstance(tc, ToddCoxeter) assert tc.py_template_params == (str,) def test_to_ToddCoxeter_015(): - tc = check_cong_to_todd_coxeter(KnuthBendix, str, rewriter="RewriteTrie") + tc = check_cong_to_todd_coxeter(KnuthBendix, str, rewriter="LenLexTrie") assert isinstance(tc, ToddCoxeter) assert tc.py_template_params == (str,) def test_to_ToddCoxeter_016(): - tc = check_cong_to_todd_coxeter(KnuthBendix, int, rewriter="RewriteFromLeft") + tc = check_cong_to_todd_coxeter(KnuthBendix, int, rewriter="LenLexSet") assert isinstance(tc, ToddCoxeter) assert tc.py_template_params == (list[int],) def test_to_ToddCoxeter_017(): - tc = check_cong_to_todd_coxeter(KnuthBendix, int, rewriter="RewriteTrie") + tc = check_cong_to_todd_coxeter(KnuthBendix, int, rewriter="LenLexTrie") assert isinstance(tc, ToddCoxeter) assert tc.py_template_params == (list[int],) @@ -641,23 +641,23 @@ def test_to_Presentation_023(): def test_to_Presentation_024(): - check_knuth_bendix_to_pres(str, str, "RewriteFromLeft") - check_knuth_bendix_to_pres(str, list[int], "RewriteFromLeft") + check_knuth_bendix_to_pres(str, str, "LenLexSet") + check_knuth_bendix_to_pres(str, list[int], "LenLexSet") def test_to_Presentation_025(): - check_knuth_bendix_to_pres(str, str, "RewriteTrie") - check_knuth_bendix_to_pres(str, list[int], "RewriteTrie") + check_knuth_bendix_to_pres(str, str, "LenLexTrie") + check_knuth_bendix_to_pres(str, list[int], "LenLexTrie") def test_to_Presentation_026(): - check_knuth_bendix_to_pres(list[int], str, "RewriteFromLeft") - check_knuth_bendix_to_pres(list[int], list[int], "RewriteFromLeft") + check_knuth_bendix_to_pres(list[int], str, "LenLexSet") + check_knuth_bendix_to_pres(list[int], list[int], "LenLexSet") def test_to_Presentation_027(): - check_knuth_bendix_to_pres(list[int], str, "RewriteTrie") - check_knuth_bendix_to_pres(list[int], list[int], "RewriteTrie") + check_knuth_bendix_to_pres(list[int], str, "LenLexTrie") + check_knuth_bendix_to_pres(list[int], list[int], "LenLexTrie") # From FroidurePin @@ -838,23 +838,23 @@ def test_to_InversePresentation_048(): def test_to_KnuthBendix_049(): - kb = check_froidure_pin_to_knuth_bendix(str, "RewriteFromLeft") + kb = check_froidure_pin_to_knuth_bendix(str, "LenLexSet") assert isinstance(kb, KnuthBendix) - assert kb.py_template_params == (str, "RewriteFromLeft") + assert kb.py_template_params == (str, "LenLexSet") def test_to_KnuthBendix_050(): - kb = check_froidure_pin_to_knuth_bendix(str, "RewriteTrie") + kb = check_froidure_pin_to_knuth_bendix(str, "LenLexTrie") assert isinstance(kb, KnuthBendix) def test_to_KnuthBendix_051(): - kb = check_froidure_pin_to_knuth_bendix(list[int], "RewriteFromLeft") + kb = check_froidure_pin_to_knuth_bendix(list[int], "LenLexSet") assert isinstance(kb, KnuthBendix) def test_to_KnuthBendix_052(): - kb = check_froidure_pin_to_knuth_bendix(list[int], "RewriteTrie") + kb = check_froidure_pin_to_knuth_bendix(list[int], "LenLexTrie") assert isinstance(kb, KnuthBendix) @@ -862,22 +862,22 @@ def test_to_KnuthBendix_052(): def test_to_KnuthBendix_053(): - kb = check_todd_coxeter_to_knuth_bendix(str, "RewriteFromLeft") + kb = check_todd_coxeter_to_knuth_bendix(str, "LenLexSet") assert isinstance(kb, KnuthBendix) def test_to_KnuthBendix_054(): - kb = check_todd_coxeter_to_knuth_bendix(str, "RewriteTrie") + kb = check_todd_coxeter_to_knuth_bendix(str, "LenLexTrie") assert isinstance(kb, KnuthBendix) def test_to_KnuthBendix_055(): - kb = check_todd_coxeter_to_knuth_bendix(list[int], "RewriteFromLeft") + kb = check_todd_coxeter_to_knuth_bendix(list[int], "LenLexSet") assert isinstance(kb, KnuthBendix) def test_to_KnuthBendix_056(): - kb = check_todd_coxeter_to_knuth_bendix(list[int], "RewriteTrie") + kb = check_todd_coxeter_to_knuth_bendix(list[int], "LenLexTrie") assert isinstance(kb, KnuthBendix) @@ -886,13 +886,13 @@ def test_to_KnuthBendix_056(): def test_to_KnuthBendix_057(): kb = check_todd_coxeter_to_knuth_bendix_default(str) - # RewriteTrie is the default rewriter + # LenLexTrie is the default rewriter assert isinstance(kb, KnuthBendix) def test_to_KnuthBendix_058(): kb = check_todd_coxeter_to_knuth_bendix_default(list[int]) - # RewriteTrie is the default rewriter + # LenLexTrie is the default rewriter assert isinstance(kb, KnuthBendix) From 099e500147406c04cced2fdedf68b5f75372332b Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Mon, 8 Jun 2026 13:58:36 +0100 Subject: [PATCH 4/6] knuth-bendix: add support for RPO --- .../knuth-bendix/to-knuth-bendix.rst | 2 + src/cong-common.cpp | 147 ++++++++++++++++++ src/knuth-bendix-impl.cpp | 3 + src/knuth-bendix.cpp | 20 ++- src/libsemigroups_pybind11/knuth_bendix.py | 49 ++++-- tests/test_knuth_bendix.py | 25 ++- 6 files changed, 227 insertions(+), 19 deletions(-) diff --git a/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst b/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst index be6870a37..a6b33f589 100644 --- a/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst +++ b/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst @@ -5,6 +5,8 @@ The full license is in the file LICENSE, distributed with this software. +.. TODO update + .. currentmodule:: libsemigroups_pybind11 Converting to a KnuthBendix diff --git a/src/cong-common.cpp b/src/cong-common.cpp index ed493a20f..7420166c2 100644 --- a/src/cong-common.cpp +++ b/src/cong-common.cpp @@ -54,6 +54,11 @@ namespace libsemigroups { using KnuthBendixWordLenLexTrie = KnuthBendix; using KnuthBendixWordLenLexSet = KnuthBendix; + using KnuthBendixStringRPOTrie = KnuthBendix; + using KnuthBendixStringRPOSet = KnuthBendix; + using KnuthBendixWordRPOTrie = KnuthBendix; + using KnuthBendixWordRPOSet = KnuthBendix; + //////////////////////////////////////////////////////////////////////// // Implementation helpers //////////////////////////////////////////////////////////////////////// @@ -133,6 +138,11 @@ This function default constructs an uninitialised :any:`{name}` instance. DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl, + detail::CongruenceCommon); + DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl, + detail::CongruenceCommon); + DEF_CONSTRUCT_DEFAULT(KnuthBendixStringLenLexTrie, detail::KnuthBendixImpl); DEF_CONSTRUCT_DEFAULT(KnuthBendixStringLenLexSet, @@ -142,6 +152,14 @@ This function default constructs an uninitialised :any:`{name}` instance. DEF_CONSTRUCT_DEFAULT(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_CONSTRUCT_DEFAULT(KnuthBendixStringRPOTrie, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_DEFAULT(KnuthBendixStringRPOSet, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_DEFAULT(KnuthBendixWordRPOTrie, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_DEFAULT(KnuthBendixWordRPOSet, detail::KnuthBendixImpl); + DEF_CONSTRUCT_DEFAULT(Congruence, detail::CongruenceCommon); DEF_CONSTRUCT_DEFAULT(Congruence, detail::CongruenceCommon); @@ -193,6 +211,9 @@ have been in if it had just been newly default constructed. DEF_INIT_DEFAULT(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_INIT_DEFAULT(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_INIT_DEFAULT(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_INIT_DEFAULT(KnuthBendixStringLenLexTrie, detail::KnuthBendixImpl); DEF_INIT_DEFAULT(KnuthBendixStringLenLexSet, @@ -202,6 +223,11 @@ have been in if it had just been newly default constructed. DEF_INIT_DEFAULT(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_INIT_DEFAULT(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl); + DEF_INIT_DEFAULT(KnuthBendixStringRPOSet, detail::KnuthBendixImpl); + DEF_INIT_DEFAULT(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl); + DEF_INIT_DEFAULT(KnuthBendixWordRPOSet, detail::KnuthBendixImpl); + DEF_INIT_DEFAULT(Congruence, detail::CongruenceCommon); DEF_INIT_DEFAULT(Congruence, detail::CongruenceCommon); @@ -276,6 +302,20 @@ of kind *knd* over the semigroup or monoid defined by the presentation *p*. DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl, + detail::CongruenceCommon); + DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl, + detail::CongruenceCommon); + + DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringRPOTrie, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringRPOSet, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordRPOTrie, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordRPOSet, + detail::KnuthBendixImpl); + DEF_CONSTRUCT_KIND_PRESENTATION(Congruence, detail::CongruenceCommon); DEF_CONSTRUCT_KIND_PRESENTATION(Congruence, @@ -353,6 +393,20 @@ had been newly constructed from *knd* and *p*. DEF_INIT_KIND_PRESENTATION(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl, + detail::CongruenceCommon); + DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl, + detail::CongruenceCommon); + + DEF_INIT_KIND_PRESENTATION(KnuthBendixStringRPOTrie, + detail::KnuthBendixImpl); + DEF_INIT_KIND_PRESENTATION(KnuthBendixStringRPOSet, + detail::KnuthBendixImpl); + DEF_INIT_KIND_PRESENTATION(KnuthBendixWordRPOTrie, + detail::KnuthBendixImpl); + DEF_INIT_KIND_PRESENTATION(KnuthBendixWordRPOSet, + detail::KnuthBendixImpl); + DEF_INIT_KIND_PRESENTATION(Congruence, detail::CongruenceCommon); DEF_INIT_KIND_PRESENTATION(Congruence, detail::CongruenceCommon); @@ -404,6 +458,14 @@ Copy a :any:`{name}` object. DEF_COPY(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl); DEF_COPY(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_COPY(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_COPY(detail::KnuthBendixImpl, detail::CongruenceCommon); + + DEF_COPY(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixStringRPOSet, detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixWordRPOSet, detail::KnuthBendixImpl); + DEF_COPY(Congruence, detail::CongruenceCommon); DEF_COPY(Congruence, detail::CongruenceCommon); @@ -460,6 +522,11 @@ number of classes in the congruence represented by a :any:`{name}` instance. DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl, + detail::CongruenceCommon); + DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl, + detail::CongruenceCommon); + DEF_NUMBER_OF_CLASSES(Congruence, detail::CongruenceCommon); DEF_NUMBER_OF_CLASSES(Congruence, detail::CongruenceCommon); @@ -543,6 +610,20 @@ This function adds a generating pair to the congruence represented by a DEF_ADD_GENERATING_PAIR(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_ADD_GENERATING_PAIR(detail::KnuthBendixImpl, + detail::CongruenceCommon); + DEF_ADD_GENERATING_PAIR(detail::KnuthBendixImpl, + detail::CongruenceCommon); + + DEF_ADD_GENERATING_PAIR(KnuthBendixStringRPOTrie, + detail::KnuthBendixImpl); + DEF_ADD_GENERATING_PAIR(KnuthBendixStringRPOSet, + detail::KnuthBendixImpl); + DEF_ADD_GENERATING_PAIR(KnuthBendixWordRPOTrie, + detail::KnuthBendixImpl); + DEF_ADD_GENERATING_PAIR(KnuthBendixWordRPOSet, + detail::KnuthBendixImpl); + DEF_ADD_GENERATING_PAIR(Congruence, detail::CongruenceCommon); DEF_ADD_GENERATING_PAIR(Congruence, detail::CongruenceCommon); @@ -626,6 +707,20 @@ contained in the congruence, but that this is not currently known. DEF_CURRENTLY_CONTAINS(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_CURRENTLY_CONTAINS(detail::KnuthBendixImpl, + detail::CongruenceCommon); + DEF_CURRENTLY_CONTAINS(detail::KnuthBendixImpl, + detail::CongruenceCommon); + + DEF_CURRENTLY_CONTAINS(KnuthBendixStringRPOTrie, + detail::KnuthBendixImpl); + DEF_CURRENTLY_CONTAINS(KnuthBendixStringRPOSet, + detail::KnuthBendixImpl); + DEF_CURRENTLY_CONTAINS(KnuthBendixWordRPOTrie, + detail::KnuthBendixImpl); + DEF_CURRENTLY_CONTAINS(KnuthBendixWordRPOSet, + detail::KnuthBendixImpl); + DEF_CURRENTLY_CONTAINS(Congruence, detail::CongruenceCommon); DEF_CURRENTLY_CONTAINS(Congruence, detail::CongruenceCommon); @@ -697,6 +792,14 @@ congruence represented by a :py:class:`{name}` instance. DEF_CONTAINS(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl); DEF_CONTAINS(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_CONTAINS(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_CONTAINS(detail::KnuthBendixImpl, detail::CongruenceCommon); + + DEF_CONTAINS(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixStringRPOSet, detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixWordRPOSet, detail::KnuthBendixImpl); + DEF_CONTAINS(Congruence, detail::CongruenceCommon); DEF_CONTAINS(Congruence, detail::CongruenceCommon); @@ -770,6 +873,14 @@ normal form for the input word *w*. DEF_REDUCE_NO_RUN(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_REDUCE_NO_RUN(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_REDUCE_NO_RUN(detail::KnuthBendixImpl, detail::CongruenceCommon); + + DEF_REDUCE_NO_RUN(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl); + DEF_REDUCE_NO_RUN(KnuthBendixStringRPOSet, detail::KnuthBendixImpl); + DEF_REDUCE_NO_RUN(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl); + DEF_REDUCE_NO_RUN(KnuthBendixWordRPOSet, detail::KnuthBendixImpl); + DEF_REDUCE_NO_RUN(Congruence, detail::CongruenceCommon); DEF_REDUCE_NO_RUN(Congruence, detail::CongruenceCommon); @@ -838,6 +949,14 @@ input word. DEF_REDUCE(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl); DEF_REDUCE(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_REDUCE(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_REDUCE(detail::KnuthBendixImpl, detail::CongruenceCommon); + + DEF_REDUCE(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixStringRPOSet, detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixWordRPOSet, detail::KnuthBendixImpl); + DEF_REDUCE(Congruence, detail::CongruenceCommon); DEF_REDUCE(Congruence, detail::CongruenceCommon); @@ -896,6 +1015,14 @@ This function returns the generating pairs of the congruence as added via DEF_GENERATING_PAIRS(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_GENERATING_PAIRS(KnuthBendixStringRPOTrie, + detail::KnuthBendixImpl); + DEF_GENERATING_PAIRS(KnuthBendixStringRPOSet, + detail::KnuthBendixImpl); + DEF_GENERATING_PAIRS(KnuthBendixWordRPOTrie, + detail::KnuthBendixImpl); + DEF_GENERATING_PAIRS(KnuthBendixWordRPOSet, detail::KnuthBendixImpl); + DEF_GENERATING_PAIRS(Congruence, detail::CongruenceCommon); DEF_GENERATING_PAIRS(Congruence, detail::CongruenceCommon); @@ -955,6 +1082,11 @@ presentation, then this presentation is returned by this function. DEF_PRESENTATION(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + DEF_PRESENTATION(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl); + DEF_PRESENTATION(KnuthBendixStringRPOSet, detail::KnuthBendixImpl); + DEF_PRESENTATION(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl); + DEF_PRESENTATION(KnuthBendixWordRPOSet, detail::KnuthBendixImpl); + DEF_PRESENTATION(Congruence, detail::CongruenceCommon); DEF_PRESENTATION(Congruence, detail::CongruenceCommon); @@ -1023,6 +1155,11 @@ triggers a full enumeration of *{var}*. DEF_PARTITION(KnuthBendixWordLenLexTrie); DEF_PARTITION(KnuthBendixWordLenLexSet); + DEF_PARTITION(KnuthBendixStringRPOTrie); + DEF_PARTITION(KnuthBendixStringRPOSet); + DEF_PARTITION(KnuthBendixWordRPOTrie); + DEF_PARTITION(KnuthBendixWordRPOSet); + DEF_PARTITION(Congruence); DEF_PARTITION(Congruence); @@ -1090,6 +1227,11 @@ instance *{var}*. DEF_NON_TRIVIAL_CLASSES(KnuthBendixWordLenLexTrie); DEF_NON_TRIVIAL_CLASSES(KnuthBendixWordLenLexSet); + DEF_NON_TRIVIAL_CLASSES(KnuthBendixStringRPOTrie); + DEF_NON_TRIVIAL_CLASSES(KnuthBendixStringRPOSet); + DEF_NON_TRIVIAL_CLASSES(KnuthBendixWordRPOTrie); + DEF_NON_TRIVIAL_CLASSES(KnuthBendixWordRPOSet); + DEF_NON_TRIVIAL_CLASSES(Congruence); DEF_NON_TRIVIAL_CLASSES(Congruence); @@ -1153,6 +1295,11 @@ the congruence represented by an instance of :any:`{name}`. DEF_NORMAL_FORMS(KnuthBendixWordLenLexTrie); DEF_NORMAL_FORMS(KnuthBendixWordLenLexSet); + DEF_NORMAL_FORMS(KnuthBendixStringRPOTrie); + DEF_NORMAL_FORMS(KnuthBendixStringRPOSet); + DEF_NORMAL_FORMS(KnuthBendixWordRPOTrie); + DEF_NORMAL_FORMS(KnuthBendixWordRPOSet); + // TODO(1) uncomment when implemented in libsemigroups // DEF_NORMAL_FORMS(Congruence); // DEF_NORMAL_FORMS(Congruence); diff --git a/src/knuth-bendix-impl.cpp b/src/knuth-bendix-impl.cpp index 59a6dda4a..f93bcf046 100644 --- a/src/knuth-bendix-impl.cpp +++ b/src/knuth-bendix-impl.cpp @@ -516,5 +516,8 @@ infinite; ``False`` is returned if it is not. m, "KnuthBendixImplLenLexSet"); detail::bind_detail_knuth_bendix_impl( m, "KnuthBendixImplLenLexTrie"); + + detail::bind_detail_knuth_bendix_impl(m, "KnuthBendixImplRPOSet"); + detail::bind_detail_knuth_bendix_impl(m, "KnuthBendixImplRPOTrie"); } } // namespace libsemigroups diff --git a/src/knuth-bendix.cpp b/src/knuth-bendix.cpp index e40a58a6a..2ec9cf00a 100644 --- a/src/knuth-bendix.cpp +++ b/src/knuth-bendix.cpp @@ -330,8 +330,10 @@ Check if all rules are reduced with respect to each other. template void bind_normal_form_range(py::module& m, char const* name) { - using NormalFormRange - = detail::KnuthBendixNormalFormRange; + using NormalFormRange = detail::KnuthBendixNormalFormRange< + Word, + Rewriter, + typename Rewriter::reduction_order>; py::class_ thing(m, name); thing.def("__repr__", [](NormalFormRange const& nfr) { @@ -459,6 +461,11 @@ redundant in this way, then ``None`` is returned. "KnuthBendixStringLenLexTrie"); bind_knuth_bendix(m, "KnuthBendixStringLenLexSet"); + bind_knuth_bendix(m, "KnuthBendixWordRPOTrie"); + bind_knuth_bendix(m, "KnuthBendixWordRPOSet"); + bind_knuth_bendix(m, "KnuthBendixStringRPOTrie"); + bind_knuth_bendix(m, "KnuthBendixStringRPOSet"); + bind_normal_form_range( m, "KnuthBendixNormalFormRangeWordLenLexTrie"); bind_normal_form_range( @@ -468,6 +475,15 @@ redundant in this way, then ``None`` is returned. bind_normal_form_range( m, "KnuthBendixNormalFormRangeStringLenLexSet"); + bind_normal_form_range( + m, "KnuthBendixNormalFormRangeWordRPOTrie"); + bind_normal_form_range( + m, "KnuthBendixNormalFormRangeWordRPOSet"); + bind_normal_form_range( + m, "KnuthBendixNormalFormRangeStringRPOTrie"); + bind_normal_form_range( + m, "KnuthBendixNormalFormRangeStringRPOSet"); + bind_redundant_rule(m); bind_redundant_rule(m); } diff --git a/src/libsemigroups_pybind11/knuth_bendix.py b/src/libsemigroups_pybind11/knuth_bendix.py index 0e0a841d3..8313c66a4 100644 --- a/src/libsemigroups_pybind11/knuth_bendix.py +++ b/src/libsemigroups_pybind11/knuth_bendix.py @@ -9,11 +9,18 @@ are contained in the submodule ``knuth_bendix``. """ +from warnings import warn + from _libsemigroups_pybind11 import ( KnuthBendixStringLenLexSet as _KnuthBendixStringLenLexSet, KnuthBendixStringLenLexTrie as _KnuthBendixStringLenLexTrie, KnuthBendixWordLenLexSet as _KnuthBendixWordLenLexSet, KnuthBendixWordLenLexTrie as _KnuthBendixWordLenLexTrie, + KnuthBendixStringRPOSet as _KnuthBendixStringRPOSet, + KnuthBendixStringRPOTrie as _KnuthBendixStringRPOTrie, + KnuthBendixWordRPOSet as _KnuthBendixWordRPOSet, + KnuthBendixWordRPOTrie as _KnuthBendixWordRPOTrie, + Order as _Order, knuth_bendix_by_overlap_length as _knuth_bendix_by_overlap_length, knuth_bendix_is_reduced as _knuth_bendix_is_reduced, knuth_bendix_non_trivial_classes as _knuth_bendix_non_trivial_classes, @@ -43,10 +50,14 @@ class KnuthBendix(_CongruenceCommon): _py_template_params_to_cxx_type = { (list[int],): _KnuthBendixWordLenLexTrie, (str,): _KnuthBendixStringLenLexTrie, - (list[int], "LenLexTrie"): _KnuthBendixWordLenLexTrie, - (str, "LenLexTrie"): _KnuthBendixStringLenLexTrie, - (list[int], "LenLexSet"): _KnuthBendixWordLenLexSet, - (str, "LenLexSet"): _KnuthBendixStringLenLexSet, + (list[int], "Trie", _Order.shortlex): _KnuthBendixWordLenLexTrie, + (str, "Trie", _Order.shortlex): _KnuthBendixStringLenLexTrie, + (list[int], "Set", _Order.shortlex): _KnuthBendixWordLenLexSet, + (str, "Set", _Order.shortlex): _KnuthBendixStringLenLexSet, + (list[int], "Trie", _Order.recursive): _KnuthBendixWordRPOTrie, + (str, "Trie", _Order.recursive): _KnuthBendixStringRPOTrie, + (list[int], "Set", _Order.recursive): _KnuthBendixWordRPOSet, + (str, "Set", _Order.recursive): _KnuthBendixStringRPOSet, } _cxx_type_to_py_template_params = dict( @@ -62,26 +73,42 @@ class KnuthBendix(_CongruenceCommon): options = _KnuthBendixStringLenLexTrie.options @_copydoc(_KnuthBendixStringLenLexTrie.__init__) - def __init__(self, *args, rewriter="LenLexTrie", **kwargs) -> None: - if rewriter not in ("LenLexSet", "LenLexTrie"): - raise TypeError( - f'expected the keyword argument "rewriter" to be ' - f'"LenLexSet" or "LenLexTrie", but found "{rewriter}"' + def __init__(self, *args, rewriting_system="Trie", order=_Order.shortlex, **kwargs) -> None: + if "rewriter" in kwargs: + warn( + 'The keyword argument "rewriter" is deprecated, please use a combination ' + 'of "rewriting_system" and "order" instead. If you also specified the ' + 'keyword argument "rewriting_system" or "order", then the value(s) you ' + "specified will be ignored!", + DeprecationWarning, + 2, ) + if kwargs["rewriter"] not in ("RewriteFromLeft", "RewriteTrie"): + raise TypeError( + f'expected the keyword argument "rewriter" to be ' + f'"RewriteFromLeft" or "RewriteTrie", but found "{rewriter}"' + ) + if kwargs["rewriter"] == "RewriteFromLeft": + rewriting_system = "Set" + order = _Order.shortlex + else: + rewriting_system = "Trie" + order = _Order.shortlex msg = f"""expected either: 1) 2 positional arguments of types congruence_kind and Presentation; or 2) 0 positional arguments and the keyword argument "word" - (and possibly the keyword argument "rewriter"). + (and possibly the keyword arguments "rewriting_system" and "order"). Found {len(args)} positional arguments and keyword arguments {list(kwargs.keys())}!""" super().__init__(*args, wrong_num_args_msg=msg, **kwargs) if _to_cxx(self) is not None: return + # args + kwargs are o/w checked by super().__init__ above if len(args) == 2: if isinstance(args[1], _Presentation): - self.py_template_params = args[1].py_template_params + (rewriter,) + self.py_template_params = args[1].py_template_params + (rewriting_system, order) else: raise TypeError( f"expected the 2nd argument to be a Presentation, but found {type(args[1])}" diff --git a/tests/test_knuth_bendix.py b/tests/test_knuth_bendix.py index 19f5d08b4..913dc7d98 100644 --- a/tests/test_knuth_bendix.py +++ b/tests/test_knuth_bendix.py @@ -14,10 +14,11 @@ from _libsemigroups_pybind11 import Runner from libsemigroups_pybind11 import ( - LIMIT_MAX, - POSITIVE_INFINITY, KnuthBendix, + LIMIT_MAX, LibsemigroupsError, + Order, + POSITIVE_INFINITY, Presentation, ReportGuard, StringRange, @@ -32,8 +33,8 @@ def check_initialisation(*args): - for rewriter in ("LenLexSet", "LenLexTrie"): - kb = KnuthBendix(*args, rewriter=rewriter) + for rws in ("Set", "Trie"): + kb = KnuthBendix(*args, rewriting_system=rws) kb.run() @@ -61,9 +62,9 @@ def test_initialisation(): kb2.run() with pytest.raises(TypeError): - KnuthBendix(kb, rewriter="LenLexSet") + KnuthBendix(kb, rewriting_system="Set", order=Order.shortlex) - kb = KnuthBendix(kind, p, rewriter="LenLexSet") + kb = KnuthBendix(kind, p, rewriting_system="Set", order=Order.shortlex) def test_attributes(): @@ -340,6 +341,18 @@ def test_knuth_bendix_runner_state(): assert isinstance(kb.state(0), Runner.state) +def test_rpo(): + p = Presentation("ab") + p.contains_empty_word(True) + presentation.add_rule(p, "aa", "") + presentation.add_rule(p, "bbb", "") + presentation.add_rule(p, "ababab", "") + + kb = KnuthBendix(congruence_kind.twosided, p, order=Order.recursive) + kb.run() + assert list(kb.active_rules()) == [("bbb", ""), ("aa", ""), ("abb", "baba"), ("abab", "bba")] + + # TODO(0) Does the alphabet bug persist? YES: the test fails # def test_alphabet_bug(): # p = Presentation("".join(chr(i) for i in range(-126, 128))) From aaa775568b439037b033a175e750749e3f5af3fb Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Mon, 8 Jun 2026 14:14:53 +0100 Subject: [PATCH 5/6] to function: add support for reduction order --- src/froidure-pin.cpp | 9 ++ src/kbe.cpp | 12 ++ src/libsemigroups_pybind11/froidure_pin.py | 12 ++ src/libsemigroups_pybind11/knuth_bendix.py | 7 +- src/libsemigroups_pybind11/to.py | 25 +++- src/to-froidure-pin.cpp | 5 + src/to-knuth-bendix.cpp | 9 ++ src/to-presentation.cpp | 14 ++ src/to-todd-coxeter.cpp | 5 + tests/test_knuth_bendix.py | 4 +- tests/test_to.py | 153 ++++++++++++++++----- 11 files changed, 206 insertions(+), 49 deletions(-) diff --git a/src/froidure-pin.cpp b/src/froidure-pin.cpp index 0dbbb3560..2236b1612 100644 --- a/src/froidure-pin.cpp +++ b/src/froidure-pin.cpp @@ -1316,6 +1316,15 @@ This function returns the element of *fp* obtained by evaluating *w*. bind_froidure_pin_stateful>>( m, "KBEWordLenLexTrie"); + bind_froidure_pin_stateful>>( + m, "KBEStringRPOSet"); + bind_froidure_pin_stateful>>( + m, "KBEStringRPOTrie"); + bind_froidure_pin_stateful>>( + m, "KBEWordRPOSet"); + bind_froidure_pin_stateful>>( + m, "KBEWordRPOTrie"); + bind_froidure_pin_stateful>(m, "KEString"); bind_froidure_pin_stateful>>( m, "KEMultiViewString"); diff --git a/src/kbe.cpp b/src/kbe.cpp index f936ede25..96db52e62 100644 --- a/src/kbe.cpp +++ b/src/kbe.cpp @@ -78,6 +78,7 @@ namespace libsemigroups { using RPOTrie = detail::RewritingSystemTrie; using RPOSet = detail::RewritingSystemSet; + // LenLex using KBEStringLenLexTrie = detail::KBE>; using KBEWordLenLexTrie = detail::KBE>; @@ -88,5 +89,16 @@ namespace libsemigroups { bind_kbe(m, "KBEWordLenLexTrie"); bind_kbe(m, "KBEStringLenLexSet"); bind_kbe(m, "KBEWordLenLexSet"); + + // RPO + using KBEStringRPOTrie = detail::KBE>; + using KBEWordRPOTrie = detail::KBE>; + using KBEStringRPOSet = detail::KBE>; + using KBEWordRPOSet = detail::KBE>; + + bind_kbe(m, "KBEStringRPOTrie"); + bind_kbe(m, "KBEWordRPOTrie"); + bind_kbe(m, "KBEStringRPOSet"); + bind_kbe(m, "KBEWordRPOSet"); } } // namespace libsemigroups diff --git a/src/libsemigroups_pybind11/froidure_pin.py b/src/libsemigroups_pybind11/froidure_pin.py index 4aaffcdae..d892be0f6 100644 --- a/src/libsemigroups_pybind11/froidure_pin.py +++ b/src/libsemigroups_pybind11/froidure_pin.py @@ -28,8 +28,12 @@ FroidurePinIntMat as _FroidurePinIntMat, FroidurePinKBEStringLenLexSet as _FroidurePinKBEStringLenLexSet, FroidurePinKBEStringLenLexTrie as _FroidurePinKBEStringLenLexTrie, + FroidurePinKBEStringRPOSet as _FroidurePinKBEStringRPOSet, + FroidurePinKBEStringRPOTrie as _FroidurePinKBEStringRPOTrie, FroidurePinKBEWordLenLexSet as _FroidurePinKBEWordLenLexSet, FroidurePinKBEWordLenLexTrie as _FroidurePinKBEWordLenLexTrie, + FroidurePinKBEWordRPOSet as _FroidurePinKBEWordRPOSet, + FroidurePinKBEWordRPOTrie as _FroidurePinKBEWordRPOTrie, FroidurePinKEMultiViewString as _FroidurePinKEMultiViewString, FroidurePinKEString as _FroidurePinKEString, FroidurePinKEWord as _FroidurePinKEWord, @@ -53,8 +57,12 @@ IntMat as _IntMat, KBEStringLenLexSet as _KBEStringLenLexSet, KBEStringLenLexTrie as _KBEStringLenLexTrie, + KBEStringRPOSet as _KBEStringRPOSet, + KBEStringRPOTrie as _KBEStringRPOTrie, KBEWordLenLexSet as _KBEWordLenLexSet, KBEWordLenLexTrie as _KBEWordLenLexTrie, + KBEWordRPOSet as _KBEWordRPOSet, + KBEWordRPOTrie as _KBEWordRPOTrie, MaxPlusMat as _MaxPlusMat, MaxPlusTruncMat as _MaxPlusTruncMat, MinPlusMat as _MinPlusMat, @@ -149,6 +157,10 @@ class FroidurePin(_CxxWrapper): (_KBEStringLenLexSet,): _FroidurePinKBEStringLenLexSet, (_KBEWordLenLexTrie,): _FroidurePinKBEWordLenLexTrie, (_KBEWordLenLexSet,): _FroidurePinKBEWordLenLexSet, + (_KBEStringRPOTrie,): _FroidurePinKBEStringRPOTrie, + (_KBEStringRPOSet,): _FroidurePinKBEStringRPOSet, + (_KBEWordRPOTrie,): _FroidurePinKBEWordRPOTrie, + (_KBEWordRPOSet,): _FroidurePinKBEWordRPOSet, } | ( { (_HPCombiPTransf16,): _FroidurePinHPCombiPTransf16, diff --git a/src/libsemigroups_pybind11/knuth_bendix.py b/src/libsemigroups_pybind11/knuth_bendix.py index 8313c66a4..48f11f825 100644 --- a/src/libsemigroups_pybind11/knuth_bendix.py +++ b/src/libsemigroups_pybind11/knuth_bendix.py @@ -14,10 +14,10 @@ from _libsemigroups_pybind11 import ( KnuthBendixStringLenLexSet as _KnuthBendixStringLenLexSet, KnuthBendixStringLenLexTrie as _KnuthBendixStringLenLexTrie, - KnuthBendixWordLenLexSet as _KnuthBendixWordLenLexSet, - KnuthBendixWordLenLexTrie as _KnuthBendixWordLenLexTrie, KnuthBendixStringRPOSet as _KnuthBendixStringRPOSet, KnuthBendixStringRPOTrie as _KnuthBendixStringRPOTrie, + KnuthBendixWordLenLexSet as _KnuthBendixWordLenLexSet, + KnuthBendixWordLenLexTrie as _KnuthBendixWordLenLexTrie, KnuthBendixWordRPOSet as _KnuthBendixWordRPOSet, KnuthBendixWordRPOTrie as _KnuthBendixWordRPOTrie, Order as _Order, @@ -84,8 +84,9 @@ def __init__(self, *args, rewriting_system="Trie", order=_Order.shortlex, **kwar 2, ) if kwargs["rewriter"] not in ("RewriteFromLeft", "RewriteTrie"): + rewriter = kwargs["rewriter"] raise TypeError( - f'expected the keyword argument "rewriter" to be ' + 'expected the keyword argument "rewriter" to be ' f'"RewriteFromLeft" or "RewriteTrie", but found "{rewriter}"' ) if kwargs["rewriter"] == "RewriteFromLeft": diff --git a/src/libsemigroups_pybind11/to.py b/src/libsemigroups_pybind11/to.py index 947ca213d..09fb37647 100644 --- a/src/libsemigroups_pybind11/to.py +++ b/src/libsemigroups_pybind11/to.py @@ -11,6 +11,7 @@ from typing import _GenericAlias from _libsemigroups_pybind11 import ( + Order as _Order, to_congruence_string as _to_congruence_string, to_congruence_word as _to_congruence_word, to_froidure_pin as _to_froidure_pin, @@ -20,10 +21,16 @@ to_knuth_bendix as _to_knuth_bendix, to_knuth_bendix_LenLexSet as _to_knuth_bendix_LenLexSet, to_knuth_bendix_LenLexTrie as _to_knuth_bendix_LenLexTrie, + to_knuth_bendix_RPOSet as _to_knuth_bendix_RPOSet, + to_knuth_bendix_RPOTrie as _to_knuth_bendix_RPOTrie, to_knuth_bendix_string_LenLexSet as _to_knuth_bendix_string_LenLexSet, to_knuth_bendix_string_LenLexTrie as _to_knuth_bendix_string_LenLexTrie, + to_knuth_bendix_string_RPOSet as _to_knuth_bendix_string_RPOSet, + to_knuth_bendix_string_RPOTrie as _to_knuth_bendix_string_RPOTrie, to_knuth_bendix_word_LenLexSet as _to_knuth_bendix_word_LenLexSet, to_knuth_bendix_word_LenLexTrie as _to_knuth_bendix_word_LenLexTrie, + to_knuth_bendix_word_RPOSet as _to_knuth_bendix_word_RPOSet, + to_knuth_bendix_word_RPOTrie as _to_knuth_bendix_word_RPOTrie, to_presentation as _to_presentation, to_presentation_string as _to_presentation_string, to_presentation_word as _to_presentation_word, @@ -69,12 +76,18 @@ def _nice_name(type_list): (_InversePresentation, list[int]): _to_inverse_presentation_word, (_InversePresentation, str): _to_inverse_presentation_string, (_KnuthBendix,): _to_knuth_bendix, - (_KnuthBendix, "LenLexTrie"): _to_knuth_bendix_LenLexTrie, - (_KnuthBendix, "LenLexSet"): _to_knuth_bendix_LenLexSet, - (_KnuthBendix, list[int], "LenLexSet"): _to_knuth_bendix_word_LenLexSet, - (_KnuthBendix, list[int], "LenLexTrie"): _to_knuth_bendix_word_LenLexTrie, - (_KnuthBendix, str, "LenLexSet"): _to_knuth_bendix_string_LenLexSet, - (_KnuthBendix, str, "LenLexTrie"): _to_knuth_bendix_string_LenLexTrie, + (_KnuthBendix, "Set", _Order.shortlex): _to_knuth_bendix_LenLexSet, + (_KnuthBendix, "Trie", _Order.shortlex): _to_knuth_bendix_LenLexTrie, + (_KnuthBendix, list[int], "Set", _Order.shortlex): _to_knuth_bendix_word_LenLexSet, + (_KnuthBendix, list[int], "Trie", _Order.shortlex): _to_knuth_bendix_word_LenLexTrie, + (_KnuthBendix, str, "Set", _Order.shortlex): _to_knuth_bendix_string_LenLexSet, + (_KnuthBendix, str, "Trie", _Order.shortlex): _to_knuth_bendix_string_LenLexTrie, + (_KnuthBendix, "Set", _Order.recursive): _to_knuth_bendix_RPOSet, + (_KnuthBendix, "Trie", _Order.recursive): _to_knuth_bendix_RPOTrie, + (_KnuthBendix, list[int], "Set", _Order.recursive): _to_knuth_bendix_word_RPOSet, + (_KnuthBendix, list[int], "Trie", _Order.recursive): _to_knuth_bendix_word_RPOTrie, + (_KnuthBendix, str, "Set", _Order.recursive): _to_knuth_bendix_string_RPOSet, + (_KnuthBendix, str, "Trie", _Order.recursive): _to_knuth_bendix_string_RPOTrie, (_Presentation,): _to_presentation, (_Presentation, str): _to_presentation_string, (_Presentation, list[int]): _to_presentation_word, diff --git a/src/to-froidure-pin.cpp b/src/to-froidure-pin.cpp index d69fb51ff..4c7f557fc 100644 --- a/src/to-froidure-pin.cpp +++ b/src/to-froidure-pin.cpp @@ -72,6 +72,11 @@ namespace libsemigroups { bind_to_froidure_pin>(m); bind_to_froidure_pin>(m); + bind_to_froidure_pin>(m); + bind_to_froidure_pin>(m); + bind_to_froidure_pin>(m); + bind_to_froidure_pin>(m); + // ToddCoxeter bind_to_froidure_pin>(m); bind_to_froidure_pin>(m); diff --git a/src/to-knuth-bendix.cpp b/src/to-knuth-bendix.cpp index 89dd0aa77..8c420a94e 100644 --- a/src/to-knuth-bendix.cpp +++ b/src/to-knuth-bendix.cpp @@ -79,12 +79,21 @@ namespace libsemigroups { "word_LenLexSet"); bind_froidure_pin_to_knuth_bendix(m, "word_LenLexTrie"); + bind_froidure_pin_to_knuth_bendix(m, "string_RPOSet"); + bind_froidure_pin_to_knuth_bendix(m, + "string_RPOTrie"); + bind_froidure_pin_to_knuth_bendix(m, "word_RPOSet"); + bind_froidure_pin_to_knuth_bendix(m, "word_RPOTrie"); // ToddCoxeter + rewriter bind_todd_coxeter_to_knuth_bendix(m, "LenLexSet"); bind_todd_coxeter_to_knuth_bendix(m, "LenLexSet"); bind_todd_coxeter_to_knuth_bendix(m, "LenLexTrie"); bind_todd_coxeter_to_knuth_bendix(m, "LenLexTrie"); + bind_todd_coxeter_to_knuth_bendix(m, "RPOSet"); + bind_todd_coxeter_to_knuth_bendix(m, "RPOSet"); + bind_todd_coxeter_to_knuth_bendix(m, "RPOTrie"); + bind_todd_coxeter_to_knuth_bendix(m, "RPOTrie"); // ToddCoxeter bind_todd_coxeter_to_knuth_bendix_default(m); diff --git a/src/to-presentation.cpp b/src/to-presentation.cpp index 4ddd4aa43..3103d439e 100644 --- a/src/to-presentation.cpp +++ b/src/to-presentation.cpp @@ -227,6 +227,20 @@ namespace libsemigroups { bind_kb_to_pres_with_word(m, "word"); bind_kb_to_pres_with_word(m, "word"); + bind_kb_to_pres(m); + bind_kb_to_pres(m); + bind_kb_to_pres(m); + bind_kb_to_pres(m); + + bind_kb_to_pres_with_word(m, "string"); + bind_kb_to_pres_with_word(m, "string"); + bind_kb_to_pres_with_word(m, "string"); + bind_kb_to_pres_with_word(m, "string"); + bind_kb_to_pres_with_word(m, "word"); + bind_kb_to_pres_with_word(m, "word"); + bind_kb_to_pres_with_word(m, "word"); + bind_kb_to_pres_with_word(m, "word"); + // From FroidurePin bind_fp_to_pres(m, "string"); bind_fp_to_pres(m, "word"); diff --git a/src/to-todd-coxeter.cpp b/src/to-todd-coxeter.cpp index 4a245d72f..9ee2a46e0 100644 --- a/src/to-todd-coxeter.cpp +++ b/src/to-todd-coxeter.cpp @@ -62,6 +62,11 @@ namespace libsemigroups { bind_to_todd_coxeter_kb(m); bind_to_todd_coxeter_kb(m); + bind_to_todd_coxeter_kb(m); + bind_to_todd_coxeter_kb(m); + bind_to_todd_coxeter_kb(m); + bind_to_todd_coxeter_kb(m); + // WordGraph m.def("to_todd_coxeter_word", [](congruence_kind knd, diff --git a/tests/test_knuth_bendix.py b/tests/test_knuth_bendix.py index 913dc7d98..505dc4998 100644 --- a/tests/test_knuth_bendix.py +++ b/tests/test_knuth_bendix.py @@ -14,11 +14,11 @@ from _libsemigroups_pybind11 import Runner from libsemigroups_pybind11 import ( - KnuthBendix, LIMIT_MAX, + POSITIVE_INFINITY, + KnuthBendix, LibsemigroupsError, Order, - POSITIVE_INFINITY, Presentation, ReportGuard, StringRange, diff --git a/tests/test_to.py b/tests/test_to.py index 778088933..8fd2d966d 100644 --- a/tests/test_to.py +++ b/tests/test_to.py @@ -4,7 +4,7 @@ # # The full license is in the file LICENSE, distributed with this software. -# pylint: disable=missing-function-docstring, invalid-name +# pylint: disable=missing-function-docstring, invalid-name, too-many-lines """This module contains some tests for the to function.""" @@ -15,8 +15,12 @@ from _libsemigroups_pybind11 import ( FroidurePinKBEStringLenLexSet, FroidurePinKBEStringLenLexTrie, + FroidurePinKBEStringRPOSet, + FroidurePinKBEStringRPOTrie, FroidurePinKBEWordLenLexSet, FroidurePinKBEWordLenLexTrie, + FroidurePinKBEWordRPOSet, + FroidurePinKBEWordRPOTrie, FroidurePinKEMultiViewString, FroidurePinKEString, FroidurePinKEWord, @@ -31,6 +35,7 @@ InversePresentation, Kambites, KnuthBendix, + Order, Presentation, ReportGuard, Stephen, @@ -74,12 +79,12 @@ def sample_to_int(x): def sample_froidure_pin(): - b1 = Bipartition([[1, -1], [2, -2], [3, -3], [4, -4]]) - b2 = Bipartition([[1, -2], [2, -3], [3, -4], [4, -1]]) - b3 = Bipartition([[1, -2], [2, -1], [3, -3], [4, -4]]) - b4 = Bipartition([[1, 2], [3, -3], [4, -4], [-1, -2]]) - S = FroidurePin(b1, b2, b3, b4) - return S + return FroidurePin( + Bipartition([[1, -1], [2, -2], [3, -3], [4, -4]]), + Bipartition([[1, -2], [2, -3], [3, -4], [4, -1]]), + Bipartition([[1, -2], [2, -1], [3, -3], [4, -4]]), + Bipartition([[1, 2], [3, -3], [4, -4], [-1, -2]]), + ) def sample_kambites_from_pres(Word): @@ -127,9 +132,9 @@ def check_cong_to_todd_coxeter(Type, Word, **kwargs): return tc -def check_knuth_bendix_to_pres(WordIn, WordOut, Rewriter): +def check_knuth_bendix_to_pres(WordIn, WordOut, Rewriter, ROrder): p = sample_pres(WordIn) - kb = KnuthBendix(congruence_kind.twosided, p, rewriter=Rewriter) + kb = KnuthBendix(congruence_kind.twosided, p, rewriting_system=Rewriter, order=ROrder) q = to(kb, rtype=(Presentation, WordOut)) assert len(q.rules) == kb.number_of_active_rules() * 2 @@ -193,16 +198,16 @@ def check_stephen_to_pres(PresType, WordIn, WordOut): assert len(p.rules) == len(s_pres.rules) -def check_froidure_pin_to_knuth_bendix(Word, Rewriter): +def check_froidure_pin_to_knuth_bendix(Word, RewritingSystem, ROrder): S = sample_froidure_pin() - kb = to(congruence_kind.twosided, S, rtype=(KnuthBendix, Word, Rewriter)) + kb = to(congruence_kind.twosided, S, rtype=(KnuthBendix, Word, RewritingSystem, ROrder)) assert S.size() == kb.number_of_classes() return kb -def check_todd_coxeter_to_knuth_bendix(Word, Rewriter): +def check_todd_coxeter_to_knuth_bendix(Word, RewritingSystem, ROrder): tc = cong_from_sample_pres(ToddCoxeter, Word) - kb = to(congruence_kind.twosided, tc, rtype=(KnuthBendix, Rewriter)) + kb = to(congruence_kind.twosided, tc, rtype=(KnuthBendix, RewritingSystem, ROrder)) assert kb.number_of_classes() == tc.number_of_classes() return kb @@ -230,24 +235,40 @@ def check_froidure_pin_to_congruence(Word): def test_to_FroidurePin_000(): - fp = check_cong_to_froidure_pin(KnuthBendix, str, rewriter="LenLexSet") + fp = check_cong_to_froidure_pin(KnuthBendix, str, rewriting_system="Set", order=Order.shortlex) assert isinstance(to_cxx(fp), FroidurePinKBEStringLenLexSet) + fp = check_cong_to_froidure_pin(KnuthBendix, str, rewriting_system="Set", order=Order.recursive) + assert isinstance(to_cxx(fp), FroidurePinKBEStringRPOSet) + def test_to_FroidurePin_001(): - fp = check_cong_to_froidure_pin(KnuthBendix, str, rewriter="LenLexTrie") + fp = check_cong_to_froidure_pin(KnuthBendix, str, rewriting_system="Trie", order=Order.shortlex) assert isinstance(to_cxx(fp), FroidurePinKBEStringLenLexTrie) + fp = check_cong_to_froidure_pin( + KnuthBendix, str, rewriting_system="Trie", order=Order.recursive + ) + assert isinstance(to_cxx(fp), FroidurePinKBEStringRPOTrie) + def test_to_FroidurePin_002(): - fp = check_cong_to_froidure_pin(KnuthBendix, int, rewriter="LenLexSet") + fp = check_cong_to_froidure_pin(KnuthBendix, int, rewriting_system="Set", order=Order.shortlex) assert isinstance(to_cxx(fp), FroidurePinKBEWordLenLexSet) + fp = check_cong_to_froidure_pin(KnuthBendix, int, rewriting_system="Set", order=Order.recursive) + assert isinstance(to_cxx(fp), FroidurePinKBEWordRPOSet) + def test_to_FroidurePin_003(): - fp = check_cong_to_froidure_pin(KnuthBendix, int, rewriter="LenLexTrie") + fp = check_cong_to_froidure_pin(KnuthBendix, int, rewriting_system="Trie", order=Order.shortlex) assert isinstance(to_cxx(fp), FroidurePinKBEWordLenLexTrie) + fp = check_cong_to_froidure_pin( + KnuthBendix, int, rewriting_system="Trie", order=Order.recursive + ) + assert isinstance(to_cxx(fp), FroidurePinKBEWordRPOTrie) + # From ToddCoxeter @@ -357,25 +378,45 @@ def test_to_FroidurePin_013(): def test_to_ToddCoxeter_014(): - tc = check_cong_to_todd_coxeter(KnuthBendix, str, rewriter="LenLexSet") + tc = check_cong_to_todd_coxeter(KnuthBendix, str, rewriting_system="Set", order=Order.shortlex) + assert isinstance(tc, ToddCoxeter) + assert tc.py_template_params == (str,) + + tc = check_cong_to_todd_coxeter(KnuthBendix, str, rewriting_system="Set", order=Order.recursive) assert isinstance(tc, ToddCoxeter) assert tc.py_template_params == (str,) def test_to_ToddCoxeter_015(): - tc = check_cong_to_todd_coxeter(KnuthBendix, str, rewriter="LenLexTrie") + tc = check_cong_to_todd_coxeter(KnuthBendix, str, rewriting_system="Trie", order=Order.shortlex) + assert isinstance(tc, ToddCoxeter) + assert tc.py_template_params == (str,) + + tc = check_cong_to_todd_coxeter( + KnuthBendix, str, rewriting_system="Trie", order=Order.recursive + ) assert isinstance(tc, ToddCoxeter) assert tc.py_template_params == (str,) def test_to_ToddCoxeter_016(): - tc = check_cong_to_todd_coxeter(KnuthBendix, int, rewriter="LenLexSet") + tc = check_cong_to_todd_coxeter(KnuthBendix, int, rewriting_system="Set", order=Order.shortlex) + assert isinstance(tc, ToddCoxeter) + assert tc.py_template_params == (list[int],) + + tc = check_cong_to_todd_coxeter(KnuthBendix, int, rewriting_system="Set", order=Order.recursive) assert isinstance(tc, ToddCoxeter) assert tc.py_template_params == (list[int],) def test_to_ToddCoxeter_017(): - tc = check_cong_to_todd_coxeter(KnuthBendix, int, rewriter="LenLexTrie") + tc = check_cong_to_todd_coxeter(KnuthBendix, int, rewriting_system="Trie", order=Order.shortlex) + assert isinstance(tc, ToddCoxeter) + assert tc.py_template_params == (list[int],) + + tc = check_cong_to_todd_coxeter( + KnuthBendix, int, rewriting_system="Trie", order=Order.recursive + ) assert isinstance(tc, ToddCoxeter) assert tc.py_template_params == (list[int],) @@ -641,23 +682,31 @@ def test_to_Presentation_023(): def test_to_Presentation_024(): - check_knuth_bendix_to_pres(str, str, "LenLexSet") - check_knuth_bendix_to_pres(str, list[int], "LenLexSet") + check_knuth_bendix_to_pres(str, str, "Set", Order.shortlex) + check_knuth_bendix_to_pres(str, list[int], "Set", Order.shortlex) + check_knuth_bendix_to_pres(str, str, "Set", Order.recursive) + check_knuth_bendix_to_pres(str, list[int], "Set", Order.recursive) def test_to_Presentation_025(): - check_knuth_bendix_to_pres(str, str, "LenLexTrie") - check_knuth_bendix_to_pres(str, list[int], "LenLexTrie") + check_knuth_bendix_to_pres(str, str, "Trie", Order.shortlex) + check_knuth_bendix_to_pres(str, list[int], "Trie", Order.shortlex) + check_knuth_bendix_to_pres(str, str, "Trie", Order.recursive) + check_knuth_bendix_to_pres(str, list[int], "Trie", Order.recursive) def test_to_Presentation_026(): - check_knuth_bendix_to_pres(list[int], str, "LenLexSet") - check_knuth_bendix_to_pres(list[int], list[int], "LenLexSet") + check_knuth_bendix_to_pres(list[int], str, "Set", Order.shortlex) + check_knuth_bendix_to_pres(list[int], list[int], "Set", Order.shortlex) + check_knuth_bendix_to_pres(list[int], str, "Set", Order.recursive) + check_knuth_bendix_to_pres(list[int], list[int], "Set", Order.recursive) def test_to_Presentation_027(): - check_knuth_bendix_to_pres(list[int], str, "LenLexTrie") - check_knuth_bendix_to_pres(list[int], list[int], "LenLexTrie") + check_knuth_bendix_to_pres(list[int], str, "Trie", Order.shortlex) + check_knuth_bendix_to_pres(list[int], list[int], "Trie", Order.shortlex) + check_knuth_bendix_to_pres(list[int], str, "Trie", Order.recursive) + check_knuth_bendix_to_pres(list[int], list[int], "Trie", Order.recursive) # From FroidurePin @@ -838,46 +887,74 @@ def test_to_InversePresentation_048(): def test_to_KnuthBendix_049(): - kb = check_froidure_pin_to_knuth_bendix(str, "LenLexSet") + kb = check_froidure_pin_to_knuth_bendix(str, "Set", Order.shortlex) + assert isinstance(kb, KnuthBendix) + assert kb.py_template_params == (str, "Set", Order.shortlex) + + kb = check_froidure_pin_to_knuth_bendix(str, "Set", Order.recursive) assert isinstance(kb, KnuthBendix) - assert kb.py_template_params == (str, "LenLexSet") + assert kb.py_template_params == (str, "Set", Order.recursive) def test_to_KnuthBendix_050(): - kb = check_froidure_pin_to_knuth_bendix(str, "LenLexTrie") + kb = check_froidure_pin_to_knuth_bendix(str, "Trie", Order.shortlex) assert isinstance(kb, KnuthBendix) + kb = check_froidure_pin_to_knuth_bendix(str, "Trie", Order.recursive) + assert isinstance(kb, KnuthBendix) + assert kb.py_template_params == (str, "Trie", Order.recursive) + def test_to_KnuthBendix_051(): - kb = check_froidure_pin_to_knuth_bendix(list[int], "LenLexSet") + kb = check_froidure_pin_to_knuth_bendix(list[int], "Set", Order.shortlex) assert isinstance(kb, KnuthBendix) + kb = check_froidure_pin_to_knuth_bendix(list[int], "Set", Order.recursive) + assert isinstance(kb, KnuthBendix) + assert kb.py_template_params == (list[int], "Set", Order.recursive) + def test_to_KnuthBendix_052(): - kb = check_froidure_pin_to_knuth_bendix(list[int], "LenLexTrie") + kb = check_froidure_pin_to_knuth_bendix(list[int], "Trie", Order.shortlex) assert isinstance(kb, KnuthBendix) + kb = check_froidure_pin_to_knuth_bendix(list[int], "Trie", Order.recursive) + assert isinstance(kb, KnuthBendix) + assert kb.py_template_params == (list[int], "Trie", Order.recursive) + # From ToddCoxeter + Rewriter def test_to_KnuthBendix_053(): - kb = check_todd_coxeter_to_knuth_bendix(str, "LenLexSet") + kb = check_todd_coxeter_to_knuth_bendix(str, "Set", Order.shortlex) + assert isinstance(kb, KnuthBendix) + + kb = check_todd_coxeter_to_knuth_bendix(str, "Set", Order.recursive) assert isinstance(kb, KnuthBendix) def test_to_KnuthBendix_054(): - kb = check_todd_coxeter_to_knuth_bendix(str, "LenLexTrie") + kb = check_todd_coxeter_to_knuth_bendix(str, "Trie", Order.shortlex) + assert isinstance(kb, KnuthBendix) + + kb = check_todd_coxeter_to_knuth_bendix(str, "Trie", Order.recursive) assert isinstance(kb, KnuthBendix) def test_to_KnuthBendix_055(): - kb = check_todd_coxeter_to_knuth_bendix(list[int], "LenLexSet") + kb = check_todd_coxeter_to_knuth_bendix(list[int], "Set", Order.shortlex) + assert isinstance(kb, KnuthBendix) + + kb = check_todd_coxeter_to_knuth_bendix(list[int], "Set", Order.recursive) assert isinstance(kb, KnuthBendix) def test_to_KnuthBendix_056(): - kb = check_todd_coxeter_to_knuth_bendix(list[int], "LenLexTrie") + kb = check_todd_coxeter_to_knuth_bendix(list[int], "Trie", Order.shortlex) + assert isinstance(kb, KnuthBendix) + + kb = check_todd_coxeter_to_knuth_bendix(list[int], "Trie", Order.recursive) assert isinstance(kb, KnuthBendix) From 68b7e608336898646a2c61ba67ab69d8dbea95a6 Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Mon, 8 Jun 2026 15:07:08 +0100 Subject: [PATCH 6/6] knuth-bendix: adjust doc --- .../knuth-bendix/to-knuth-bendix.rst | 58 ++++++++++++------- src/knuth-bendix.cpp | 7 ++- src/libsemigroups_pybind11/knuth_bendix.py | 1 + src/libsemigroups_pybind11/to.py | 1 + 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst b/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst index a6b33f589..312186597 100644 --- a/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst +++ b/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst @@ -5,8 +5,6 @@ The full license is in the file LICENSE, distributed with this software. -.. TODO update - .. currentmodule:: libsemigroups_pybind11 Converting to a KnuthBendix @@ -35,8 +33,8 @@ possible: .. _todd-coxeter-to-knuth-bendix-default: -Converting a :any:`ToddCoxeter` to a :any:`KnuthBendix` (default rewriter) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Converting a :any:`ToddCoxeter` to a :any:`KnuthBendix` (default rewriting system and order) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To construct a :any:`KnuthBendix` from a :any:`ToddCoxeter` using the default rewriter, specify all of the following values for *args*: @@ -99,12 +97,19 @@ following values for *args*: - **tc** (:any:`ToddCoxeter`) -- the :any:`ToddCoxeter` object being converted. -Additionally, specify one of the following for *rtype*: +Additionally, specify *rtype* to be a tuple with first item :any:`KnuthBendix`, second item one of + + - ``'Trie'`` for constructing a :any:`KnuthBendix` + with a trie based rewriting system. + - ``'Set'`` for constructing a :any:`KnuthBendix` + with a set based rewriting system. - - ``(KnuthBendix, 'RewriteTrie')`` for constructing a :any:`KnuthBendix` - with the ``RewriteTrie`` rewriter. - - ``(KnuthBendix, 'RewriteFromLeft')`` for constructing a :any:`KnuthBendix` - with the ``RewriteFromLeft`` rewriter. +and the third item one of: + + - :any:`Order.shortlex` for constructing a :any:`KnuthBendix` + with short-lex reduction ordering. + - :any:`Order.recursive` for constructing a :any:`KnuthBendix` + with recursive path reduction ordering. This function converts a :any:`ToddCoxeter` object *tc* to a :any:`KnuthBendix` object with the rewriter as specified above, using @@ -119,6 +124,7 @@ the semigroup defined by *tc*. ... congruence_kind, ... to, ... KnuthBendix, + ... Order, ... Presentation, ... presentation, ... ToddCoxeter, @@ -134,7 +140,7 @@ the semigroup defined by *tc*. >>> kb = to( ... congruence_kind.twosided, # knd ... tc, # tc - ... rtype=(KnuthBendix, 'RewriteFromLeft') + ... rtype=(KnuthBendix, 'Set', Order.shortlex) ... ) >>> kb.run() @@ -156,18 +162,30 @@ following values for *args*: Additionally, specify one of the following for *rtype*: - - ``(KnuthBendix, str, 'RewriteTrie')`` for constructing a - :any:`KnuthBendix` on words with type ``str`` using the ``RewriteTrie`` - rewriter. - - ``(KnuthBendix, list[int], 'RewriteTrie')`` for constructing a + - ``(KnuthBendix, str, 'Trie', Order.shortlex)`` for constructing a + :any:`KnuthBendix` on words with type ``str`` using the + trie based rewriting system and short-lex reduction ordering. + - ``(KnuthBendix, list[int], 'Trie', Order.shortlex)`` for constructing a :any:`KnuthBendix` on words with type ``list[int]`` using the - ``RewriteTrie`` rewriter. - - ``(KnuthBendix, str, 'RewriteFromLeft')`` for constructing a + trie based rewriting system and short-lex reduction ordering. + - ``(KnuthBendix, str, 'Set', Order.shortlex)`` for constructing a + :any:`KnuthBendix` on words with type ``str`` using a set based rewriting + system and short-lex reduction ordering. + - ``(KnuthBendix, list[int], 'Set', Order.shortlex)`` for constructing a + :any:`KnuthBendix` on words with type ``list[int]`` using a set based + rewriting system and short-lex reduction ordering. + - ``(KnuthBendix, str, 'Trie', Order.recursive)`` for constructing a :any:`KnuthBendix` on words with type ``str`` using the - ``RewriteFromLeft`` rewriter. - - ``(KnuthBendix, list[int], 'RewriteFromLeft')`` for constructing a + trie based rewriting system and recursive path reduction ordering. + - ``(KnuthBendix, list[int], 'Trie', Order.recursive)`` for constructing a :any:`KnuthBendix` on words with type ``list[int]`` using the - ``RewriteFromLeft`` rewriter. + trie based rewriting system and recursive path reduction ordering. + - ``(KnuthBendix, str, 'Set', Order.recursive)`` for constructing a + :any:`KnuthBendix` on words with type ``str`` using a set based rewriting + system and recursive path reduction ordering. + - ``(KnuthBendix, list[int], 'Set', Order.recursive)`` for constructing a + :any:`KnuthBendix` on words with type ``list[int]`` using a set based + rewriting system and short-lex reduction ordering. This function converts a :any:`FroidurePin` object *fpb* to a :any:`KnuthBendix` object with the word type and rewriter as specified above. This is done using @@ -198,7 +216,7 @@ the semigroup defined by *fpb*. >>> kb = to( ... congruence_kind.twosided, # knd ... S, # tc - ... rtype=(KnuthBendix, list[int], 'RewriteFromLeft') + ... rtype=(KnuthBendix, list[int], 'Set', Order.recursive) ... ) >>> kb.run() diff --git a/src/knuth-bendix.cpp b/src/knuth-bendix.cpp index 2ec9cf00a..71c3d584f 100644 --- a/src/knuth-bendix.cpp +++ b/src/knuth-bendix.cpp @@ -87,9 +87,10 @@ nested class :any:`KnuthBendix.options`. def_construct_default( thing, "KnuthBendix", - // TODO update - doc{.extra_kwargs = ", rewriter: str", .extra_kwargs_doc = R"pbdoc( - * **rewriter** (*str*) -- the type of rewriter to use, must be either ``"RewriteTrie"`` or ``"RewriteFromLeft"``.)pbdoc"sv}); + doc{.extra_kwargs = ", rewriting_system: str, order: Order", + .extra_kwargs_doc = R"pbdoc( + * **rewriting_system** (*str*) -- the type of rewriting system to use, must be either ``"Trie"`` or ``"Set"``. + * **order** (*Order*) -- the reduction ordering to use, must be either :any:`Order.shortlex` or :any:`Order.recursive`.)pbdoc"sv}); def_init_default(thing, "KnuthBendix"); def_construct_kind_presentation(thing, "KnuthBendix"); diff --git a/src/libsemigroups_pybind11/knuth_bendix.py b/src/libsemigroups_pybind11/knuth_bendix.py index 48f11f825..856835dcd 100644 --- a/src/libsemigroups_pybind11/knuth_bendix.py +++ b/src/libsemigroups_pybind11/knuth_bendix.py @@ -75,6 +75,7 @@ class KnuthBendix(_CongruenceCommon): @_copydoc(_KnuthBendixStringLenLexTrie.__init__) def __init__(self, *args, rewriting_system="Trie", order=_Order.shortlex, **kwargs) -> None: if "rewriter" in kwargs: + # TODO(v2) remove this entire if-statement warn( 'The keyword argument "rewriter" is deprecated, please use a combination ' 'of "rewriting_system" and "order" instead. If you also specified the ' diff --git a/src/libsemigroups_pybind11/to.py b/src/libsemigroups_pybind11/to.py index 09fb37647..7a1c71cf7 100644 --- a/src/libsemigroups_pybind11/to.py +++ b/src/libsemigroups_pybind11/to.py @@ -47,6 +47,7 @@ from .todd_coxeter import ToddCoxeter as _ToddCoxeter +# FIXME this function converts list[int] -> list, but shouldn't def _nice_name(type_list): """Convert an iterable of type-like things into a string""" single_element = False