libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
kbe.hpp
1//
2// libsemigroups - C++ library for semigroups and monoids
3// Copyright (C) 2019-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// This file contains the declaration of the class KBE, which can be used as
20// the element_type for a FroidurePin instance. This class just wraps a
21// reduced word of a KnuthBendixImpl instance.
22
23#ifndef LIBSEMIGROUPS_DETAIL_KBE_HPP_
24#define LIBSEMIGROUPS_DETAIL_KBE_HPP_
25
26#include <cstddef> // for size_t
27#include <string> // for string
28#include <utility> // for hash
29
30#include "libsemigroups/adapters.hpp" // for One
31#include "libsemigroups/froidure-pin.hpp" // for FroidurePin
32#include "libsemigroups/obvinf.hpp" // for is_obviously_infinite
33#include "libsemigroups/types.hpp" // for word_type, letter_type
34
35namespace libsemigroups {
36 namespace detail {
37 // This class is used to wrap libsemigroups::internal_string_type into an
38 // object that can be used as generators for a FroidurePin object.
39 template <typename KnuthBendix_>
40 class KBE {
41 using internal_string_type = std::string;
42
43 explicit KBE(internal_string_type const&);
44 explicit KBE(internal_string_type&&);
45
46 public:
47 using knuth_bendix_type = KnuthBendix_;
48
49 KBE() = default;
50
51 KBE(KBE const&) = default;
52 KBE(KBE&&) = default;
53
54 KBE& operator=(KBE const&) = default;
55 KBE& operator=(KBE&&) = default;
56
57 ~KBE() = default;
58
59 // Construct from internal string
60 KBE(knuth_bendix_type&, internal_string_type const&);
61 KBE(knuth_bendix_type&, internal_string_type&&);
62
63 // Construct from external types
64 KBE(knuth_bendix_type&, letter_type const&);
65 KBE(knuth_bendix_type&, word_type const&);
66
67 bool operator==(KBE const&) const;
68 bool operator<(KBE const&) const;
69 void swap(KBE&);
70
71 internal_string_type const& string() const noexcept;
72
73 std::string string(knuth_bendix_type const& kb) const;
74
75 word_type word(knuth_bendix_type const& kb) const;
76
77 friend std::ostringstream& operator<<(std::ostringstream& os,
78 KBE const& kbe) {
79 os << kbe.string();
80 return os;
81 }
82
83 private:
84 internal_string_type _kb_word;
85 };
86
87 } // namespace detail
88
90 // Adapters for KBE class
92
93 template <typename KnuthBendix_>
94 struct Complexity<detail::KBE<KnuthBendix_>> {
95 constexpr size_t
96 operator()(detail::KBE<KnuthBendix_> const&) const noexcept {
97 return LIMIT_MAX;
98 }
99 };
100
101 template <typename KnuthBendix_>
102 struct Degree<detail::KBE<KnuthBendix_>> {
103 constexpr size_t
104 operator()(detail::KBE<KnuthBendix_> const&) const noexcept {
105 return 0;
106 }
107 };
108
109 template <typename KnuthBendix_>
110 struct IncreaseDegree<detail::KBE<KnuthBendix_>> {
111 void operator()(detail::KBE<KnuthBendix_> const&, size_t) const noexcept {}
112 };
113
114 template <typename KnuthBendix_>
115 struct One<detail::KBE<KnuthBendix_>> {
116 detail::KBE<KnuthBendix_>
117 operator()(detail::KBE<KnuthBendix_> const&) const noexcept {
118 return detail::KBE<KnuthBendix_>();
119 }
120
121 detail::KBE<KnuthBendix_> operator()(size_t = 0) const noexcept {
122 return detail::KBE<KnuthBendix_>();
123 }
124 };
125
126 template <typename KnuthBendix_>
127 struct Product<detail::KBE<KnuthBendix_>> {
128 void operator()(detail::KBE<KnuthBendix_>& xy,
129 detail::KBE<KnuthBendix_> const& x,
130 detail::KBE<KnuthBendix_> const& y,
131 KnuthBendix_* kb,
132 size_t) {
133 std::string w(x.string()); // internal_string_type
134 w += y.string();
135 xy = detail::KBE<KnuthBendix_>(*kb, w);
136 }
137 };
138
139 template <typename KnuthBendix_>
140 struct FroidurePinState<detail::KBE<KnuthBendix_>> {
141 using type = KnuthBendix_;
142 };
143
144 // template <>
145 // word_type FroidurePin<detail::KBE<KnuthBendixImpl<>>>::factorisation(
146 // detail::KBE<KnuthBendixImpl<>> const& x);
147
148 // template <>
149 // tril FroidurePin<detail::KBE<KnuthBendixImpl<>>>::is_finite() const;
150
151} // namespace libsemigroups
152
154// Specializations of std::hash and std::equal_to
156
157namespace std {
158 template <typename KnuthBendix_>
159 struct hash<libsemigroups::detail::KBE<KnuthBendix_>> {
160 size_t operator()(libsemigroups::detail::KBE<KnuthBendix_> const& x) const {
161 return hash<string>()(x.string());
162 }
163 };
164
165 template <typename KnuthBendix_>
166 struct equal_to<libsemigroups::detail::KBE<KnuthBendix_>> {
167 bool operator()(libsemigroups::detail::KBE<KnuthBendix_> const& x,
168 libsemigroups::detail::KBE<KnuthBendix_> const& y) const {
169 return x == y;
170 }
171 };
172} // namespace std
173
174#include "kbe.tpp"
175
176#endif // LIBSEMIGROUPS_DETAIL_KBE_HPP_
LimitMax const LIMIT_MAX
Value for the maximum of something.
std::vector< letter_type > word_type
Type for a word over the generators of a semigroup.
Definition types.hpp:101
size_t letter_type
Type for the index of a generator of a semigroup.
Definition types.hpp:98
Namespace for everything in the libsemigroups library.
Definition action.hpp:44
T operator()(T... args)
Adapter for the complexity of multiplication.
Definition adapters.hpp:121
Adapter for the degree of an element.
Definition adapters.hpp:159
Adapter for increasing the degree of an element.
Definition adapters.hpp:199
Adapter for the identity element of the given type.
Definition adapters.hpp:246
Adapter for the product of two elements.
Definition adapters.hpp:284