Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/source/data-structures/order/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ This page contains the documentation for classes and several functions for
comparing words (i.e. lists of integers ``list[int]`` or strings ``str``) with
respect to certain reduction orderings.

Some of the orders are generalisations of others. In particular,
when the weight of every generator is the same:

- :any:`len_wt_lex_cmp` is a generalisation of :any:`lenlex_cmp`;
- :any:`rev_len_wt_lex_cmp` is a generalisation of :any:`rev_lenlex_cmp`;
- :any:`wt_lenlex_cmp` is a generalisation of :any:`lenlex_cmp`; and
- :any:`rev_wt_lenlex_cmp` is a generalisation of :any:`rev_lenlex_cmp`;
- :any:`wt_lex_cmp` is a generalisation of :any:`lex_cmp`; and
- :any:`rev_wt_lex_cmp` is a generalisation of :any:`rev_lex_cmp`.

Additionally:

- :any:`wr_cmp` is a generalisation of :any:`lenlex_cmp` when all
of the generators have the same level;
- :any:`rev_wr_cmp` is a generalisation of :any:`rev_lenlex_cmp` when all
of the generators have the same level;
- :any:`wr_cmp` is a generalisation of :any:`rev_rpo_cmp` when all
of the generators have a different level; and
- :any:`rev_wr_cmp` is a generalisation of :any:`rpo_cmp` when all
of the generators have a different level.

.. seealso::

- :any:`Order`
Expand Down
13 changes: 13 additions & 0 deletions docs/source/libsemigroups.bib
Original file line number Diff line number Diff line change
Expand Up @@ -672,3 +672,16 @@ @article{Du2026aa
volume = {150},
year = {2026}
}

@article{Dershowitz1982aa,
title = {Orderings for term-rewriting systems},
journal = {Theoretical Computer Science},
volume = {17},
number = {3},
pages = {279-301},
year = {1982},
issn = {0304-3975},
doi = {https://doi.org/10.1016/0304-3975(82)90026-3},
url = {https://www.sciencedirect.com/science/article/pii/0304397582900263},
author = {Nachum Dershowitz},
}
14 changes: 14 additions & 0 deletions docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ and the third item one of:
with short-lex reduction ordering.
- :any:`Order.rpo` for constructing a :any:`KnuthBendix`
with recursive-path reduction ordering.
- :any:`Order.rev_rpo` for constructing a :any:`KnuthBendix`
with reverse recursive-path reduction ordering.

This function converts a :any:`ToddCoxeter` object *tc* to a :any:`KnuthBendix`
object with the rewriter as specified above, using
Expand Down Expand Up @@ -186,6 +188,18 @@ Additionally, specify one of the following for *rtype*:
- ``(KnuthBendix, list[int], 'Set', Order.rpo)`` 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.rev_rpo)`` for constructing a
:any:`KnuthBendix` on words with type ``str`` using the
trie based rewriting system and reverse recursive-path reduction ordering.
- ``(KnuthBendix, list[int], 'Trie', Order.rev_rpo)`` for constructing a
:any:`KnuthBendix` on words with type ``list[int]`` using the
trie based rewriting system and reverse recursive-path reduction ordering.
- ``(KnuthBendix, str, 'Set', Order.rev_rpo)`` for constructing a
:any:`KnuthBendix` on words with type ``str`` using a set based rewriting
system and reverse recursive-path reduction ordering.
- ``(KnuthBendix, list[int], 'Set', Order.rev_rpo)`` for constructing a
:any:`KnuthBendix` on words with type ``list[int]`` using a set based
rewriting system and reverse recursive-path reduction.

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
Expand Down
130 changes: 130 additions & 0 deletions src/cong-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace libsemigroups {

using LenLexTrie = detail::RewritingSystemTrie<LenLexCmp>;
using LenLexSet = detail::RewritingSystemSet<LenLexCmp>;
using RPOTrie = detail::RewritingSystemTrie<RPOCmp>;
using RPOSet = detail::RewritingSystemSet<RPOCmp>;
using RevRPOTrie = detail::RewritingSystemTrie<RevRPOCmp>;
using RevRPOSet = detail::RewritingSystemSet<RevRPOCmp>;

Expand All @@ -54,6 +56,11 @@ namespace libsemigroups {
using KnuthBendixWordLenLexTrie = KnuthBendix<word_type, LenLexTrie>;
using KnuthBendixWordLenLexSet = KnuthBendix<word_type, LenLexSet>;

using KnuthBendixStringRPOTrie = KnuthBendix<std::string, RPOTrie>;
using KnuthBendixStringRPOSet = KnuthBendix<std::string, RPOSet>;
using KnuthBendixWordRPOTrie = KnuthBendix<word_type, RPOTrie>;
using KnuthBendixWordRPOSet = KnuthBendix<word_type, RPOSet>;

using KnuthBendixStringRevRPOTrie = KnuthBendix<std::string, RevRPOTrie>;
using KnuthBendixStringRevRPOSet = KnuthBendix<std::string, RevRPOSet>;
using KnuthBendixWordRevRPOTrie = KnuthBendix<word_type, RevRPOTrie>;
Expand Down Expand Up @@ -138,6 +145,11 @@ This function default constructs an uninitialised :any:`{name}` instance.
DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl<LenLexSet>,
detail::CongruenceCommon);

DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl<RPOTrie>,
detail::CongruenceCommon);
DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl<RPOSet>,
detail::CongruenceCommon);

DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl<RevRPOTrie>,
detail::CongruenceCommon);
DEF_CONSTRUCT_DEFAULT(detail::KnuthBendixImpl<RevRPOSet>,
Expand All @@ -152,6 +164,14 @@ This function default constructs an uninitialised :any:`{name}` instance.
DEF_CONSTRUCT_DEFAULT(KnuthBendixWordLenLexSet,
detail::KnuthBendixImpl<LenLexSet>);

DEF_CONSTRUCT_DEFAULT(KnuthBendixStringRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_CONSTRUCT_DEFAULT(KnuthBendixStringRPOSet,
detail::KnuthBendixImpl<RPOSet>);
DEF_CONSTRUCT_DEFAULT(KnuthBendixWordRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_CONSTRUCT_DEFAULT(KnuthBendixWordRPOSet, detail::KnuthBendixImpl<RPOSet>);

DEF_CONSTRUCT_DEFAULT(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_CONSTRUCT_DEFAULT(KnuthBendixStringRevRPOSet,
Expand Down Expand Up @@ -212,6 +232,9 @@ have been in if it had just been newly default constructed.
DEF_INIT_DEFAULT(detail::KnuthBendixImpl<LenLexSet>,
detail::CongruenceCommon);

DEF_INIT_DEFAULT(detail::KnuthBendixImpl<RPOTrie>, detail::CongruenceCommon);
DEF_INIT_DEFAULT(detail::KnuthBendixImpl<RPOSet>, detail::CongruenceCommon);

DEF_INIT_DEFAULT(detail::KnuthBendixImpl<RevRPOTrie>,
detail::CongruenceCommon);
DEF_INIT_DEFAULT(detail::KnuthBendixImpl<RevRPOSet>,
Expand All @@ -226,6 +249,11 @@ have been in if it had just been newly default constructed.
DEF_INIT_DEFAULT(KnuthBendixWordLenLexSet,
detail::KnuthBendixImpl<LenLexSet>);

DEF_INIT_DEFAULT(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_INIT_DEFAULT(KnuthBendixStringRPOSet, detail::KnuthBendixImpl<RPOSet>);
DEF_INIT_DEFAULT(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_INIT_DEFAULT(KnuthBendixWordRPOSet, detail::KnuthBendixImpl<RPOSet>);

DEF_INIT_DEFAULT(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_INIT_DEFAULT(KnuthBendixStringRevRPOSet,
Expand Down Expand Up @@ -309,11 +337,25 @@ of kind *knd* over the semigroup or monoid defined by the presentation *p*.
DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordLenLexSet,
detail::KnuthBendixImpl<LenLexSet>);

DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl<RPOTrie>,
detail::CongruenceCommon);
DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl<RPOSet>,
detail::CongruenceCommon);

DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl<RevRPOTrie>,
detail::CongruenceCommon);
DEF_CONSTRUCT_KIND_PRESENTATION(detail::KnuthBendixImpl<RevRPOSet>,
detail::CongruenceCommon);

DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringRPOSet,
detail::KnuthBendixImpl<RPOSet>);
DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixWordRPOSet,
detail::KnuthBendixImpl<RPOSet>);

DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_CONSTRUCT_KIND_PRESENTATION(KnuthBendixStringRevRPOSet,
Expand Down Expand Up @@ -400,11 +442,25 @@ had been newly constructed from *knd* and *p*.
DEF_INIT_KIND_PRESENTATION(KnuthBendixWordLenLexSet,
detail::KnuthBendixImpl<LenLexSet>);

DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl<RPOTrie>,
detail::CongruenceCommon);
DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl<RPOSet>,
detail::CongruenceCommon);

DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl<RevRPOTrie>,
detail::CongruenceCommon);
DEF_INIT_KIND_PRESENTATION(detail::KnuthBendixImpl<RevRPOSet>,
detail::CongruenceCommon);

DEF_INIT_KIND_PRESENTATION(KnuthBendixStringRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_INIT_KIND_PRESENTATION(KnuthBendixStringRPOSet,
detail::KnuthBendixImpl<RPOSet>);
DEF_INIT_KIND_PRESENTATION(KnuthBendixWordRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_INIT_KIND_PRESENTATION(KnuthBendixWordRPOSet,
detail::KnuthBendixImpl<RPOSet>);

DEF_INIT_KIND_PRESENTATION(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_INIT_KIND_PRESENTATION(KnuthBendixStringRevRPOSet,
Expand Down Expand Up @@ -465,9 +521,17 @@ Copy a :any:`{name}` object.
DEF_COPY(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl<LenLexTrie>);
DEF_COPY(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl<LenLexSet>);

DEF_COPY(detail::KnuthBendixImpl<RPOTrie>, detail::CongruenceCommon);
DEF_COPY(detail::KnuthBendixImpl<RPOSet>, detail::CongruenceCommon);

DEF_COPY(detail::KnuthBendixImpl<RevRPOTrie>, detail::CongruenceCommon);
DEF_COPY(detail::KnuthBendixImpl<RevRPOSet>, detail::CongruenceCommon);

DEF_COPY(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_COPY(KnuthBendixStringRPOSet, detail::KnuthBendixImpl<RPOSet>);
DEF_COPY(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_COPY(KnuthBendixWordRPOSet, detail::KnuthBendixImpl<RPOSet>);

DEF_COPY(KnuthBendixStringRevRPOTrie, detail::KnuthBendixImpl<RevRPOTrie>);
DEF_COPY(KnuthBendixStringRevRPOSet, detail::KnuthBendixImpl<RevRPOSet>);
DEF_COPY(KnuthBendixWordRevRPOTrie, detail::KnuthBendixImpl<RevRPOTrie>);
Expand Down Expand Up @@ -529,6 +593,11 @@ number of classes in the congruence represented by a :any:`{name}` instance.
DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl<LenLexSet>,
detail::CongruenceCommon);

DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl<RPOTrie>,
detail::CongruenceCommon);
DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl<RPOSet>,
detail::CongruenceCommon);

DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl<RevRPOTrie>,
detail::CongruenceCommon);
DEF_NUMBER_OF_CLASSES(detail::KnuthBendixImpl<RevRPOSet>,
Expand Down Expand Up @@ -610,6 +679,15 @@ This function adds a generating pair to the congruence represented by a
DEF_ADD_GENERATING_PAIR(KnuthBendixWordLenLexSet,
detail::KnuthBendixImpl<LenLexSet>);

DEF_ADD_GENERATING_PAIR(KnuthBendixStringRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_ADD_GENERATING_PAIR(KnuthBendixStringRPOSet,
detail::KnuthBendixImpl<RPOSet>);
DEF_ADD_GENERATING_PAIR(KnuthBendixWordRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_ADD_GENERATING_PAIR(KnuthBendixWordRPOSet,
detail::KnuthBendixImpl<RPOSet>);

DEF_ADD_GENERATING_PAIR(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_ADD_GENERATING_PAIR(KnuthBendixStringRevRPOSet,
Expand Down Expand Up @@ -695,6 +773,15 @@ contained in the congruence, but that this is not currently known.
DEF_CURRENTLY_CONTAINS(KnuthBendixWordLenLexSet,
detail::KnuthBendixImpl<LenLexSet>);

DEF_CURRENTLY_CONTAINS(KnuthBendixStringRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_CURRENTLY_CONTAINS(KnuthBendixStringRPOSet,
detail::KnuthBendixImpl<RPOSet>);
DEF_CURRENTLY_CONTAINS(KnuthBendixWordRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_CURRENTLY_CONTAINS(KnuthBendixWordRPOSet,
detail::KnuthBendixImpl<RPOSet>);

DEF_CURRENTLY_CONTAINS(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_CURRENTLY_CONTAINS(KnuthBendixStringRevRPOSet,
Expand Down Expand Up @@ -770,6 +857,11 @@ congruence represented by a :py:class:`{name}` instance.
DEF_CONTAINS(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl<LenLexTrie>);
DEF_CONTAINS(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl<LenLexSet>);

DEF_CONTAINS(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_CONTAINS(KnuthBendixStringRPOSet, detail::KnuthBendixImpl<RPOSet>);
DEF_CONTAINS(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_CONTAINS(KnuthBendixWordRPOSet, detail::KnuthBendixImpl<RPOSet>);

DEF_CONTAINS(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_CONTAINS(KnuthBendixStringRevRPOSet, detail::KnuthBendixImpl<RevRPOSet>);
Expand Down Expand Up @@ -842,6 +934,11 @@ normal form for the input word *w*.
DEF_REDUCE_NO_RUN(KnuthBendixWordLenLexSet,
detail::KnuthBendixImpl<LenLexSet>);

DEF_REDUCE_NO_RUN(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_REDUCE_NO_RUN(KnuthBendixStringRPOSet, detail::KnuthBendixImpl<RPOSet>);
DEF_REDUCE_NO_RUN(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_REDUCE_NO_RUN(KnuthBendixWordRPOSet, detail::KnuthBendixImpl<RPOSet>);

DEF_REDUCE_NO_RUN(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_REDUCE_NO_RUN(KnuthBendixStringRevRPOSet,
Expand Down Expand Up @@ -914,6 +1011,11 @@ input word.
DEF_REDUCE(KnuthBendixWordLenLexTrie, detail::KnuthBendixImpl<LenLexTrie>);
DEF_REDUCE(KnuthBendixWordLenLexSet, detail::KnuthBendixImpl<LenLexSet>);

DEF_REDUCE(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_REDUCE(KnuthBendixStringRPOSet, detail::KnuthBendixImpl<RPOSet>);
DEF_REDUCE(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_REDUCE(KnuthBendixWordRPOSet, detail::KnuthBendixImpl<RPOSet>);

DEF_REDUCE(KnuthBendixStringRevRPOTrie, detail::KnuthBendixImpl<RevRPOTrie>);
DEF_REDUCE(KnuthBendixStringRevRPOSet, detail::KnuthBendixImpl<RevRPOSet>);
DEF_REDUCE(KnuthBendixWordRevRPOTrie, detail::KnuthBendixImpl<RevRPOTrie>);
Expand Down Expand Up @@ -977,6 +1079,14 @@ This function returns the generating pairs of the congruence as added via
DEF_GENERATING_PAIRS(KnuthBendixWordLenLexSet,
detail::KnuthBendixImpl<LenLexSet>);

DEF_GENERATING_PAIRS(KnuthBendixStringRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_GENERATING_PAIRS(KnuthBendixStringRPOSet,
detail::KnuthBendixImpl<RPOSet>);
DEF_GENERATING_PAIRS(KnuthBendixWordRPOTrie,
detail::KnuthBendixImpl<RPOTrie>);
DEF_GENERATING_PAIRS(KnuthBendixWordRPOSet, detail::KnuthBendixImpl<RPOSet>);

DEF_GENERATING_PAIRS(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_GENERATING_PAIRS(KnuthBendixStringRevRPOSet,
Expand Down Expand Up @@ -1045,6 +1155,11 @@ presentation, then this presentation is returned by this function.
DEF_PRESENTATION(KnuthBendixWordLenLexSet,
detail::KnuthBendixImpl<LenLexSet>);

DEF_PRESENTATION(KnuthBendixStringRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_PRESENTATION(KnuthBendixStringRPOSet, detail::KnuthBendixImpl<RPOSet>);
DEF_PRESENTATION(KnuthBendixWordRPOTrie, detail::KnuthBendixImpl<RPOTrie>);
DEF_PRESENTATION(KnuthBendixWordRPOSet, detail::KnuthBendixImpl<RPOSet>);

DEF_PRESENTATION(KnuthBendixStringRevRPOTrie,
detail::KnuthBendixImpl<RevRPOTrie>);
DEF_PRESENTATION(KnuthBendixStringRevRPOSet,
Expand Down Expand Up @@ -1122,6 +1237,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(KnuthBendixStringRevRPOTrie);
DEF_PARTITION(KnuthBendixStringRevRPOSet);
DEF_PARTITION(KnuthBendixWordRevRPOTrie);
Expand Down Expand Up @@ -1194,6 +1314,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(KnuthBendixStringRevRPOTrie);
DEF_NON_TRIVIAL_CLASSES(KnuthBendixStringRevRPOSet);
DEF_NON_TRIVIAL_CLASSES(KnuthBendixWordRevRPOTrie);
Expand Down Expand Up @@ -1262,6 +1387,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);

DEF_NORMAL_FORMS(KnuthBendixStringRevRPOTrie);
DEF_NORMAL_FORMS(KnuthBendixStringRevRPOSet);
DEF_NORMAL_FORMS(KnuthBendixWordRevRPOTrie);
Expand Down
18 changes: 10 additions & 8 deletions src/du-narendran-rusinowitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,26 @@ namespace libsemigroups {
R"pbdoc(
:sig=(p: Presentation) -> str | list[int]:
:only-document-once:
Find an alphabet order that orients every rule using reverse recursive-path ordering.
Return an ordered alphabet such that the rules are oriented with
respect to recursive-path order; see :any:`rpo_cmp`.

This function returns the alphabet of *p*, ordered so that every rule
:math:`u \to v` satisfies :math:`u > v` with respect to reverse recursive-path
ordering. It returns an empty word if no such order exists, or if the alphabet
of *p* is empty.
This function returns the alphabet of *p* ordered so that the rules of
*p* satisfy :math:`x_i \to y_i` and :math`x_i > y_i` with respect to
recursive-path order and the returned alphabet order. The returned
alphabet is empty if this fails, or if the alphabet was empty to begin
with.

:param p: the presentation whose rules are to be oriented.
:type p: Presentation

:returns: An alphabet order orienting every rule, or an empty word if none
exists.
:returns: The ordered alphabet, if such an alphabet exists. Otherwise, the
empty alphabet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really a comment about this PR, but maybe this should return None if it can't do it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should change the C++ code to return an optional, or should this be a Python only change?

:rtype: str | list[int]

:raises LibsemigroupsError: if the alphabet or rules of *p* are invalid.

.. seealso::
:any:`rev_rpo_cmp`
:any:`rpo_cmp`

.. doctest::

Expand Down
Loading
Loading