libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
froidure-pin.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#ifndef LIBSEMIGROUPS_FROIDURE_PIN_HPP_
20#define LIBSEMIGROUPS_FROIDURE_PIN_HPP_
21
22#include <cstddef> // for size_t
23#include <initializer_list> // for initializer_list
24#include <iterator> // for make_move_iterator
25#include <memory> // for shared_ptr, make_shared
26#include <mutex> // for mutex
27#include <type_traits> // for is_const, remove_pointer
28#include <unordered_map> // for unordered_map
29#include <utility> // for pair
30#include <vector> // for vector
31
32#include "adapters.hpp" // for Complexity, Degree, IncreaseDegree
33#include "debug.hpp" // for LIBSEMIGROUPS_ASSERT
34#include "exception.hpp" // for LIBSEMIGROUPS_EXCEPTION
35#include "froidure-pin-base.hpp" // for FroidurePinBase, FroidurePinBase::s...
36#include "types.hpp" // for letter_type, word_type
37
38#include "detail/bruidhinn-traits.hpp" // for detail::BruidhinnTraits
39#include "detail/iterator.hpp" // for ConstIteratorStateless
40#include "detail/report.hpp" // for report_default
41#include "detail/stl.hpp" // for EqualTo, Hash
42
43#include "rx/ranges.hpp" // for iterator_range
44
46namespace libsemigroups {
47
48 template <typename T>
49 struct FroidurePinState {
50 using type = void;
51 };
52
66 template <typename Element,
67 typename State = typename FroidurePinState<Element>::type>
69 // Require to get the value_type from detail::BruidhinnTraits to remove
70 // pointer to const.
75 using element_type = typename detail::BruidhinnTraits<Element>::value_type;
76
81 using state_type = State;
82
85
88
91
94
97
100
103
106
109 };
110
186 template <typename Element, typename Traits = FroidurePinTraits<Element>>
187 class FroidurePin : private detail::BruidhinnTraits<Element>,
188 public FroidurePinBase {
189 private:
191 // FroidurePin - typedefs - private
193
194 using internal_element_type =
195 typename detail::BruidhinnTraits<Element>::internal_value_type;
196 using internal_const_element_type =
197 typename detail::BruidhinnTraits<Element>::internal_const_value_type;
198 using internal_const_reference =
199 typename detail::BruidhinnTraits<Element>::internal_const_reference;
200 using internal_idempotent_pair
202
203 static_assert(
204 std::is_const_v<internal_const_element_type>
205 || std::is_const_v<
206 std::remove_pointer_t<internal_const_element_type>>,
207 "internal_const_element_type must be const or pointer to const");
208
209 // The elements of a semigroup are stored in _elements, but because of the
210 // way add_generators/closure work, it might not be the case that all the
211 // words of a given length are contiguous in _elements. Hence we require a
212 // means of finding the next element of a given length. In
213 // _enumerate_order, the first K_1 values are element_index_type's equal to
214 // the positions in _elements of the words of length 1, the next K_2 values
215 // are the element_index_type's equal to the positions in _elements of the
216 // words of length 2, and so on.
217 //
218 // This alias is used to distinguish variables that refer to positions in
219 // _elements (element_index_type) from those that refer to positions in
220 // _enumerate_order (enumerate_index_type).
221 using enumerate_index_type = FroidurePinBase::enumerate_index_type;
222
223 struct InternalEqualTo : private detail::BruidhinnTraits<Element> {
224 [[nodiscard]] bool operator()(internal_const_reference x,
225 internal_const_reference y) const {
226 return EqualTo()(this->to_external_const(x),
227 this->to_external_const(y));
228 }
229 };
230
231 struct InternalHash : private detail::BruidhinnTraits<Element> {
232 [[nodiscard]] size_t operator()(internal_const_reference x) const {
233 return Hash()(this->to_external_const(x));
234 }
235 };
236
237 using map_type = std::unordered_map<internal_const_element_type,
239 InternalHash,
240 InternalEqualTo>;
241
242 public:
244 // FroidurePin - typedefs - public
246
248 using element_type = typename detail::BruidhinnTraits<Element>::value_type;
249
251 // This only really exists to allow the python bindings to compile with
252 // gcc-6 + 7 (at least).
253 using value_type = element_type;
254
256 using const_element_type =
257 typename detail::BruidhinnTraits<Element>::const_value_type;
258
260 using const_reference =
261 typename detail::BruidhinnTraits<Element>::const_reference;
262
264 using rvalue_reference =
265 typename detail::BruidhinnTraits<Element>::rvalue_reference;
266
268 using reference = typename detail::BruidhinnTraits<Element>::reference;
269
271 using const_pointer =
272 typename detail::BruidhinnTraits<Element>::const_pointer;
273
276
279
282
284 using state_type = typename Traits::state_type;
285
287 using Complexity = typename Traits::Complexity;
288
290 using Degree = typename Traits::Degree;
291
293 using EqualTo = typename Traits::EqualTo;
294
296 using Hash = typename Traits::Hash;
297
299 using IncreaseDegree = typename Traits::IncreaseDegree;
300
302 using Less = typename Traits::Less;
303
305 using One = typename Traits::One;
306
308 using Product = typename Traits::Product;
309
311 using Swap = typename Traits::Swap;
312
313 private:
314 template <typename T>
315 static constexpr bool IsState
316 = ((!std::is_void_v<T>) &&std::is_same_v<state_type, T>);
317
319 // FroidurePin - data - private
321
324 internal_element_type _id;
326 map_type _map;
327 mutable std::mutex _mtx;
330 mutable internal_element_type _tmp_product;
331
332 void internal_product(reference xy,
335 state_type* stt,
336 size_t tid = 0) const {
337 if constexpr (std::is_void_v<state_type>) {
338 (void) stt; // To silence warnings in g++-9
339 Product()(xy, x, y, tid);
340 } else {
341 Product()(xy, x, y, stt, tid);
342 }
343 }
344
345 public:
347 // FroidurePin - constructors + destructor - public
349
355 FroidurePin();
356
366 FroidurePin& init();
367
380 template <typename State, typename = std::enable_if_t<IsState<State>>>
382 _state = stt;
383 }
384
396 template <typename State, typename = std::enable_if_t<IsState<State>>>
398 init();
399 _state = stt;
400 }
401
418 template <typename State, typename = std::enable_if_t<IsState<State>>>
419 explicit FroidurePin(State const& stt)
420 : FroidurePin(std::make_shared<state_type>(stt)) {}
421
433 template <typename State, typename = std::enable_if_t<IsState<State>>>
434 FroidurePin& init(State const& stt) {
436 }
437
440
442 FroidurePin& operator=(FroidurePin&&) = default;
443
458 template <typename Iterator1, typename Iterator2>
459 FroidurePin(Iterator1 first, Iterator2 last);
460
477 template <typename Iterator1, typename Iterator2>
478 FroidurePin& init(Iterator1 first, Iterator2 last);
479
490 FroidurePin(FroidurePin const& that);
491
493 FroidurePin(FroidurePin&&) = default;
494
495 ~FroidurePin();
496
497 private:
498 void free_data();
499
501 // FroidurePin - constructor - private
503
505
506 public:
508 // FroidurePin - member functions - public
510
539 template <typename Iterator1, typename Iterator2>
540 [[nodiscard]] const_reference to_element_no_checks(Iterator1 first,
541 Iterator2 last) const;
542
572 template <typename Iterator1, typename Iterator2>
573 [[nodiscard]] const_reference to_element(Iterator1 first,
574 Iterator2 last) const;
575
600 template <typename Iterator1,
601 typename Iterator2,
602 typename Iterator3,
603 typename Iterator4>
604 [[nodiscard]] bool equal_to_no_checks(Iterator1 first1,
605 Iterator2 last1,
606 Iterator3 first2,
607 Iterator4 last2) const;
608
631 template <typename Iterator1,
632 typename Iterator2,
633 typename Iterator3,
634 typename Iterator4>
635 [[nodiscard]] bool equal_to(Iterator1 first1,
636 Iterator2 last1,
637 Iterator3 first2,
638 Iterator4 last2) const {
641 return equal_to_no_checks(first1, last1, first2, last2);
642 }
643
655 [[nodiscard]] size_t number_of_generators() const noexcept override;
656
677 [[nodiscard]] const_reference generator(generator_index_type i) const;
678
699 [[nodiscard]] const_reference
701
723
724#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
726#endif
727
761 [[nodiscard]] element_index_type
763
778 //! This function does not trigger any enumeration.
780 element_index_type j) const {
783 return fast_product_no_checks(i, j);
784 }
785
799 [[nodiscard]] size_t number_of_idempotents();
800
816 // TODO(1) improve this it doesn't need to trigger a full enum.
817 [[nodiscard]] bool is_idempotent_no_checks(element_index_type i);
818
833 //! This function triggers a full enumeration.
834 [[nodiscard]] bool is_idempotent(element_index_type i) {
835 run();
837 return is_idempotent_no_checks(i);
838 }
839
857 FroidurePin& reserve(size_t val);
858
872 [[nodiscard]] bool contains(const_reference x);
873
891
910
927 // There's no no-checks version of this, there can't be.
929
944 [[nodiscard]] const_reference at(element_index_type i);
945
961
977
993
994#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
995 // The following are required, they are documented in FroidurePinBase.
996 // Sphinx/doxygen get confused by this, so we don't allow Doxygen to parse
997 // these two declarations.
1000#endif
1001
1020 //! No enumeration is triggered by calls to this function.
1021 [[nodiscard]] tril is_finite() const override {
1022 return tril::TRUE;
1023 }
1024
1043 template <typename Iterator1, typename Iterator2>
1044 FroidurePin& add_generators_no_checks(Iterator1 first, Iterator2 last);
1045
1062 template <typename Iterator1, typename Iterator2>
1063 FroidurePin& add_generators(Iterator1 first, Iterator2 last);
1064
1103
1142
1143 // TODO(1) make the following work
1144 // FroidurePin add_generator(rvalue_reference x);
1145
1167 template <typename Iterator1, typename Iterator2>
1168 [[nodiscard]] FroidurePin
1169 copy_add_generators_no_checks(Iterator1 first, Iterator2 last) const;
1170
1195 template <typename Iterator1, typename Iterator2>
1196 [[nodiscard]] FroidurePin copy_add_generators(Iterator1 first,
1197 Iterator2 last) const {
1198 throw_if_degree_too_small(first, last);
1199 throw_if_inconsistent_degree(first, last);
1200 return copy_add_generators_no_checks(first, last);
1201 }
1202
1203 // TODO(1) copy_add_generator
1204 // TODO(1) copy_add_generators_no_checks
1205
1236 template <typename Iterator1, typename Iterator2>
1237 FroidurePin& closure_no_checks(Iterator1 first, Iterator2 last);
1238
1261 template <typename Iterator1, typename Iterator2>
1262 FroidurePin& closure(Iterator1 first, Iterator2 last) {
1263 throw_if_degree_too_small(first, last);
1264 throw_if_inconsistent_degree(first, last);
1265 return closure_no_checks(first, last);
1266 }
1267
1268 // TODO(1) closure(const_reference)
1269 // TODO(1) closure_no_checks(const_reference)
1270
1295 template <typename Iterator1, typename Iterator2>
1296 [[nodiscard]] FroidurePin copy_closure_no_checks(Iterator1 first,
1297 Iterator2 last);
1298
1326 template <typename Iterator1, typename Iterator2>
1327 [[nodiscard]] FroidurePin copy_closure(Iterator1 first, Iterator2 last) {
1328 throw_if_degree_too_small(first, last);
1329 throw_if_inconsistent_degree(first, last);
1330 return copy_closure_no_checks(first, last);
1331 }
1332
1333 // TODO(1) copy_closure(const_reference)
1334 // TODO(1) copy_closure_no_checks(const_reference)
1335
1342 //! \no_libsemigroups_except
1344 return _state;
1345 }
1346
1362 template <typename Iterator1, typename Iterator2>
1363 static void throw_if_inconsistent_degree(Iterator1 first, Iterator2 last);
1364
1365 private:
1367 // FroidurePin - validation member functions - private
1369
1370 void throw_if_bad_degree(const_reference) const;
1371
1372 template <typename Iterator1, typename Iterator2>
1373 void throw_if_bad_degree(Iterator1, Iterator2) const;
1374
1375 template <typename Iterator1, typename Iterator2>
1376 void throw_if_degree_too_small(Iterator1, Iterator2) const;
1377
1379 // FroidurePin - enumeration member functions - private
1381
1382 void expand(size_type);
1383 void is_one(internal_const_element_type x, element_index_type) noexcept(
1384 std::is_nothrow_default_constructible_v<InternalEqualTo>&& noexcept(
1386
1387 void copy_generators_from_elements(size_t);
1388 void closure_update(element_index_type,
1392 size_type,
1393 size_t const&,
1395 state_type*);
1396
1397 void init_degree(const_reference);
1398
1399 template <typename Iterator1, typename Iterator2>
1400 void add_generators_before_start(Iterator1, Iterator2);
1401
1402 template <typename Iterator1, typename Iterator2>
1403 void add_generators_after_start(Iterator1, Iterator2);
1404
1406 // FroidurePin - initialisation member functions - private
1408
1409 void init_sorted();
1410 void init_idempotents();
1411 void idempotents(enumerate_index_type,
1412 enumerate_index_type,
1413 enumerate_index_type,
1415
1416 // Forward declarations - implemented in froidure-pin.tpp
1417 struct DerefPairFirst;
1418 struct AddressOfPairFirst;
1419 struct IteratorPairFirstTraits;
1420
1422 // FroidurePin - iterators - private
1424
1425 // A type for const iterators through (element, index) pairs of \c this.
1426 using const_iterator_pair_first
1427 = detail::ConstIteratorStateless<IteratorPairFirstTraits>;
1428
1429 public:
1431 // FroidurePin - iterators - public
1438 using const_iterator
1439 = detail::BruidhinnConstIterator<element_type,
1441
1446 using const_iterator_sorted = const_iterator_pair_first;
1447
1455 using const_iterator_idempotents = const_iterator_pair_first;
1456
1476 [[nodiscard]] const_iterator cbegin() const;
1477
1497 [[nodiscard]] const_iterator begin() const;
1498
1518 [[nodiscard]] const_iterator cend() const;
1519
1539 [[nodiscard]] const_iterator end() const;
1540
1554 [[nodiscard]] const_iterator_sorted cbegin_sorted();
1555
1568 [[nodiscard]] const_iterator_sorted cend_sorted();
1569
1583
1596
1597 private:
1598 void run_impl() override;
1599
1600 void report_progress();
1601
1602 bool finished_impl() const override;
1603 };
1604
1609 template <typename Iterator1, typename Iterator2>
1610 FroidurePin(Iterator1, Iterator2)
1612
1613 // Namespace doc is in froidure-pin-base.hpp
1614 namespace froidure_pin {
1615
1630 // NOTE: this isn't called make because it is not constructing anything,
1631 // rather re-initializing.
1632 template <typename Container>
1635 Container const& gens) {
1636 return fp.init(std::begin(gens), std::end(gens));
1637 }
1638
1639 // TODO(1) make the following work
1640 // template <typename Container>
1641 // FroidurePin<typename Container::value_type>&
1642 // init(FroidurePin<typename Container::value_type>& fp, Container&& gens) {
1643 // return fp.init(std::make_move_iterator(std::begin(gens)),
1644 // std::make_move_iterator(std::end(gens)));
1645 // }
1646
1647 // clang-format off
1648 // NOLINTNEXTLINE(whitespace/line_length)
1650 // clang-format on
1651 template <typename Element>
1652 [[nodiscard]] FroidurePin<Element>
1654 return fp.init(std::begin(gens), std::end(gens));
1655 }
1656
1668 template <typename Container>
1670 Container const& coll) {
1671 fp.add_generators(std::begin(coll), std::end(coll));
1672 }
1673
1686 template <typename Container>
1687 void
1692
1693 // TODO(1) make the following work
1694 // template <typename Container>
1695 // FroidurePin<typename Container::value_type>&
1696 // add_generators(FroidurePin<typename Container::value_type>& fp,
1697 // Container&& coll) {
1698 // // Note that this currently doesn't do anything different than the
1699 // // function above.
1700 // return fp.add_generators(std::make_move_iterator(std::begin(coll)),
1701 // std::make_move_iterator(std::end(coll)));
1702 // }
1703
1715 template <typename Element>
1720
1733 template <typename Element>
1738
1754 template <typename Container>
1757 Container const& coll) {
1758 return fp.copy_add_generators(std::begin(coll), std::end(coll));
1759 }
1760
1777 template <typename Container>
1781 Container const& coll) {
1782 return fp.copy_add_generators_no_checks(std::begin(coll), std::end(coll));
1783 }
1784
1800 template <typename Element>
1801 [[nodiscard]] FroidurePin<Element>
1806
1822 template <typename Element>
1823 [[nodiscard]] FroidurePin<Element>
1828
1840 template <typename Container>
1842 Container const& coll) {
1843 fp.closure(std::begin(coll), std::end(coll));
1844 }
1845
1857 template <typename Container>
1859 Container const& coll) {
1860 fp.closure_no_checks(std::begin(coll), std::end(coll));
1861 }
1862
1874 template <typename Element>
1877 fp.closure(std::begin(coll), std::end(coll));
1878 }
1879
1891 template <typename Element>
1896
1911 template <typename Container>
1914 Container const& coll) {
1915 return fp.copy_closure(std::begin(coll), std::end(coll));
1916 }
1917
1932 template <typename Container>
1935 Container const& coll) {
1936 return fp.copy_closure_no_checks(std::begin(coll), std::end(coll));
1937 }
1938
1954 template <typename Element>
1955 [[nodiscard]] FroidurePin<Element>
1960
1976 template <typename Element>
1977 [[nodiscard]] FroidurePin<Element>
1982
1983 // TODO(1) implement the next function
1984 // \brief Returns a range object containing the so-far enumerated
1985 // idempotents.
1986 //
1987 // This function returns a range object containing the so-far enumerated
1988 // idempotents. No enumeration of \p fp is triggered by calls to this
1989 // function.
1990 //
1991 // See TODO(1) for more details about range objects.
1992 //
1993 // \tparam Element the type of the elements in the represented
1994 // semigroup.
1995 //
1996 // \tparam Traits a traits class holding various adapters used by the
1997 // implementation (defaults to FroidurePinTraits).
1998 //
1999 // \param fp the FroidurePin instance.
2000 //
2001 // \returns A range object.
2002 //
2003 // is_idempotent_no_checks current performs a full enum. so this doesn't
2004 // work.
2005 //
2006 // template <typename Element, typename Traits>
2007 // [[nodiscard]] auto
2008 // current_idempotents(FroidurePin<Element, Traits> const& fp) {
2009 // return rx::iterator_range(fp.cbegin(), fp.cend())
2010 // | rx::filter([&fp](auto const& x) {
2011 // return fp.is_idempotent_no_checks(fp.current_position(x));
2012 // });
2013 // }
2014
2034 template <typename Element, typename Traits>
2036 fp.run();
2037 return rx::iterator_range(fp.cbegin_idempotents(), fp.cend_idempotents());
2038 }
2039
2059 template <typename Element, typename Traits>
2061 return rx::iterator_range(fp.cbegin_sorted(), fp.cend_sorted());
2062 }
2063
2064 // TODO(1) current_sorted_elements
2065
2086 template <typename Element, typename Traits>
2087 [[nodiscard]] auto
2089 return rx::iterator_range(fp.cbegin(), fp.cend());
2090 }
2091
2110 template <typename Element, typename Traits>
2111 [[nodiscard]] auto elements(FroidurePin<Element, Traits>& fp) {
2112 fp.run();
2113 return current_elements(fp);
2114 }
2115
2143 template <typename Element, typename Traits, typename Word>
2146 Word const& w) {
2147 return fp.to_element_no_checks(std::begin(w), std::end(w));
2148 }
2149
2150 // clang-format off
2151 // NOLINTNEXTLINE(whitespace/line_length)
2153 // clang-format on
2154 template <typename Element, typename Traits, typename T = size_t>
2161
2188 template <typename Element, typename Traits, typename Word>
2190 to_element(FroidurePin<Element, Traits> const& fp, Word const& w) {
2191 return fp.to_element(std::begin(w), std::end(w));
2192 }
2193
2194 // clang-format off
2195 // NOLINTNEXTLINE(whitespace/line_length)
2197 // clang-format on
2198 template <typename Element, typename Traits, typename T = size_t>
2204
2226 template <typename Element, typename Traits, typename Word>
2227 [[nodiscard]] bool
2229 Word const& x,
2230 Word const& y) {
2231 return fp.equal_to_no_checks(
2232 std::begin(x), std::end(x), std::begin(y), std::end(y));
2233 }
2234
2255 template <typename Element, typename Traits, typename Word>
2256 [[nodiscard]] bool equal_to(FroidurePin<Element, Traits> const& fp,
2257 Word const& x,
2258 Word const& y) {
2259 return fp.equal_to(
2260 std::begin(x), std::end(x), std::begin(y), std::end(y));
2261 }
2262
2284 template <typename Element, typename Traits, typename Word = word_type>
2285 [[nodiscard]] Word minimal_factorisation(
2288
2308 template <typename Element, typename Traits, typename Word>
2311 Word& w,
2313
2336 template <typename Element, typename Traits, typename Word = word_type>
2337 [[nodiscard]] Word
2340
2363 template <typename Element, typename Traits, typename Word>
2364 void
2366 Word& w,
2368
2369 } // namespace froidure_pin
2370
2381
2395 template <template <typename...> typename Thing,
2396 typename Container,
2397 typename Element = typename Container::value_type>
2398 [[nodiscard]] auto make(Container const& gens)
2399 -> std::enable_if_t<std::is_same_v<Thing<Element>, FroidurePin<Element>>,
2402 std::end(gens));
2403 return FroidurePin(std::begin(gens), std::end(gens));
2404 }
2405
2406 // TODO(1) make the following work
2407 // template <typename Container>
2408 // FroidurePin<typename Container::value_type>
2409 // make(Container&& gens) {
2410 // return FroidurePin(std::make_move_iterator(std::begin(gens)),
2411 // std::make_move_iterator(std::end(gens)));
2412 // }
2413
2433 template <template <typename...> typename Thing, typename Element>
2435 -> std::enable_if_t<std::is_same_v<Thing<Element>, FroidurePin<Element>>,
2438 std::end(gens));
2439 return FroidurePin(std::begin(gens), std::end(gens));
2440 }
2441
2463 template <template <typename...> typename Thing,
2464 typename Iterator1,
2465 typename Iterator2,
2466 typename Element
2467 = std::decay_t<decltype(*std::declval<Iterator1>())>>
2468 [[nodiscard]] auto make(Iterator1 first, Iterator2 last)
2469 -> std::enable_if_t<std::is_same_v<Thing<Element>, FroidurePin<Element>>,
2471 static_assert(
2472 std::is_same_v<std::decay_t<decltype(*std::declval<Iterator2>())>,
2473 Element>);
2475 return FroidurePin(first, last);
2476 }
2477
2496 template <typename Element, typename Traits>
2497 [[nodiscard]] std::string
2499
2500} // namespace libsemigroups
2501
2502#include "froidure-pin.tpp"
2503
2504#endif // LIBSEMIGROUPS_FROIDURE_PIN_HPP_
T begin(T... args)
element_index_type current_position(Iterator1 first, Iterator2 last) const
Returns the position corresponding to a word.
Definition froidure-pin-base.hpp:310
FroidurePinBase()
Default constructor.
void minimal_factorisation(Iterator d_first, element_index_type pos)
Output to an iterator the short-lex least word representing an element given by index.
Definition froidure-pin-base.hpp:1086
void throw_if_element_index_out_of_range(element_index_type i) const
Throw an exception if an index is out of range.
size_type element_index_type
Alias for the index of an element.
Definition froidure-pin-base.hpp:87
void factorisation(Iterator d_first, element_index_type pos)
Output to an iterator a word representing an element given by index.
Definition froidure-pin-base.hpp:1155
void throw_if_any_generator_index_out_of_range(Iterator1 first, Iterator2 last) const
Throw an exception if any generator index is out of range.
Definition froidure-pin-base.hpp:1805
size_type generator_index_type
Alias for the index of a generator.
Definition froidure-pin-base.hpp:81
WordGraph< element_index_type > cayley_graph_type
Alias for the types of the left and right Cayley graphs.
Definition froidure-pin-base.hpp:90
uint32_t size_type
Alias for the type of the size of the enumerated semigroup.
Definition froidure-pin-base.hpp:75
Class implementing the Froidure-Pin algorithm.
Definition froidure-pin.hpp:188
typename detail::BruidhinnTraits< Element >::const_pointer const_pointer
Type of element const pointers.
Definition froidure-pin.hpp:270
const_reference generator_no_checks(generator_index_type i) const
Returns the generator with specified index.
const_reference at(element_index_type i)
Access element specified by index with bound checks.
typename detail::BruidhinnTraits< Element >::reference reference
Type of element references.
Definition froidure-pin.hpp:267
typename Traits::EqualTo EqualTo
Adapter for testing equality.
Definition froidure-pin.hpp:292
bool contains(const_reference x)
Test membership of an element.
const_iterator begin() const
Returns a const iterator pointing to the first element (ordered by discovery).
bool is_idempotent(element_index_type i)
Check if an element is an idempotent via its index.
Definition froidure-pin.hpp:833
const_reference sorted_at(element_index_type i)
Access element specified by sorted index with bound checks.
const_iterator cbegin() const
Returns a const iterator pointing to the first element (ordered by discovery).
FroidurePin & operator=(FroidurePin const &)
Copy assignment operator.
const_reference to_element_no_checks(Iterator1 first, Iterator2 last) const
Convert a word in the generators to an element.
tril is_finite() const override
Check finiteness.
Definition froidure-pin.hpp:1020
FroidurePin copy_closure_no_checks(Iterator1 first, Iterator2 last)
Copy and add non-redundant generators.
const_iterator_sorted cbegin_sorted()
Returns a const iterator pointing to the first element (sorted by Less).
typename Traits::One One
Adapter for the identity element of the given type.
Definition froidure-pin.hpp:304
FroidurePin & closure(Iterator1 first, Iterator2 last)
Add non-redundant generators in collection.
Definition froidure-pin.hpp:1261
typename detail::BruidhinnTraits< Element >::const_reference const_reference
Type of element const references.
Definition froidure-pin.hpp:259
FroidurePinBase::element_index_type element_index_type
Alias for the index of an element.
Definition froidure-pin.hpp:277
element_index_type fast_product_no_checks(element_index_type i, element_index_type j) const
Multiply elements via their indices.
bool is_idempotent_no_checks(element_index_type i)
Check if an element is an idempotent via its index.
typename Traits::Degree Degree
Adapter for the degree of an element.
Definition froidure-pin.hpp:289
typename Traits::Less Less
Adapter for comparisons.
Definition froidure-pin.hpp:301
typename detail::BruidhinnTraits< Element >::value_type element_type
Type of the elements.
Definition froidure-pin.hpp:247
FroidurePinBase::cayley_graph_type cayley_graph_type
Alias for the types of the left and right Cayley graphs.
Definition froidure-pin.hpp:280
FroidurePin copy_add_generators_no_checks(Iterator1 first, Iterator2 last) const
Copy and add a collection of generators.
element_index_type fast_product(element_index_type i, element_index_type j) const
Multiply elements via their indices.
Definition froidure-pin.hpp:778
typename Traits::Hash Hash
Adapter for hashing.
Definition froidure-pin.hpp:295
FroidurePin & closure_no_checks(Iterator1 first, Iterator2 last)
Add non-redundant generators in collection.
size_t number_of_idempotents()
Returns the number of idempotents.
element_index_type sorted_position(const_reference x)
Returns the sorted index of an element.
std::shared_ptr< state_type > state() const
Returns a std::shared_ptr to the state (if any).
Definition froidure-pin.hpp:1342
const_reference operator[](element_index_type i) const
Access element specified by index.
typename Traits::state_type state_type
Type of the state used for multiplication (if any).
Definition froidure-pin.hpp:283
FroidurePin & init()
Reinitialize a FroidurePin object.
FroidurePin(Iterator1, Iterator2) -> FroidurePin< std::decay_t< decltype(*std::declval< Iterator1 >())> >
size_t number_of_generators() const noexcept override
Returns the number of generators.
FroidurePinBase::size_type size_type
Alias for the type of the size of the enumerated semigroup.
Definition froidure-pin.hpp:274
const_iterator_pair_first const_iterator_idempotents
Return type of cbegin_idempotents and cend_idempotents.
Definition froidure-pin.hpp:1452
typename detail::BruidhinnTraits< Element >::rvalue_reference rvalue_reference
Type of element rvalue references.
Definition froidure-pin.hpp:263
const_iterator cend() const
Returns a const iterator pointing to one past the last known element.
bool equal_to_no_checks(Iterator1 first1, Iterator2 last1, Iterator3 first2, Iterator4 last2) const
Check equality of words in the generators.
typename Traits::Swap Swap
Adapter for swapping.
Definition froidure-pin.hpp:310
const_iterator_idempotents cend_idempotents()
Returns a const iterator pointing one past the last idempotent.
static void throw_if_inconsistent_degree(Iterator1 first, Iterator2 last)
Throws if the degrees of the elements in a given range are not all equal.
typename Traits::Complexity Complexity
Adapter for the complexity of multiplication.
Definition froidure-pin.hpp:286
FroidurePin copy_add_generators(Iterator1 first, Iterator2 last) const
Copy and add a collection of generators.
Definition froidure-pin.hpp:1195
typename Traits::Product Product
Adapter for the product of two elements.
Definition froidure-pin.hpp:307
const_reference generator(generator_index_type i) const
Returns the generator with specified index.
element_type value_type
Alias for element_type.
Definition froidure-pin.hpp:252
FroidurePin copy_closure(Iterator1 first, Iterator2 last)
Copy and add non-redundant generators.
Definition froidure-pin.hpp:1326
element_index_type to_sorted_position(element_index_type i)
Returns the sorted index of an element via its index.
typename detail::BruidhinnTraits< Element >::const_value_type const_element_type
Type of const elements.
Definition froidure-pin.hpp:255
element_index_type current_position(const_reference x) const
Find the position of an element with no enumeration.
FroidurePin & add_generator_no_checks(const_reference x)
Add a copy of an element to the generators.
const_reference to_element(Iterator1 first, Iterator2 last) const
Convert a word in the generators to an element.
const_iterator end() const
Returns a const iterator pointing one past the last known element.
bool equal_to(Iterator1 first1, Iterator2 last1, Iterator3 first2, Iterator4 last2) const
Check equality of words in the generators.
Definition froidure-pin.hpp:634
std::string to_human_readable_repr(FroidurePin< Element, Traits > const &fp)
Return a human readable representation of a FroidurePin object.
FroidurePin & add_generator(const_reference x)
Add a copy of an element to the generators.
FroidurePin & add_generators(Iterator1 first, Iterator2 last)
Add collection of generators via iterators.
const_iterator_idempotents cbegin_idempotents()
Returns a const iterator pointing at the first idempotent.
detail::BruidhinnConstIterator< element_type, std::vector< internal_element_type > > const_iterator
Return type of cbegin and cend.
Definition froidure-pin.hpp:1436
const_reference sorted_at_no_checks(element_index_type i)
Access element specified by sorted index with bound checks.
typename Traits::IncreaseDegree IncreaseDegree
Adapter for increasing the degree of an element.
Definition froidure-pin.hpp:298
element_index_type position(const_reference x)
Find the position of an element with enumeration if necessary.
const_iterator_sorted cend_sorted()
Returns a const iterator pointing one past the last element (sorted by Less).
FroidurePin & add_generators_no_checks(Iterator1 first, Iterator2 last)
Add collection of generators via iterators.
FroidurePin & reserve(size_t val)
Requests the given capacity for elements.
const_iterator_pair_first const_iterator_sorted
Return type of cbegin_sorted and cend_sorted.
Definition froidure-pin.hpp:1443
FroidurePin()
Default constructor.
void run()
Run until finished.
T declval(T... args)
T end(T... args)
enable_if_is_same< Return, Blocks > make(Container const &cont)
Check the arguments, construct a Blocks object, and check it.
Definition bipart.hpp:798
tril
Enum to indicate true, false or not currently knowable.
Definition types.hpp:56
@ TRUE
Value representing true.
Definition types.hpp:60
T make_shared(T... args)
This namespace contains helper functions for the FroidurePin class template.
Definition froidure-pin-base.hpp:1843
FroidurePin< typename Container::value_type > copy_closure(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Copy and add non-redundant generators from a container.
Definition froidure-pin.hpp:1913
auto elements(FroidurePin< Element, Traits > &fp)
Returns a range object containing all of the elements.
Definition froidure-pin.hpp:2111
bool equal_to(FroidurePin< Element, Traits > const &fp, Word const &x, Word const &y)
Check equality of words in the generators.
Definition froidure-pin.hpp:2256
FroidurePin< typename Container::value_type > copy_add_generators(FroidurePin< typename Container::value_type > const &fp, Container const &coll)
Copy a FroidurePin instance and add a collection of generators from a container.
Definition froidure-pin.hpp:1756
FroidurePin< Element, Traits >::const_reference to_element(FroidurePin< Element, Traits > const &fp, Word const &w)
Convert a word in the generators to an element.
Definition froidure-pin.hpp:2190
void add_generators_no_checks(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Add collection of generators from container.
Definition froidure-pin.hpp:1688
bool equal_to_no_checks(FroidurePin< Element, Traits > const &fp, Word const &x, Word const &y)
Check equality of words in the generators.
Definition froidure-pin.hpp:2228
void closure_no_checks(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Add non-redundant generators from a container.
Definition froidure-pin.hpp:1858
FroidurePin< typename Container::value_type > & init(FroidurePin< typename Container::value_type > &fp, Container const &gens)
Re-initialize a FroidurePin object from a container of generators.
Definition froidure-pin.hpp:1634
FroidurePin< Element, Traits >::const_reference to_element_no_checks(FroidurePin< Element, Traits > const &fp, Word const &w)
Convert a word in the generators to an element.
Definition froidure-pin.hpp:2145
void add_generators(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Add collection of generators from container.
Definition froidure-pin.hpp:1669
void factorisation(FroidurePinBase &fpb, Word &word, FroidurePinBase::element_index_type pos)
Modify a word to contain a word representing an element given by index.
Definition froidure-pin-base.hpp:2304
auto current_elements(FroidurePin< Element, Traits > const &fp)
Returns a range object containing the so-far enumerated elements.
Definition froidure-pin.hpp:2088
FroidurePin< typename Container::value_type > copy_add_generators_no_checks(FroidurePin< typename Container::value_type > const &fp, Container const &coll)
Copy a FroidurePin instance and add a collection of generators from a container.
Definition froidure-pin.hpp:1779
void minimal_factorisation(FroidurePinBase &fpb, Word &word, FroidurePinBase::element_index_type pos)
Modify a word to contain the short-lex least word representing an element given by index.
Definition froidure-pin-base.hpp:2204
auto idempotents(FroidurePin< Element, Traits > &fp)
Returns a range object containing all of the idempotents.
Definition froidure-pin.hpp:2035
void closure(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Add non-redundant generators from a container.
Definition froidure-pin.hpp:1841
auto sorted_elements(FroidurePin< Element, Traits > &fp)
Returns a range object containing all of the elements.
Definition froidure-pin.hpp:2060
FroidurePin< typename Container::value_type > copy_closure_no_checks(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Copy and add non-redundant generators from a container.
Definition froidure-pin.hpp:1934
Namespace for everything in the libsemigroups library.
Definition action.hpp:44
Adapter for the complexity of multiplication.
Definition adapters.hpp:121
Adapter for the degree of an element.
Definition adapters.hpp:159
Adapter for testing equality.
Definition adapters.hpp:413
Traits class for FroidurePin.
Definition froidure-pin.hpp:68
::libsemigroups::Degree< element_type > Degree
Adapter for the degree of an element.
Definition froidure-pin.hpp:87
::libsemigroups::Product< element_type > Product
Adapter for the product of two elements.
Definition froidure-pin.hpp:105
::libsemigroups::Complexity< element_type > Complexity
Adapter for the complexity of multiplication.
Definition froidure-pin.hpp:84
typename detail::BruidhinnTraits< Element >::value_type element_type
The type of the elements of a FroidurePin instance.
Definition froidure-pin.hpp:75
::libsemigroups::Hash< element_type > Hash
Adapter for hashing.
Definition froidure-pin.hpp:93
::libsemigroups::IncreaseDegree< element_type > IncreaseDegree
Adapter for increasing the degree of an element.
Definition froidure-pin.hpp:96
::libsemigroups::Less< element_type > Less
Adapter for comparisons.
Definition froidure-pin.hpp:99
::libsemigroups::Swap< element_type > Swap
Adapter for swapping.
Definition froidure-pin.hpp:108
::libsemigroups::EqualTo< element_type > EqualTo
Adapter for testing equality.
Definition froidure-pin.hpp:90
::libsemigroups::One< element_type > One
Adapter for the identity element of the given type.
Definition froidure-pin.hpp:102
State state_type
The type of the state (if any).
Definition froidure-pin.hpp:81
Adapter for hashing.
Definition adapters.hpp:446
Adapter for increasing the degree of an element.
Definition adapters.hpp:199
Adapter for comparisons.
Definition adapters.hpp:634
Adapter for the identity element of the given type.
Definition adapters.hpp:246
Adapter for the product of two elements.
Definition adapters.hpp:284
Adapter for swapping.
Definition adapters.hpp:666