libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
tce.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 TCE, which is a wrapper
20// around ToddCoxeterImpl class indices, that can be used as the element type
21// for the FroidurePin class template. This file also contains specializations
22// of the adapters complexity, degree, less, one, product, and std::hash for
23// TCE.
24
25#ifndef LIBSEMIGROUPS_DETAIL_TCE_HPP_
26#define LIBSEMIGROUPS_DETAIL_TCE_HPP_
27
28#include <cstddef> // for size_t
29#include <sstream> // for ostream, ostringstream
30#include <type_traits> // for integral_constant
31#include <utility> // for hash
32
33#include "libsemigroups/adapters.hpp" // for Complexity, Degree, Less, One, Product, ...
34#include "libsemigroups/constants.hpp" // for LIMIT_MAX
35#include "libsemigroups/todd-coxeter.hpp" // for ToddCoxeterImpl
36
37#include "string.hpp" // for to_string
38
39namespace libsemigroups {
40 template <typename T>
41 struct FroidurePinState;
42
43 namespace detail {
44
45 class TCE {
46 public:
47 using node_type = typename ToddCoxeterImpl::node_type;
48 using word_graph_type = typename ToddCoxeterImpl::word_graph_type;
49
50 TCE() noexcept = default;
51 TCE(TCE const&) noexcept = default;
52 TCE(TCE&&) noexcept = default;
53 TCE& operator=(TCE const&) noexcept = default;
54 TCE& operator=(TCE&&) noexcept = default;
55 ~TCE() = default;
56
57 explicit TCE(node_type i) noexcept : _index(i) {}
58
59 bool operator==(TCE const& that) const noexcept {
60 return _index == that._index;
61 }
62
63 bool operator<(TCE const& that) const noexcept {
64 return _index < that._index;
65 }
66
67 TCE one() const noexcept {
68 return TCE(0);
69 }
70
71 operator node_type() const {
72 return _index;
73 }
74
75 private:
76 // Note that the value of the class_index_type _value below is the
77 // actual class_index_type used in the ToddCoxeterImpl class and not that
78 // number minus 1, which is what "class_index" means in the context of
79 // CongruenceCommon objects.
80 node_type _index;
81 };
82
83 // The following are not really required but are here as a reminder that
84 // TCE are used in BruidhinnTraits which depends on the values in the
85 // static_asserts below.
86 static_assert(std::is_trivial<TCE>::value, "TCE is not trivial!!!");
87 static_assert(std::integral_constant<bool, (sizeof(TCE) <= 8)>::value,
88 "TCE's sizeof exceeds 8!!");
89 } // namespace detail
90
93 detail::TCE const& x) {
94 os << "TCE(" << detail::TCE::node_type(x) << ")";
95 return os;
96 }
97
99 inline std::ostream& operator<<(std::ostream& os, detail::TCE const& x) {
100 os << ::libsemigroups::detail::to_string(x);
101 return os;
102 }
103
104 // Specialization of the adapter libsemigroups::Complexity for detail::TCE.
105 template <>
106 struct Complexity<detail::TCE> {
107 // Returns LIMIT_MAX, because it is not possible to multiply arbitrary TCE
108 // instances, only arbitrary TCE by a TCE representing a generator (see
109 // TCE::operator*). This adapter is used by the FroidurePin class to
110 // determine if it is better to trace paths in the Cayley graph or to
111 // directly multiply elements (using the \c * operator). Since LIMIT_MAX
112 // is returned, elements are not directly multiplied by the \c * operator
113 // (except if the right hand argument represents a TCE).
114 constexpr size_t operator()(detail::TCE const&) const noexcept {
115 return LIMIT_MAX;
116 }
117 };
118
119 template <>
120 struct Degree<detail::TCE> {
121 constexpr size_t operator()(detail::TCE const&) const noexcept {
122 return 0;
123 }
124 };
125
126 template <>
127 struct IncreaseDegree<detail::TCE> {
128 void operator()(detail::TCE const&, size_t) const noexcept {}
129 };
130
132 template <>
133 struct One<detail::TCE> {
135 detail::TCE operator()(detail::TCE const& x) const noexcept {
136 return x.one();
137 }
138 };
139
140 template <>
141 struct Product<detail::TCE> {
142 void operator()(detail::TCE& xy,
143 detail::TCE const& x,
144 detail::TCE const& y,
145 detail::TCE::word_graph_type* t,
146 size_t = 0) const {
147 // y- 1, x????
148 xy = detail::TCE(t->target_no_checks(x, y - 1));
149 }
150 };
151
152 template <>
153 struct FroidurePinState<detail::TCE> {
154 using type = typename detail::ToddCoxeterImpl::word_graph_type;
155 };
156} // namespace libsemigroups
157
158namespace std {
159 template <>
160 struct hash<libsemigroups::detail::TCE> {
161 using node_type = libsemigroups::detail::TCE::node_type;
162 size_t operator()(libsemigroups::detail::TCE const& x) const noexcept {
163 return std::hash<node_type>()(x);
164 }
165 };
166} // namespace std
167
168#endif // LIBSEMIGROUPS_DETAIL_TCE_HPP_
std::ostringstream & operator<<(std::ostringstream &os, BMat8 const &x)
Insertion operator.
LimitMax const LIMIT_MAX
Value for the maximum of something.
Namespace for everything in the libsemigroups library.
Definition action.hpp:44
T operator()(T... args)
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