Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update knuth-bendix-hpp for v1/3 #209

Merged
merged 6 commits into from
Dec 12, 2024
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
2 changes: 1 addition & 1 deletion docs/source/main-algorithms/cong-intf/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ semigroups and monoids. These classes are:

* :any:`Congruence`
* :any:`Kambites`
* :any:`KnuthBendix`
* :any:`KnuthBendixRewriteTrie`
* :any:`ToddCoxeter`

.. toctree::
Expand Down
50 changes: 50 additions & 0 deletions docs/source/main-algorithms/knuth-bendix/class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. Copyright (c) 2021-2024 J. D. Mitchell

Distributed under the terms of the GPL license version 3.

The full license is in the file LICENSE, distributed with this software.

.. currentmodule:: _libsemigroups_pybind11

The KnuthBendix class
=====================

.. autoclass:: KnuthBendixRewriteTrie
:doc-only:
:class-doc-from: class

Contents
--------

.. autosummary::
:nosignatures:

~KnuthBendixRewriteTrie
KnuthBendixRewriteTrie.active_rules
KnuthBendixRewriteTrie.check_confluence_interval
KnuthBendixRewriteTrie.confluent
KnuthBendixRewriteTrie.confluent_known
KnuthBendixRewriteTrie.copy
KnuthBendixRewriteTrie.contains
KnuthBendixRewriteTrie.currently_contains
KnuthBendixRewriteTrie.generating_pairs
KnuthBendixRewriteTrie.gilman_graph
KnuthBendixRewriteTrie.gilman_graph_node_labels
KnuthBendixRewriteTrie.max_overlap
KnuthBendixRewriteTrie.max_pending_rules
KnuthBendixRewriteTrie.max_rules
KnuthBendixRewriteTrie.number_of_active_rules
KnuthBendixRewriteTrie.number_of_classes
KnuthBendixRewriteTrie.number_of_inactive_rules
KnuthBendixRewriteTrie.overlap_policy
KnuthBendixRewriteTrie.presentation
KnuthBendixRewriteTrie.reduce_no_run
KnuthBendixRewriteTrie.total_rules

Full API
--------

.. autoclass:: KnuthBendixRewriteTrie
:class-doc-from: init
:members:
:exclude-members: options
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Knuth-Bendix helpers
====================

This page contains the documentation for various helper functions for
manipulating ``KnuthBendix`` objects. All such functions are contained in the
submodule ``libsemigroups_pybind11.knuth_bendix``.
manipulating :any:`KnuthBendixRewriteTrie` objects. All such functions are
contained in the submodule ``libsemigroups_pybind11.knuth_bendix``.

.. seealso::
:py:class:`overlap`
Expand All @@ -20,9 +20,9 @@ submodule ``libsemigroups_pybind11.knuth_bendix``.
Contents
--------

.. .. currentmodule:: libsemigroups_pybind11.knuth_bendix
.. currentmodule:: libsemigroups_pybind11.knuth_bendix

.. .. autosummary::
.. autosummary::
:nosignatures:

by_overlap_length
Expand All @@ -34,6 +34,7 @@ Contents
Full API
--------

.. .. automodule:: libsemigroups_pybind11.knuth_bendix
.. automodule:: libsemigroups_pybind11.knuth_bendix
:members:
:imported-members:
:exclude-members: KnuthBendix
10 changes: 5 additions & 5 deletions docs/source/main-algorithms/knuth-bendix/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
Knuth-Bendix
=============

This page describes the functionality for the Knuth-Bendix procedure
in ``libsemigroups_pybind11``.
This page describes the functionality for the Knuth-Bendix procedure
in ``libsemigroups_pybind11``.


.. toctree::
:maxdepth: 1

knuth-bendix
kb-helpers
overlap
class
helpers
nested
79 changes: 0 additions & 79 deletions docs/source/main-algorithms/knuth-bendix/knuth-bendix.rst

This file was deleted.

18 changes: 18 additions & 0 deletions docs/source/main-algorithms/knuth-bendix/nested.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.. Copyright (c) 2024 J. D. Mitchell

Distributed under the terms of the GPL license version 3.

The full license is in the file LICENSE, distributed with this software.

.. currentmodule:: libsemigroups_pybind11

The options nested class
========================

This page contains documentation for the nested class
:any:`KnuthBendixRewriteTrie.options` which holds various values that can be used
to control the behaviour of Knuth-Bendix.

