diff --git a/build_tools/__init__.py b/build_tools/__init__.py index 2732eb1c..3babec7d 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/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst b/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst index be6870a3..31218659 100644 --- a/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst +++ b/docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst @@ -33,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*: @@ -97,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. + +and the third item one of: - - ``(KnuthBendix, 'RewriteTrie')`` for constructing a :any:`KnuthBendix` - with the ``RewriteTrie`` rewriter. - - ``(KnuthBendix, 'RewriteFromLeft')`` for constructing a :any:`KnuthBendix` - with the ``RewriteFromLeft`` rewriter. + - :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 @@ -117,6 +124,7 @@ the semigroup defined by *tc*. ... congruence_kind, ... to, ... KnuthBendix, + ... Order, ... Presentation, ... presentation, ... ToddCoxeter, @@ -132,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() @@ -154,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 @@ -196,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/cong-common.cpp b/src/cong-common.cpp index b74f593f..7420166c 100644 --- a/src/cong-common.cpp +++ b/src/cong-common.cpp @@ -40,19 +40,24 @@ 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; + + using KnuthBendixStringRPOTrie = KnuthBendix; + using KnuthBendixStringRPOSet = KnuthBendix; + using KnuthBendixWordRPOTrie = KnuthBendix; + using KnuthBendixWordRPOSet = KnuthBendix; //////////////////////////////////////////////////////////////////////// // Implementation helpers @@ -128,19 +133,32 @@ 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(detail::KnuthBendixImpl, + detail::CongruenceCommon); + DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl, + detail::CongruenceCommon); + + 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(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); @@ -188,19 +206,27 @@ 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(detail::KnuthBendixImpl, detail::CongruenceCommon); + DEF_INIT_DEFAULT(detail::KnuthBendixImpl, detail::CongruenceCommon); + + 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(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); @@ -262,19 +288,33 @@ 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, + detail::CongruenceCommon); + + 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(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(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); @@ -339,19 +379,33 @@ 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(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); @@ -396,15 +450,21 @@ 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(KnuthBendixStringLenLexTrie, detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixStringLenLexSet, detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl); + DEF_COPY(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); - DEF_COPY(KnuthBendixStringRewriteTrie, detail::KnuthBendixImpl); - DEF_COPY(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_COPY(KnuthBendixWordRewriteTrie, detail::KnuthBendixImpl); - DEF_COPY(KnuthBendixWordRewriteFromLeft, - 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); @@ -457,9 +517,14 @@ 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, + detail::CongruenceCommon); + + 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 +596,33 @@ 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(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); @@ -614,19 +693,33 @@ 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(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); @@ -690,18 +783,22 @@ 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(KnuthBendixStringLenLexTrie, + detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixStringLenLexSet, detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl); + DEF_CONTAINS(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); - DEF_CONTAINS(KnuthBendixStringRewriteTrie, - detail::KnuthBendixImpl); - DEF_CONTAINS(KnuthBendixStringRewriteFromLeft, - detail::KnuthBendixImpl); - DEF_CONTAINS(KnuthBendixWordRewriteTrie, - detail::KnuthBendixImpl); - DEF_CONTAINS(KnuthBendixWordRewriteFromLeft, - 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); @@ -762,19 +859,27 @@ 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(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); @@ -836,17 +941,21 @@ 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(KnuthBendixStringLenLexTrie, detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixStringLenLexSet, detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl); + DEF_REDUCE(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl); + + 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(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); @@ -897,14 +1006,22 @@ 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(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); @@ -956,14 +1073,19 @@ 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(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); @@ -1028,10 +1150,15 @@ 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(KnuthBendixStringRPOTrie); + DEF_PARTITION(KnuthBendixStringRPOSet); + DEF_PARTITION(KnuthBendixWordRPOTrie); + DEF_PARTITION(KnuthBendixWordRPOSet); DEF_PARTITION(Congruence); DEF_PARTITION(Congruence); @@ -1095,10 +1222,15 @@ 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(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); @@ -1158,10 +1290,15 @@ 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); + + 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); diff --git a/src/froidure-pin.cpp b/src/froidure-pin.cpp index bd61e0f1..2236b161 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,24 @@ 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, "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>>( diff --git a/src/kbe.cpp b/src/kbe.cpp index 4e4d02c8..96db52e6 100644 --- a/src/kbe.cpp +++ b/src/kbe.cpp @@ -73,18 +73,32 @@ 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; + + // LenLex + 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"); + + // 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/knuth-bendix-impl.cpp b/src/knuth-bendix-impl.cpp index a6a9d01c..f93bcf04 100644 --- a/src/knuth-bendix-impl.cpp +++ b/src/knuth-bendix-impl.cpp @@ -507,9 +507,17 @@ 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"); + + 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 b5f9fa48..71c3d584 100644 --- a/src/knuth-bendix.cpp +++ b/src/knuth-bendix.cpp @@ -87,8 +87,10 @@ nested class :any:`KnuthBendix.options`. def_construct_default( thing, "KnuthBendix", - 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"); @@ -329,8 +331,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) { @@ -386,7 +390,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 +451,39 @@ 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_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( + m, "KnuthBendixNormalFormRangeWordLenLexSet"); + bind_normal_form_range( + m, "KnuthBendixNormalFormRangeStringLenLexTrie"); + 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/froidure_pin.py b/src/libsemigroups_pybind11/froidure_pin.py index 839c6de2..d892be0f 100644 --- a/src/libsemigroups_pybind11/froidure_pin.py +++ b/src/libsemigroups_pybind11/froidure_pin.py @@ -26,10 +26,14 @@ 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, + 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, @@ -51,10 +55,14 @@ 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, + 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, @@ -145,10 +153,14 @@ 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, + (_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 ac2410d4..856835dc 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 ( - KnuthBendixStringRewriteFromLeft as _KnuthBendixStringRewriteFromLeft, - KnuthBendixStringRewriteTrie as _KnuthBendixStringRewriteTrie, - KnuthBendixWordRewriteFromLeft as _KnuthBendixWordRewriteFromLeft, - KnuthBendixWordRewriteTrie as _KnuthBendixWordRewriteTrie, + KnuthBendixStringLenLexSet as _KnuthBendixStringLenLexSet, + KnuthBendixStringLenLexTrie as _KnuthBendixStringLenLexTrie, + KnuthBendixStringRPOSet as _KnuthBendixStringRPOSet, + KnuthBendixStringRPOTrie as _KnuthBendixStringRPOTrie, + KnuthBendixWordLenLexSet as _KnuthBendixWordLenLexSet, + KnuthBendixWordLenLexTrie as _KnuthBendixWordLenLexTrie, + 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, @@ -38,15 +45,19 @@ 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], "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( @@ -59,29 +70,47 @@ class KnuthBendix(_CongruenceCommon): _all_wrapped_cxx_types = {*_py_template_params_to_cxx_type.values()} - options = _KnuthBendixStringRewriteTrie.options - - @_copydoc(_KnuthBendixStringRewriteTrie.__init__) - def __init__(self, *args, rewriter="RewriteTrie", **kwargs) -> None: - if rewriter not in ("RewriteFromLeft", "RewriteTrie"): - raise TypeError( - f'expected the keyword argument "rewriter" to be ' - f'"RewriteFromLeft" or "RewriteTrie", but found "{rewriter}"' + options = _KnuthBendixStringLenLexTrie.options + + @_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 ' + 'keyword argument "rewriting_system" or "order", then the value(s) you ' + "specified will be ignored!", + DeprecationWarning, + 2, ) + if kwargs["rewriter"] not in ("RewriteFromLeft", "RewriteTrie"): + rewriter = kwargs["rewriter"] + raise TypeError( + '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])}" @@ -93,11 +122,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 b60915d5..7a1c71cf 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, @@ -18,12 +19,18 @@ 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_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, @@ -40,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 @@ -69,12 +77,18 @@ 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, "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 629754c4..4c7f557f 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,15 @@ 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); + + 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 3297aed9..8c420a94 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,35 @@ 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"); + 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, "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"); + 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 894ce75c..3103d439 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,34 @@ 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"); + + 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 ad7aabd3..9ee2a46e 100644 --- a/src/to-todd-coxeter.cpp +++ b/src/to-todd-coxeter.cpp @@ -51,11 +51,21 @@ 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); + + 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 89fdfc25..505dc499 100644 --- a/tests/test_knuth_bendix.py +++ b/tests/test_knuth_bendix.py @@ -18,6 +18,7 @@ POSITIVE_INFINITY, KnuthBendix, LibsemigroupsError, + Order, Presentation, ReportGuard, StringRange, @@ -32,8 +33,8 @@ def check_initialisation(*args): - for rewriter in ("RewriteFromLeft", "RewriteTrie"): - 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="RewriteFromLeft") + KnuthBendix(kb, rewriting_system="Set", order=Order.shortlex) - kb = KnuthBendix(kind, p, rewriter="RewriteFromLeft") + kb = KnuthBendix(kind, p, rewriting_system="Set", order=Order.shortlex) def test_attributes(): @@ -93,7 +94,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 @@ -341,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))) diff --git a/tests/test_to.py b/tests/test_to.py index d05c86d2..8fd2d966 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.""" @@ -13,10 +13,14 @@ # 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, + 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,23 +235,39 @@ 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, 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="RewriteTrie") - assert isinstance(to_cxx(fp), FroidurePinKBEStringRewriteTrie) + 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="RewriteFromLeft") - assert isinstance(to_cxx(fp), FroidurePinKBEWordRewriteFromLeft) + 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="RewriteTrie") - assert isinstance(to_cxx(fp), FroidurePinKBEWordRewriteTrie) + 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="RewriteFromLeft") + 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="RewriteTrie") + 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="RewriteFromLeft") + 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="RewriteTrie") + 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, "RewriteFromLeft") - check_knuth_bendix_to_pres(str, list[int], "RewriteFromLeft") + 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, "RewriteTrie") - check_knuth_bendix_to_pres(str, list[int], "RewriteTrie") + 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, "RewriteFromLeft") - check_knuth_bendix_to_pres(list[int], list[int], "RewriteFromLeft") + 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, "RewriteTrie") - check_knuth_bendix_to_pres(list[int], list[int], "RewriteTrie") + 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, "RewriteFromLeft") + 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, "RewriteFromLeft") + assert kb.py_template_params == (str, "Set", Order.recursive) def test_to_KnuthBendix_050(): - kb = check_froidure_pin_to_knuth_bendix(str, "RewriteTrie") + 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], "RewriteFromLeft") + 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], "RewriteTrie") + 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, "RewriteFromLeft") + 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, "RewriteTrie") + 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], "RewriteFromLeft") + 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], "RewriteTrie") + 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) @@ -886,13 +963,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)