diff --git a/docs/source/data-structures/order/index.rst b/docs/source/data-structures/order/index.rst index 2cd7ff38..e1b41f20 100644 --- a/docs/source/data-structures/order/index.rst +++ b/docs/source/data-structures/order/index.rst @@ -35,3 +35,5 @@ Full API .. autofunction:: recursive_path_compare .. autofunction:: shortlex_compare + +.. autofunction:: wt_shortlex_compare diff --git a/src/libsemigroups_pybind11/__init__.py b/src/libsemigroups_pybind11/__init__.py index 25bd333f..7db4950d 100644 --- a/src/libsemigroups_pybind11/__init__.py +++ b/src/libsemigroups_pybind11/__init__.py @@ -99,6 +99,8 @@ shortlex_compare, side, tril, + wt_lex_compare, + wt_shortlex_compare, ) except ModuleNotFoundError as e: raise ModuleNotFoundError( diff --git a/src/order.cpp b/src/order.cpp index 1480d7ba..822089bb 100644 --- a/src/order.cpp +++ b/src/order.cpp @@ -201,6 +201,116 @@ is based on the source code of :cite:`Holt2018aa`. R"pbdoc( :sig=(x: str | list[int], y: str | list[int]) -> bool: :only-document-once: +)pbdoc"); + + // No prefix because not in subpackage + m.def( + "wt_shortlex_compare", + [](std::string const& x, + std::string const& y, + std::vector const& weights) { + return wt_shortlex_compare(x, y, weights); + }, + py::arg("x"), + py::arg("y"), + py::arg("weights"), + R"pbdoc( +:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool: +:only-document-once: +Compare two values of type :any:`str` or ``list[int]`` using weighted shortlex ordering. + +This function compares two objects using the weighted short-lex ordering. The +weight of a word is computed by adding up the weights of the letters in the +word, where the ith index of the weights vector corresponds to the weight of +the ith letter in the alphabet. Heavier words come later in the ordering than +all lighter words. Amongst words of equal weight, short-lex ordering is used. + +:param x: the first object for comparison. +:type x: str | list[int] + +:param y: the second object for comparison. +:type y: str | list[int] + +:param weights: the weights vector, where the ith index corresponds to the weight of the ith letter. +:type weights: list[int] + +:returns: The boolean value ``True`` if *x* is weighted short-lex less than *y*, and ``False`` otherwise. +:rtype: bool + +:raises LibsemigroupsError: if any letter in *x* or *y* is not a valid index into the weights vector. + +:complexity: At most :math:`O(n + m)` where :math:`n` is the length of *x* and :math:`m` is the length of *y*. +)pbdoc"); + + // No prefix because not in subpackage + m.def( + "wt_shortlex_compare", + [](word_type const& x, + word_type const& y, + std::vector const& weights) { + return wt_shortlex_compare(x, y, weights); + }, + py::arg("x"), + py::arg("y"), + py::arg("weights"), + R"pbdoc( +:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool: +:only-document-once: +)pbdoc"); + + // No prefix because not in subpackage + m.def( + "wt_lex_compare", + [](std::string const& x, + std::string const& y, + std::vector const& weights) { + return wt_lex_compare(x, y, weights); + }, + py::arg("x"), + py::arg("y"), + py::arg("weights"), + R"pbdoc( +:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool: +:only-document-once: +Compare two values of type :any:`str` or ``list[int]`` using weighted lex ordering. + +This function compares two objects using the weighted lex ordering. The +weight of a word is computed by adding up the weights of the letters in the +word, where the ith index of the weights vector corresponds to the weight of +the ith letter in the alphabet. Heavier words come later in the ordering than +all lighter words. Amongst words of equal weight, lexicographic ordering is used. + +:param x: the first object for comparison. +:type x: str | list[int] + +:param y: the second object for comparison. +:type y: str | list[int] + +:param weights: the weights vector, where the ith index corresponds to the weight of the ith letter. +:type weights: list[int] + +:returns: The boolean value ``True`` if *x* is weighted lex less than *y*, and ``False`` otherwise. +:rtype: bool + +:raises LibsemigroupsError: if any letter in *x* or *y* is not a valid index into the weights vector. + +:complexity: At most :math:`O(n + m)` where :math:`n` is the length of *x* and :math:`m` is the length of *y*. +)pbdoc"); + + // No prefix because not in subpackage + m.def( + "wt_lex_compare", + [](word_type const& x, + word_type const& y, + std::vector const& weights) { + return wt_lex_compare(x, y, weights); + }, + py::arg("x"), + py::arg("y"), + py::arg("weights"), + R"pbdoc( +:sig=(x: str | list[int], y: str | list[int], weights: list[int]) -> bool: +:only-document-once: )pbdoc"); } } // namespace libsemigroups