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
12 changes: 12 additions & 0 deletions docs/source/data-structures/order/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,27 @@ Contents
.. autosummary::
:signatures: short

lenlex_cmp
lex_cmp
lexicographical_compare
recursive_path_compare
rev_rpo_cmp
rpo_cmp
shortlex_compare

Full API
--------

.. autofunction:: lenlex_cmp

.. autofunction:: lex_cmp

.. autofunction:: lexicographical_compare

.. autofunction:: recursive_path_compare

.. autofunction:: rev_rpo_cmp

.. autofunction:: rpo_cmp

.. autofunction:: shortlex_compare
32 changes: 16 additions & 16 deletions docs/source/main-algorithms/knuth-bendix/to-knuth-bendix.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ Additionally, specify *rtype* to be a tuple with first item :any:`KnuthBendix`,

and the third item one of:

- :any:`Order.shortlex` for constructing a :any:`KnuthBendix`
- :any:`Order.lenlex` for constructing a :any:`KnuthBendix`
with short-lex reduction ordering.
- :any:`Order.recursive` for constructing a :any:`KnuthBendix`
with recursive path reduction ordering.
- :any:`Order.rpo` 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
Expand Down Expand Up @@ -140,7 +140,7 @@ the semigroup defined by *tc*.
>>> kb = to(
... congruence_kind.twosided, # knd
... tc, # tc
... rtype=(KnuthBendix, 'Set', Order.shortlex)
... rtype=(KnuthBendix, 'Set', Order.lenlex)
... )
>>> kb.run()

Expand All @@ -162,28 +162,28 @@ following values for *args*:

Additionally, specify one of the following for *rtype*:

- ``(KnuthBendix, str, 'Trie', Order.shortlex)`` for constructing a
- ``(KnuthBendix, str, 'Trie', Order.lenlex)`` 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
- ``(KnuthBendix, list[int], 'Trie', Order.lenlex)`` for constructing a
:any:`KnuthBendix` on words with type ``list[int]`` using the
trie based rewriting system and short-lex reduction ordering.
- ``(KnuthBendix, str, 'Set', Order.shortlex)`` for constructing a
- ``(KnuthBendix, str, 'Set', Order.lenlex)`` 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
- ``(KnuthBendix, list[int], 'Set', Order.lenlex)`` 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
- ``(KnuthBendix, str, 'Trie', Order.rpo)`` for constructing a
:any:`KnuthBendix` on words with type ``str`` using the
trie based rewriting system and recursive path reduction ordering.
- ``(KnuthBendix, list[int], 'Trie', Order.recursive)`` for constructing a
trie based rewriting system and recursive-path reduction ordering.
- ``(KnuthBendix, list[int], 'Trie', Order.rpo)`` for constructing a
:any:`KnuthBendix` on words with type ``list[int]`` using the
trie based rewriting system and recursive path reduction ordering.
- ``(KnuthBendix, str, 'Set', Order.recursive)`` for constructing a
trie based rewriting system and recursive-path reduction ordering.
- ``(KnuthBendix, str, 'Set', Order.rpo)`` 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
system and recursive-path reduction ordering.
- ``(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.

Expand Down Expand Up @@ -216,7 +216,7 @@ the semigroup defined by *fpb*.
>>> kb = to(
... congruence_kind.twosided, # knd
... S, # tc
... rtype=(KnuthBendix, list[int], 'Set', Order.recursive)
... rtype=(KnuthBendix, list[int], 'Set', Order.rpo)
... )
>>> kb.run()

Expand Down
243 changes: 131 additions & 112 deletions src/cong-common.cpp

Large diffs are not rendered by default.

26 changes: 14 additions & 12 deletions src/froidure-pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,10 +1272,10 @@ This function returns the element of *fp* obtained by evaluating *w*.
} // namespace

