libsemigroups  v3.1.2
C++ library for semigroups and monoids
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// TODO(1): Make as many of these functions const as possible
34namespace libsemigroups {
35
43
51
53 // FroidurePin -> Presentation
55
87 template <typename Result>
88 auto to(FroidurePinBase& fp) -> std::enable_if_t<
89 std::is_same_v<Presentation<typename Result::word_type>, Result>,
90 Result>;
91
93 // KnuthBendix -> Presentation
95
135 template <typename Result,
136 typename WordIn,
137 typename Rewriter,
138 typename ReductionOrder>
139 auto to(KnuthBendix<WordIn, Rewriter, ReductionOrder>& kb)
140 -> std::enable_if_t<
141 std::is_same_v<Presentation<typename Result::word_type>, Result>,
142 Result>;
143
178#ifdef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
179 // FIXME(1) this is the same hack as elsewhere (deliberately introducing a
180 // typo) because Doxygen conflates functions with trailing return type but the
181 // same name and signature.
182 template <template <typename...> typename Thing,
183 typename Word,
184 typename Rewriter typename ReductionOrder>
185 auto to(KnutBendix<Word, Rewriter, ReductionOrder>& kb)
186 -> std::enable_if_t<std::is_same_v<Thing<Word>, Presentation<Word>>,
188#else
189 template <template <typename...> typename Thing,
190 typename Word,
191 typename Rewriter,
192 typename ReductionOrder>
193 auto to(KnuthBendix<Word, Rewriter, ReductionOrder>& kb)
194 -> std::enable_if_t<std::is_same_v<Thing<Word>, Presentation<Word>>,
196 return to<Presentation<Word>>(kb);
197 }
198#endif
199
201 // Presentation + function -> Presentation
203
238 template <typename Result, typename Word, typename Func>
239 auto to(Presentation<Word> const& p, Func&& f) -> std::enable_if_t<
240 std::is_same_v<Presentation<typename Result::word_type>, Result>,
241 Result>;
242
244 // InversePresentation + function -> InversePresentation
246
284 template <typename Result, typename Word, typename Func>
285 auto to(InversePresentation<Word> const& ip, Func&& f) -> std::enable_if_t<
286 std::is_same_v<InversePresentation<typename Result::word_type>, Result>,
287 Result>;
288
290 // Presentation -> Presentation
292
334 template <typename Result, typename Word>
335 auto to(Presentation<Word> const& p) -> std::enable_if_t<
336 std::is_same_v<Presentation<typename Result::word_type>, Result>
337 && !std::is_same_v<typename Result::word_type, Word>,
338 Result>;
339
340 // This function is documented above because Doxygen conflates these two
341 // functions.
342 template <typename Result, typename Word>
343 auto to(Presentation<Word> const& p) noexcept
344 -> std::enable_if_t<std::is_same_v<Presentation<Word>, Result>,
345 Result const&> {
346 return p;
347 }
348
350 // InversePresentation -> InversePresentation
352
396 template <typename Result, typename Word>
397 auto to(InversePresentation<Word> const& ip) noexcept -> std::enable_if_t<
398 std::is_same_v<InversePresentation<typename Result::word_type>, Result>
399 && !std::is_same_v<Word, typename Result::word_type>,
400 Result> {
401 using WordOutput = typename Result::word_type;
402 return to<InversePresentation<WordOutput>>(ip, [&ip](auto val) {
403 return words::human_readable_letter<WordOutput>(ip.index(val));
404 });
405 }
406
407 // This function is documented above because Doxygen conflates these two
408 // functions.
409 template <typename Result, typename Word>
410 auto to(InversePresentation<Word> const& ip) noexcept
411 -> std::enable_if_t<std::is_same_v<InversePresentation<Word>, Result>,
412 Result const&> {
413 return ip;
414 }
415
417 // Presentation -> InversePresentation
419
447 // \note The parameter \p p must not be an `InversePresentation`, otherwise
448 // a compilation error is thrown.
449 // NOTE: not sure this is true anymore so just leaving it out
450#ifdef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
451 // FIXME(1) this is the same hack as elsewhere because Doxygen conflates
452 // functions with trailing return type but the same name and signature.
453 template <template <typename...> typename Thing, typename Word>
454 auto to(Presentation<Word> cont& p) -> std::enable_if_t<
455 std::is_same_v<InversePresentation<Word>, Thing<Word>>,
457#else
458 template <template <typename...> typename Thing, typename Word>
459 auto to(Presentation<Word> const& p) -> std::enable_if_t<
460 std::is_same_v<InversePresentation<Word>, Thing<Word>>,
462#endif
463
464} // namespace libsemigroups
465
466#include "to-presentation.tpp"
467
468#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:2317
For an implementation of presentations for semigroups or monoids.
Definition presentation.hpp:102
Word::value_type human_readable_letter(size_t i)
Returns a character by index in human readable order.
Definition word-range.hpp:2131
Namespace for everything in the libsemigroups library.
Definition action.hpp:44
auto to(detail::KnuthBendixImpl< Rewriter, ReductionOrder > &kb) -> std::enable_if_t< std::is_same_v< Presentation< typename Result::word_type >, Result >, Result >
No doc.