Skip to content

Commit 8707115

Browse files
presentation: add making a presentation from FroidurePin
1 parent 33f0663 commit 8707115

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

libsemigroups_pybind11/presentation.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# The full license is in the file LICENSE, distributed with this software.
88

9-
# pylint: disable=no-name-in-module, invalid-name, unused-import
9+
# pylint: disable=no-name-in-module, invalid-name, unused-import, fixme
1010

1111
"""
1212
This package provides the user-facing python part of libsemigroups_pybind11 for
@@ -32,27 +32,29 @@
3232
normalize_alphabet,
3333
redundant_rule_strings,
3434
redundant_rule_words,
35+
FroidurePinBase,
36+
make_from_froidure_pin,
3537
)
3638

3739

38-
def Presentation(alphabet):
40+
def Presentation(arg):
3941
"""
40-
Construct a Presentation instance of the type specified by its argument
41-
(which is the alphabet to be used).
42+
Construct a Presentation instance of the type specified by its argument.
4243
"""
43-
if isinstance(alphabet, PresentationStrings):
44-
result = PresentationStrings(alphabet)
45-
elif isinstance(alphabet, PresentationWords):
46-
result = PresentationWords(alphabet)
47-
elif isinstance(alphabet, str):
44+
if isinstance(arg, PresentationStrings):
45+
result = PresentationStrings(arg)
46+
elif isinstance(arg, PresentationWords):
47+
result = PresentationWords(arg)
48+
elif isinstance(arg, str):
4849
result = PresentationStrings()
49-
result.alphabet(alphabet)
50-
elif isinstance(alphabet, list) and all(
51-
isinstance(x, int) for x in alphabet
52-
):
50+
result.alphabet(arg)
51+
elif isinstance(arg, list) and all(isinstance(x, int) for x in arg):
5352
result = PresentationWords()
54-
result.alphabet(alphabet)
53+
result.alphabet(arg)
54+
elif isinstance(arg, FroidurePinBase):
55+
result = make_from_froidure_pin(arg)
5556
else:
57+
# TODO update this string
5658
raise TypeError("expected string or list of ints argument")
5759
return result
5860

src/present.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
#include <vector> // for vector
2929

3030
// libsemigroups....
31-
#include <libsemigroups/present.hpp> // for Presentation
31+
#include <libsemigroups/froidure-pin-base.hpp> // for FroidurePinBase
32+
#include <libsemigroups/make-present.hpp> // for make
33+
#include <libsemigroups/present.hpp> // for Presentation
3234

3335
// pybind11....
3436
#include <pybind11/pybind11.h> // for class_, init, module
@@ -69,28 +71,21 @@ namespace libsemigroups {
6971
py::overload_cast<size_type>(&Presentation<T>::alphabet))
7072
.def("alphabet",
7173
py::overload_cast<T const &>(&Presentation<T>::alphabet))
72-
.def("alphabet_from_rules",
73-
&Presentation<T>::alphabet_from_rules)
74-
.def("letter",
75-
&Presentation<T>::letter)
76-
.def("index",
77-
&Presentation<T>::index)
74+
.def("alphabet_from_rules", &Presentation<T>::alphabet_from_rules)
75+
.def("letter", &Presentation<T>::letter)
76+
.def("index", &Presentation<T>::index)
7877
.def("contains_empty_word",
7978
py::overload_cast<>(&Presentation<T>::contains_empty_word,
8079
py::const_))
8180
.def("contains_empty_word",
8281
py::overload_cast<bool>(&Presentation<T>::contains_empty_word))
83-
.def_readwrite("rules",
84-
&Presentation<T>::rules)
82+
.def_readwrite("rules", &Presentation<T>::rules)
8583
.def("validate_alphabet",
8684
py::overload_cast<>(&Presentation<T>::validate_alphabet,
8785
py::const_))
88-
.def("validate_letter",
89-
&Presentation<T>::validate_letter)
90-
.def("validate_rules",
91-
&Presentation<T>::validate_rules)
92-
.def("validate",
93-
&Presentation<T>::validate)
86+
.def("validate_letter", &Presentation<T>::validate_letter)
87+
.def("validate_rules", &Presentation<T>::validate_rules)
88+
.def("validate", &Presentation<T>::validate)
9489
.def("__repr__", &presentation_repr<T>);
9590

9691
m.def("add_rule",
@@ -114,6 +109,10 @@ namespace libsemigroups {
114109
m.def("reverse", &presentation::reverse<T>);
115110
m.def("normalize_alphabet", &presentation::normalize_alphabet<T>);
116111

112+
m.def(
113+
"make_from_froidure_pin",
114+
py::overload_cast<FroidurePinBase &>(&make<Presentation<word_type>>));
115+
117116
// TODO add make
118117
}
119118
} // namespace

0 commit comments

Comments
 (0)