void init_froidure_pin(py::module& m) {
using LenLexTrie = detail::RewritingSystemTrie<ShortLexCompare>;
using LenLexSet = detail::RewritingSystemSet<ShortLexCompare>;
using RPOTrie = detail::RewritingSystemTrie<RecursivePathCompare>;
using RPOSet = detail::RewritingSystemSet<RecursivePathCompare>;
using LenLexTrie = detail::RewritingSystemTrie<LenLexCmp>;
using LenLexSet = detail::RewritingSystemSet<LenLexCmp>;
using RevRPOTrie = detail::RewritingSystemTrie<RevRPOCmp>;
using RevRPOSet = detail::RewritingSystemSet<RevRPOCmp>;

bind_froidure_pin_stateless<Transf<0, uint8_t>>(m, "Transf1");
bind_froidure_pin_stateless<Transf<0, uint16_t>>(m, "Transf2");
Expand Down Expand Up @@ -1316,14 +1316,16 @@ This function returns the element of *fp* obtained by evaluating *w*.
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<word_type, LenLexTrie>>>(
m, "KBEWordLenLexTrie");

bind_froidure_pin_stateful<detail::KBE<KnuthBendix<std::string, RPOSet>>>(
m, "KBEStringRPOSet");
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<std::string, RPOTrie>>>(
m, "KBEStringRPOTrie");
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<word_type, RPOSet>>>(
m, "KBEWordRPOSet");
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<word_type, RPOTrie>>>(
m, "KBEWordRPOTrie");
bind_froidure_pin_stateful<
detail::KBE<KnuthBendix<std::string, RevRPOSet>>>(m,
"KBEStringRevRPOSet");
bind_froidure_pin_stateful<
detail::KBE<KnuthBendix<std::string, RevRPOTrie>>>(
m, "KBEStringRevRPOTrie");
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<word_type, RevRPOSet>>>(
m, "KBEWordRevRPOSet");
bind_froidure_pin_stateful<detail::KBE<KnuthBendix<word_type, RevRPOTrie>>>(
m, "KBEWordRevRPOTrie");

bind_froidure_pin_stateful<detail::KE<std::string>>(m, "KEString");
bind_froidure_pin_stateful<detail::KE<detail::MultiView<std::string>>>(
Expand Down
27 changes: 14 additions & 13 deletions src/kbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ namespace libsemigroups {
}

void init_kbe(py::module& m) {
using LenLexTrie = detail::RewritingSystemTrie<ShortLexCompare>;
using LenLexSet = detail::RewritingSystemSet<ShortLexCompare>;
using RPOTrie = detail::RewritingSystemTrie<RecursivePathCompare>;
using RPOSet = detail::RewritingSystemSet<RecursivePathCompare>;
using LenLexTrie = detail::RewritingSystemTrie<LenLexCmp>;
using LenLexSet = detail::RewritingSystemSet<LenLexCmp>;
using RevRPOTrie = detail::RewritingSystemTrie<RevRPOCmp>;
using RevRPOSet = detail::RewritingSystemSet<RevRPOCmp>;

// LenLex
using KBEStringLenLexTrie
Expand All @@ -91,14 +91,15 @@ namespace libsemigroups {
bind_kbe<KBEWordLenLexSet>(m, "KBEWordLenLexSet");

// RPO
using KBEStringRPOTrie = detail::KBE<KnuthBendix<std::string, RPOTrie>>;
using KBEWordRPOTrie = detail::KBE<KnuthBendix<word_type, RPOTrie>>;
using KBEStringRPOSet = detail::KBE<KnuthBendix<std::string, RPOSet>>;
using KBEWordRPOSet = detail::KBE<KnuthBendix<word_type, RPOSet>>;

bind_kbe<KBEStringRPOTrie>(m, "KBEStringRPOTrie");
bind_kbe<KBEWordRPOTrie>(m, "KBEWordRPOTrie");
bind_kbe<KBEStringRPOSet>(m, "KBEStringRPOSet");
bind_kbe<KBEWordRPOSet>(m, "KBEWordRPOSet");
using KBEStringRevRPOTrie
= detail::KBE<KnuthBendix<std::string, RevRPOTrie>>;
using KBEWordRevRPOTrie = detail::KBE<KnuthBendix<word_type, RevRPOTrie>>;
using KBEStringRevRPOSet = detail::KBE<KnuthBendix<std::string, RevRPOSet>>;
using KBEWordRevRPOSet = detail::KBE<KnuthBendix<word_type, RevRPOSet>>;

bind_kbe<KBEStringRevRPOTrie>(m, "KBEStringRevRPOTrie");
bind_kbe<KBEWordRevRPOTrie>(m, "KBEWordRevRPOTrie");
bind_kbe<KBEStringRevRPOSet>(m, "KBEStringRevRPOSet");
bind_kbe<KBEWordRevRPOSet>(m, "KBEWordRevRPOSet");
}
} // namespace libsemigroups
15 changes: 8 additions & 7 deletions src/knuth-bendix-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
//

// TODO(1) this file is not organised like any other:
// * kb should be called thing
// * we don't chain the "def"s in the other files (easier to wrangle)

// C std headers....
Expand Down Expand Up @@ -507,17 +506,19 @@ infinite; ``False`` is returned if it is not.
} // namespace detail

void init_detail_knuth_bendix_impl(py::module& m) {
using LenLexTrie = detail::RewritingSystemTrie<ShortLexCompare>;
using LenLexSet = detail::RewritingSystemSet<ShortLexCompare>;
using RPOTrie = detail::RewritingSystemTrie<RecursivePathCompare>;
using RPOSet = detail::RewritingSystemSet<RecursivePathCompare>;
using LenLexTrie = detail::RewritingSystemTrie<LenLexCmp>;
using LenLexSet = detail::RewritingSystemSet<LenLexCmp>;
using RevRPOTrie = detail::RewritingSystemTrie<RevRPOCmp>;
using RevRPOSet = detail::RewritingSystemSet<RevRPOCmp>;

detail::bind_detail_knuth_bendix_impl<LenLexSet>(
m, "KnuthBendixImplLenLexSet");
detail::bind_detail_knuth_bendix_impl<LenLexTrie>(
m, "KnuthBendixImplLenLexTrie");

detail::bind_detail_knuth_bendix_impl<RPOSet>(m, "KnuthBendixImplRPOSet");
detail::bind_detail_knuth_bendix_impl<RPOTrie>(m, "KnuthBendixImplRPOTrie");
detail::bind_detail_knuth_bendix_impl<RevRPOSet>(
m, "KnuthBendixImplRevRPOSet");
detail::bind_detail_knuth_bendix_impl<RevRPOTrie>(
m, "KnuthBendixImplRevRPOTrie");
}
} // namespace libsemigroups
41 changes: 20 additions & 21 deletions src/knuth-bendix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ nested class :any:`KnuthBendix.options`.
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});
* **order** (*Order*) -- the reduction ordering to use, must be either :any:`Order.lenlex` or :any:`Order.rpo`.)pbdoc"sv});

