-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8261f17
commit bb244e1
Showing
32 changed files
with
1,359 additions
and
2,039 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.. 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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright (c) 2024, J. D. Mitchell, Joseph Edwards | ||
# | ||
# Distributed under the terms of the GPL license version 3. | ||
# | ||
# The full license is in the file LICENSE, distributed with this software. | ||
|
||
# pylint: disable=no-name-in-module, unused-import, protected-access, | ||
# pylint: disable=missing-function-docstring | ||
|
||
""" | ||
This package provides the user-facing python part of libsemigroups_pybind11 for | ||
the KnuthBendix class from libsemigroups. | ||
""" | ||
|
||
from functools import wraps as _wraps | ||
from typing import List | ||
|
||
from _libsemigroups_pybind11 import ( | ||
KnuthBendixRewriteFromLeft as _KnuthBendixRewriteFromLeft, | ||
KnuthBendixRewriteTrie as _KnuthBendixRewriteTrie, | ||
PresentationStrings as _PresentationStrings, | ||
PresentationWords as _PresentationWords, | ||
congruence_kind as _congruence_kind, | ||
knuth_bendix_by_overlap_length as by_overlap_length, | ||
knuth_bendix_str_normal_forms as _knuth_bendix_str_normal_forms, | ||
knuth_bendix_word_normal_forms as _knuth_bendix_word_normal_forms, | ||
knuth_bendix_str_non_trivial_classes as _knuth_bendix_str_non_trivial_classes, | ||
knuth_bendix_word_non_trivial_classes as _knuth_bendix_word_non_trivial_classes, | ||
knuth_bendix_redundant_rule as redundant_rule, | ||
knuth_bendix_is_reduced as is_reduced, | ||
) | ||
|
||
from .detail.decorators import ( | ||
may_return_positive_infinity as _may_return_positive_infinity, | ||
) | ||
|
||
_Presentation = (_PresentationStrings, _PresentationWords) | ||
_KnuthBendix = (_KnuthBendixRewriteFromLeft, _KnuthBendixRewriteTrie) | ||
|
||
for KB in _KnuthBendix: | ||
KB.number_of_classes = _may_return_positive_infinity(KB._number_of_classes) | ||
|
||
|
||
def KnuthBendix(*args, rewriter="RewriteTrie"): # pylint: disable=invalid-name | ||
""" | ||
Construct a KnuthBendix instance of the type specified by its arguments | ||
""" | ||
if len(args) not in (0, 2): | ||
raise TypeError(f"expected 0 or 2 positional arguments, found {len(args)}") | ||
|
||
if len(args) == 2 and not isinstance(args[0], _congruence_kind): | ||
raise TypeError( | ||
( | ||
"the 1st positional argument must be congruence_kind, " | ||
f"found ({type(args[0])})" | ||
) | ||
) | ||
|
||
if len(args) == 2 and not isinstance(args[1], _Presentation): | ||
raise TypeError( | ||
( | ||
"the 2nd positional argument must be presentation, " | ||
f"found ({type(args[1])})" | ||
) | ||
) | ||
|
||
if rewriter == "RewriteFromLeft": | ||
result = _KnuthBendixRewriteFromLeft(*args) | ||
elif rewriter == "RewriteTrie": | ||
result = _KnuthBendixRewriteTrie(*args) | ||
else: | ||
raise TypeError( | ||
( | ||
f'expected the rewriter kwarg to be either "RewriteTrie" or ' | ||
f'"RewriteFromLeft", but found {rewriter}' | ||
) | ||
) | ||
|
||
return result | ||
|
||
|
||
@_wraps(_knuth_bendix_str_non_trivial_classes) | ||
def non_trivial_classes(kb1: KnuthBendix, kb2: KnuthBendix, **kwargs): | ||
if len(kwargs) != 1: | ||
raise TypeError(f"expected 1 keyword argument, but found {len(kwargs)}") | ||
if "Word" not in kwargs: | ||
raise TypeError( | ||
f'expected keyword argument "Word", but found "{next(iter(kwargs))}"' | ||
) | ||
if kwargs["Word"] is List[int]: | ||
return _knuth_bendix_word_non_trivial_classes(kb1, kb2) | ||
if kwargs["Word"] is str: | ||
return _knuth_bendix_str_non_trivial_classes(kb1, kb2) | ||
|
||
val = kwargs["Word"] | ||
val = f'"{val}"' if isinstance(val, str) else val | ||
|
||
raise TypeError( | ||
'expected the value of the keyword argument "Word" to be ' | ||
f"List[int] or str, but found {val}" | ||
) | ||
|
||
|
||
@_wraps(_knuth_bendix_str_normal_forms) | ||
def normal_forms(kb: KnuthBendix, **kwargs): | ||
if len(kwargs) != 1: | ||
raise TypeError(f"expected 1 keyword argument, but found {len(kwargs)}") | ||
if "Word" not in kwargs: | ||
raise TypeError( | ||
f'expected keyword argument "Word", but found "{next(iter(kwargs))}"' | ||
) | ||
if kwargs["Word"] is List[int]: | ||
return _knuth_bendix_word_normal_forms(kb) | ||
if kwargs["Word"] is str: | ||
return _knuth_bendix_str_normal_forms(kb) | ||
|
||
val = kwargs["Word"] | ||
val = f'"{val}"' if isinstance(val, str) else val | ||
|
||
raise TypeError( | ||
'expected the value of the keyword argument "Word" to be ' | ||
f"List[int] or str, but found {val}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.