libsemigroups  v3.0.0
C++ library for semigroups and monoids
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Loading...
Searching...
No Matches
to-presentation.hpp
1//
2// libsemigroups - C++ library for semigroups and monoids
3// Copyright (C) 2023-2025 James D. Mitchell
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17//
18
19#ifndef LIBSEMIGROUPS_TO_PRESENTATION_HPP_
20#define LIBSEMIGROUPS_TO_PRESENTATION_HPP_
21
22#include <algorithm> // for transform, rotate
23#include <string> // for basic_string
24#include <type_traits> // for is_same_v, ena...
25#include <utility> // for move
26#include <vector> // for vector
27
28#include "froidure-pin-base.hpp" // for FroidurePinBase
29#include "knuth-bendix-class.hpp" // for KnuthBendix
30#include "presentation.hpp" // for Presentation
31#include "word-range.hpp" // for human_readable...
32
33#include "detail/knuth-bendix-impl.hpp" // for KnuthBendixImpl
34
35namespace libsemigroups {
36
44
52
54 // FroidurePin -> Presentation
56
88 template <typename Result>
89 auto to(FroidurePinBase& fp) -> std::enable_if_t<
90 std::is_same_v<Presentation<typename Result::word_type>, Result>,
91 Result>;
92
94 // KnuthBendix -> Presentation
96
132 template <template <typename...> typename Thing,
133 typename Word,
134 typename Rewriter,
135 typename ReductionOrder>
136 auto to(KnuthBendix<Word, Rewriter, ReductionOrder>& kb)
137 -> std::enable_if_t<std::is_same_v<Thing<Word>, Presentation<Word>>,
139 return to<Presentation<Word>>(kb);
140 }
141
143 // Presentation + function -> Presentation
145
180 template <typename Result, typename Word, typename Func>
181 auto to(Presentation<Word> const& p, Func&& f) -> std::enable_if_t<
182 std::is_same_v<Presentation<typename Result::word_type>, Result>,
183 Result>;
184
186 // InversePresentation + function -> InversePresentation
188
226 template <typename Result, typename Word, typename Func>
227 auto to(InversePresentation<Word> const& ip, Func&& f) -> std::enable_if_t<
228 std::is_same_v<InversePresentation<typename Result::word_type>, Result>,
229 Result>;
230
232 // Presentation -> Presentation
234
276 template <typename Result, typename Word>
277 auto to(Presentation<Word> const& p) -> std::enable_if_t<
278 std::is_same_v<Presentation<typename Result::word_type>, Result>
279 && !std::is_same_v<typename Result::word_type, Word>,
280 Result>;
281
282 // This function is documented above because Doxygen conflates these two
283 // functions.
284 template <typename Result, typename Word>
285 auto to(Presentation<Word> const& p) noexcept
286 -> std::enable_if_t<std::is_same_v<Presentation<Word>, Result>,
287 Result const&> {
288 return p;
289 }
290
292 // InversePresentation -> InversePresentation
294
338 template <typename Result, typename Word>
339 auto to(InversePresentation<Word> const& ip) noexcept -> std::enable_if_t<
340 std::is_same_v<InversePresentation<typename Result::word_type>, Result>
341 && !std::is_same_v<Word, typename Result::word_type>,
342 Result> {
343 using WordOutput = typename Result::word_type;
344 return to<InversePresentation<WordOutput>>(ip, [&ip](auto val) {
345 return words::human_readable_letter<WordOutput>(ip.index(val));
346 });
347 }
348
349 // This function is documented above because Doxygen conflates these two
350 // functions.
351 template <typename Result, typename Word>
352 auto to(InversePresentation<Word> const& ip) noexcept
353 -> std::enable_if_t<std::is_same_v<InversePresentation<Word>, Result>,
354 Result const&> {
355 return ip;
356 }
357
359 // Presentation -> InversePresentation
361
389 // \note The parameter \p p must not be an `InversePresentation`, otherwise
390 // a compilation error is thrown.
391 // NOTE: not sure this is true anymore so just leaving it out
392#ifdef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
393 // FIXME(1) this is the same hack as elsewhere because Doxygen conflates
394 // functions with trailing return type but the same name and signature.
395 template <template <typename...> typename Thing, typename Word>
396 auto to(Presentation<Word> cont& p) -> std::enable_if_t<
397 std::is_same_v<InversePresentation<Word>, Thing<Word>>,
399#else
400 template <template <typename...> typename Thing, typename Word>
401 auto to(Presentation<Word> const& p) -> std::enable_if_t<
402 std::is_same_v<InversePresentation<Word>, Thing<Word>>,
404#endif
405
406} // namespace libsemigroups
407
408#include "to-presentation.tpp"
409
410#endif // LIBSEMIGROUPS_TO_PRESENTATION_HPP_
Base class for FroidurePin containing non-element specific data and member functions.
Definition froidure-pin-base.hpp:66
For an implementation of inverse presentations for semigroups or monoids.
Definition presentation.hpp:2188
For an implementation of presentations for semigroups or monoids.
Definition presentation.hpp:102
auto to(detail::KnuthBendixImpl< Rewriter, ReductionOrder > &kb) -> std::enable_if_t< std::is_same_v< Presentation< typename Result::word_type >, Result >, Result >
No doc.
Word::value_type human_readable_letter(size_t i)
Returns a character by index in human readable order.
Definition word-range.hpp:2108
Namespace for everything in the libsemigroups library.
Definition action.hpp:44