.. autoclass:: _libsemigroups_pybind11::KnuthBendixRewriteTrie.options
:members:
:exclude-members: name
14 changes: 0 additions & 14 deletions docs/source/main-algorithms/knuth-bendix/overlap.rst

This file was deleted.

2 changes: 1 addition & 1 deletion docs/source/main-algorithms/todd-coxeter/class/common.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Common methods

This page contains documentation of the methods of :any:`ToddCoxeter`
that are implemented in all of the classes :any:`Congruence`, :any:`Kambites`,
:any:`KnuthBendix`, and :any:`ToddCoxeter`.
:any:`KnuthBendixRewriteTrie`, and :any:`ToddCoxeter`.

.. automethod:: ToddCoxeter.add_generating_pair
.. automethod:: ToddCoxeter.contains
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The full license is in the file LICENSE, distributed with this software.

.. currentmodule:: _libsemigroups_pybind11
.. currentmodule:: libsemigroups_pybind11.todd_coxeter

Class index to word
===================
Expand All @@ -14,6 +14,4 @@ can be used to convert the index of a congruence class to a representative word
belonging to that congruence class.

.. automethod:: ToddCoxeter.current_word_of
.. automethod:: ToddCoxeter.current_str_of
.. automethod:: ToddCoxeter.word_of
.. automethod:: ToddCoxeter.str_of
6 changes: 2 additions & 4 deletions docs/source/main-algorithms/todd-coxeter/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ Contents
.. autosummary::
:nosignatures:

str_class_by_index
word_class_by_index
class_by_index
class_of
word_normal_forms
str_normal_forms
normal_forms
is_non_trivial
non_trivial_classes
partition
Expand Down
6 changes: 2 additions & 4 deletions etc/replace-strings-in-doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

def dict_sub(replacements, string):
"""replacements has the form {"regex1": "replacement", "regex2": "replacement2", ...}"""
global_expression = re.compile(
"|".join("(" + x + ")" for x in replacements)
)
global_expression = re.compile("|".join("(" + x + ")" for x in replacements))
replacements_by_group = {}
group = 1
for expr, replacement in replacements.items():
Expand Down Expand Up @@ -42,7 +40,7 @@ def dive(path):
"PresentationStrings": "Presentation",
r"_libsemigroups_pybind11.": "",
"libsemigroups::Presentation<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >": "Presentation",
"RightActionPPerm16List": "Action",
"RightActionPPerm1List": "Action",
"libsemigroups::BMat8": "BMat8",
"libsemigroups_pybind11.bmat8": "bmat8",
"libsemigroups_pybind11.knuth_bendix": "knuth_bendix",
Expand Down
3 changes: 1 addition & 2 deletions libsemigroups_pybind11/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
lexicographical_compare,
recursive_path_compare,
shortlex_compare,
overlap,
to_presentation,
to_inverse_presentation,
LibsemigroupsError,
Expand Down Expand Up @@ -82,7 +81,7 @@
from .adapters import ImageRightAction, ImageLeftAction


# from .knuth_bendix import KnuthBendix
from .knuth_bendix import KnuthBendix
from .matrix import _Matrix as Matrix, _MatrixKind as MatrixKind
from .presentation import Presentation, InversePresentation
from .transf import (
Expand Down
42 changes: 42 additions & 0 deletions libsemigroups_pybind11/detail/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,45 @@ def wrapper(self, *args, **kwargs):
return result

return wrapper


def template_params_as_kwargs(**kwargs_map):
"""
Usage example:

@template_params_as_kwargs(
Word={str: _str_normal_forms, List[int]: _word_normal_forms}
)
def foo(**kwargs):
pass

will call _str_normal_forms(*args) on calls to foo(Word = str) and call
_word_normal_forms on calls to foo(Word = List[int]).

Currently only works with a single kwarg
"""

def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
if len(kwargs) != len(kwargs_map):
raise TypeError(
f"expected {len(kwargs_map)} keyword argument"
f"{'s'[:len(kwargs_map)^1]}, but found {len(kwargs)}"
)
if kwargs_map.keys() != kwargs.keys():
raise TypeError(
f"expected keyword arguments {tuple(kwargs_map.keys())}, "
f"but found {tuple(kwargs.keys())}"
)
for key, val in kwargs.items():
if val in kwargs_map[key]:
return kwargs_map[key][val](*args)
raise TypeError(
f'expected the value of the keyword argument "{key}" to belong in '
f"{kwargs_map[key].keys()}, but found {val}"
)

return wrapper

return decorator
Loading
Loading