def_init_default(thing, "KnuthBendix");
def_construct_kind_presentation(thing, "KnuthBendix");
Expand Down Expand Up @@ -331,10 +331,8 @@ Check if all rules are reduced with respect to each other.

template <typename Word, typename Rewriter>
void bind_normal_form_range(py::module& m, char const* name) {
using NormalFormRange = detail::KnuthBendixNormalFormRange<
Word,
Rewriter,
typename Rewriter::reduction_order>;
using NormalFormRange
= detail::KnuthBendixNormalFormRange<Word, Rewriter>;
py::class_<NormalFormRange> thing(m, name);

thing.def("__repr__", [](NormalFormRange const& nfr) {
Expand Down Expand Up @@ -451,21 +449,22 @@ redundant in this way, then ``None`` is returned.
}

void init_knuth_bendix(py::module& m) {
using LenLexTrie = detail::RewritingSystemTrie<ShortLexCompare>;
using LenLexSet = detail::RewritingSystemSet<ShortLexCompare>;
using RPOTrie = detail::RewritingSystemTrie<RecursivePathCompare>;
using RPOSet = detail::RewritingSystemSet<RecursivePathCompare>;
using LenLexTrie = detail::RewritingSystemTrie<LenLexCmp>;
using LenLexSet = detail::RewritingSystemSet<LenLexCmp>;
using RevRPOTrie = detail::RewritingSystemTrie<RevRPOCmp>;
using RevRPOSet = detail::RewritingSystemSet<RevRPOCmp>;

bind_knuth_bendix<word_type, LenLexTrie>(m, "KnuthBendixWordLenLexTrie");
bind_knuth_bendix<word_type, LenLexSet>(m, "KnuthBendixWordLenLexSet");
bind_knuth_bendix<std::string, LenLexTrie>(m,
"KnuthBendixStringLenLexTrie");
bind_knuth_bendix<std::string, LenLexSet>(m, "KnuthBendixStringLenLexSet");

bind_knuth_bendix<word_type, RPOTrie>(m, "KnuthBendixWordRPOTrie");
bind_knuth_bendix<word_type, RPOSet>(m, "KnuthBendixWordRPOSet");
bind_knuth_bendix<std::string, RPOTrie>(m, "KnuthBendixStringRPOTrie");
bind_knuth_bendix<std::string, RPOSet>(m, "KnuthBendixStringRPOSet");
bind_knuth_bendix<word_type, RevRPOTrie>(m, "KnuthBendixWordRevRPOTrie");
bind_knuth_bendix<word_type, RevRPOSet>(m, "KnuthBendixWordRevRPOSet");
bind_knuth_bendix<std::string, RevRPOTrie>(m,
"KnuthBendixStringRevRPOTrie");
bind_knuth_bendix<std::string, RevRPOSet>(m, "KnuthBendixStringRevRPOSet");

bind_normal_form_range<word_type, LenLexTrie>(
m, "KnuthBendixNormalFormRangeWordLenLexTrie");
Expand All @@ -476,14 +475,14 @@ redundant in this way, then ``None`` is returned.
bind_normal_form_range<std::string, LenLexSet>(
m, "KnuthBendixNormalFormRangeStringLenLexSet");

bind_normal_form_range<word_type, RPOTrie>(
m, "KnuthBendixNormalFormRangeWordRPOTrie");
bind_normal_form_range<word_type, RPOSet>(
m, "KnuthBendixNormalFormRangeWordRPOSet");
bind_normal_form_range<std::string, RPOTrie>(
m, "KnuthBendixNormalFormRangeStringRPOTrie");
bind_normal_form_range<std::string, RPOSet>(
m, "KnuthBendixNormalFormRangeStringRPOSet");
bind_normal_form_range<word_type, RevRPOTrie>(
m, "KnuthBendixNormalFormRangeWordRevRPOTrie");
bind_normal_form_range<word_type, RevRPOSet>(
m, "KnuthBendixNormalFormRangeWordRevRPOSet");
bind_normal_form_range<std::string, RevRPOTrie>(
m, "KnuthBendixNormalFormRangeStringRevRPOTrie");
bind_normal_form_range<std::string, RevRPOSet>(
m, "KnuthBendixNormalFormRangeStringRevRPOSet");

bind_redundant_rule<std::string>(m);
bind_redundant_rule<word_type>(m);
Expand Down
15 changes: 15 additions & 0 deletions src/libsemigroups_pybind11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from .bipartition import Bipartition
from .blocks import Blocks
from .congruence import Congruence
from .detail.cxx_wrapper import wrap_cxx_free_fn as _wrap_cxx_free_fn
from .detail.dot import Dot
from .forest import PathsFromRoots, PathsToRoots
from .froidure_pin import FroidurePin
Expand Down Expand Up @@ -103,12 +104,16 @@
delta,
error_message_with_prefix,
freeband_equal_to,
lenlex_cmp as _lenlex_cmp,
lex_cmp as _lex_cmp,
lexicographical_compare,
number_of_words,
random_string,
random_strings,
random_word,
recursive_path_compare,
rev_rpo_cmp as _rev_rpo_cmp,
rpo_cmp as _rpo_cmp,
shortlex_compare,
side,
tril,
Expand All @@ -120,6 +125,12 @@
) from e


lenlex_cmp = _wrap_cxx_free_fn(_lenlex_cmp)
lex_cmp = _wrap_cxx_free_fn(_lex_cmp)
rev_rpo_cmp = _wrap_cxx_free_fn(_rev_rpo_cmp)
rpo_cmp = _wrap_cxx_free_fn(_rpo_cmp)


__all__ = [
"__version__",
# Constants from _libsemigruops_pybind11
Expand Down Expand Up @@ -158,12 +169,16 @@
"delta",
"error_message_with_prefix",
"freeband_equal_to",
"lenlex_cmp",
"lex_cmp",
"lexicographical_compare",
"number_of_words",
"random_string",
"random_strings",
"random_word",
"recursive_path_compare",
"rev_rpo_cmp",
"rpo_cmp",
"shortlex_compare",
"side",
"tril",
Expand Down
24 changes: 12 additions & 12 deletions src/libsemigroups_pybind11/froidure_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
FroidurePinIntMat as _FroidurePinIntMat,
FroidurePinKBEStringLenLexSet as _FroidurePinKBEStringLenLexSet,
FroidurePinKBEStringLenLexTrie as _FroidurePinKBEStringLenLexTrie,
FroidurePinKBEStringRPOSet as _FroidurePinKBEStringRPOSet,
FroidurePinKBEStringRPOTrie as _FroidurePinKBEStringRPOTrie,
FroidurePinKBEStringRevRPOSet as _FroidurePinKBEStringRevRPOSet,
FroidurePinKBEStringRevRPOTrie as _FroidurePinKBEStringRevRPOTrie,
FroidurePinKBEWordLenLexSet as _FroidurePinKBEWordLenLexSet,
FroidurePinKBEWordLenLexTrie as _FroidurePinKBEWordLenLexTrie,
FroidurePinKBEWordRPOSet as _FroidurePinKBEWordRPOSet,
FroidurePinKBEWordRPOTrie as _FroidurePinKBEWordRPOTrie,
FroidurePinKBEWordRevRPOSet as _FroidurePinKBEWordRevRPOSet,
FroidurePinKBEWordRevRPOTrie as _FroidurePinKBEWordRevRPOTrie,
FroidurePinKEMultiViewString as _FroidurePinKEMultiViewString,
FroidurePinKEString as _FroidurePinKEString,
FroidurePinKEWord as _FroidurePinKEWord,
Expand All @@ -57,12 +57,12 @@
IntMat as _IntMat,
KBEStringLenLexSet as _KBEStringLenLexSet,
KBEStringLenLexTrie as _KBEStringLenLexTrie,
KBEStringRPOSet as _KBEStringRPOSet,
KBEStringRPOTrie as _KBEStringRPOTrie,
KBEStringRevRPOSet as _KBEStringRevRPOSet,
KBEStringRevRPOTrie as _KBEStringRevRPOTrie,
KBEWordLenLexSet as _KBEWordLenLexSet,
KBEWordLenLexTrie as _KBEWordLenLexTrie,
KBEWordRPOSet as _KBEWordRPOSet,
KBEWordRPOTrie as _KBEWordRPOTrie,
KBEWordRevRPOSet as _KBEWordRevRPOSet,
KBEWordRevRPOTrie as _KBEWordRevRPOTrie,
MaxPlusMat as _MaxPlusMat,
MaxPlusTruncMat as _MaxPlusTruncMat,
MinPlusMat as _MinPlusMat,
Expand Down Expand Up @@ -157,10 +157,10 @@ class FroidurePin(_CxxWrapper):
(_KBEStringLenLexSet,): _FroidurePinKBEStringLenLexSet,
(_KBEWordLenLexTrie,): _FroidurePinKBEWordLenLexTrie,
(_KBEWordLenLexSet,): _FroidurePinKBEWordLenLexSet,
(_KBEStringRPOTrie,): _FroidurePinKBEStringRPOTrie,
(_KBEStringRPOSet,): _FroidurePinKBEStringRPOSet,
(_KBEWordRPOTrie,): _FroidurePinKBEWordRPOTrie,
(_KBEWordRPOSet,): _FroidurePinKBEWordRPOSet,
(_KBEStringRevRPOTrie,): _FroidurePinKBEStringRevRPOTrie,
(_KBEStringRevRPOSet,): _FroidurePinKBEStringRevRPOSet,
(_KBEWordRevRPOTrie,): _FroidurePinKBEWordRevRPOTrie,
(_KBEWordRevRPOSet,): _FroidurePinKBEWordRevRPOSet,
} | (
{
(_HPCombiPTransf16,): _FroidurePinHPCombiPTransf16,
Expand Down
Loading
Loading