19#ifndef LIBSEMIGROUPS_FROIDURE_PIN_HPP_
20#define LIBSEMIGROUPS_FROIDURE_PIN_HPP_
23#include <initializer_list>
28#include <unordered_map>
32#include "adapters.hpp"
34#include "exception.hpp"
35#include "froidure-pin-base.hpp"
38#include "detail/bruidhinn-traits.hpp"
39#include "detail/iterator.hpp"
40#include "detail/report.hpp"
41#include "detail/stl.hpp"
43#include "rx/ranges.hpp"
49 struct FroidurePinState {
66 template <
typename Element,
67 typename State =
typename FroidurePinState<Element>::type>
75 using element_type =
typename detail::BruidhinnTraits<Element>::value_type;
188 template <
typename Element,
typename Traits = Fro
idurePinTraits<Element>>
196 using internal_element_type =
197 typename detail::BruidhinnTraits<Element>::internal_value_type;
198 using internal_const_element_type =
199 typename detail::BruidhinnTraits<Element>::internal_const_value_type;
200 using internal_const_reference =
201 typename detail::BruidhinnTraits<Element>::internal_const_reference;
202 using internal_idempotent_pair
206 std::is_const_v<internal_const_element_type>
208 std::remove_pointer_t<internal_const_element_type>>,
209 "internal_const_element_type must be const or pointer to const");
223 using enumerate_index_type = FroidurePinBase::enumerate_index_type;
225 struct InternalEqualTo :
private detail::BruidhinnTraits<Element> {
226 [[nodiscard]]
bool operator()(internal_const_reference x,
227 internal_const_reference y)
const {
228 return EqualTo()(this->to_external_const(x),
229 this->to_external_const(y));
233 struct InternalHash :
private detail::BruidhinnTraits<Element> {
234 [[nodiscard]]
size_t operator()(internal_const_reference x)
const {
235 return Hash()(this->to_external_const(x));
250 using element_type =
typename detail::BruidhinnTraits<Element>::value_type;
259 typename detail::BruidhinnTraits<Element>::const_value_type;
263 typename detail::BruidhinnTraits<Element>::const_reference;
267 typename detail::BruidhinnTraits<Element>::rvalue_reference;
270 using reference =
typename detail::BruidhinnTraits<Element>::reference;
274 typename detail::BruidhinnTraits<Element>::const_pointer;
286 using state_type =
typename Traits::state_type;
289 using Complexity =
typename Traits::Complexity;
292 using Degree =
typename Traits::Degree;
295 using EqualTo =
typename Traits::EqualTo;
298 using Hash =
typename Traits::Hash;
304 using Less =
typename Traits::Less;
307 using One =
typename Traits::One;
310 using Product =
typename Traits::Product;
313 using Swap =
typename Traits::Swap;
316 template <
typename T>
317 static constexpr bool IsState
318 = ((!std::is_void_v<T>) &&std::is_same_v<state_type, T>);
326 internal_element_type _id;
332 mutable internal_element_type _tmp_product;
338 size_t tid = 0)
const {
339 if constexpr (std::is_void_v<state_type>) {
382 template <
typename State,
typename = std::enable_if_t<IsState<State>>>
398 template <
typename State,
typename = std::enable_if_t<IsState<State>>>
420 template <
typename State,
typename = std::enable_if_t<IsState<State>>>
435 template <
typename State,
typename = std::enable_if_t<IsState<State>>>
460 template <
typename Iterator1,
typename Iterator2>
479 template <
typename Iterator1,
typename Iterator2>
541 template <
typename Iterator1,
typename Iterator2>
543 Iterator2 last)
const;
574 template <
typename Iterator1,
typename Iterator2>
576 Iterator2 last)
const;
602 template <
typename Iterator1,
609 Iterator4 last2)
const;
633 template <
typename Iterator1,
637 [[nodiscard]]
bool equal_to(Iterator1 first1,
640 Iterator4 last2)
const {
726#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
996#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
1045 template <
typename Iterator1,
typename Iterator2>
1066 template <
typename Iterator1,
typename Iterator2>
1171 template <
typename Iterator1,
typename Iterator2>
1199 template <
typename Iterator1,
typename Iterator2>
1201 Iterator2 last)
const {
1202 throw_if_degree_too_small(first, last);
1240 template <
typename Iterator1,
typename Iterator2>
1265 template <
typename Iterator1,
typename Iterator2>
1267 throw_if_degree_too_small(first, last);
1299 template <
typename Iterator1,
typename Iterator2>
1330 template <
typename Iterator1,
typename Iterator2>
1332 throw_if_degree_too_small(first, last);
1366 template <
typename Iterator1,
typename Iterator2>
1376 template <
typename Iterator1,
typename Iterator2>
1377 void throw_if_bad_degree(Iterator1, Iterator2)
const;
1379 template <
typename Iterator1,
typename Iterator2>
1380 void throw_if_degree_too_small(Iterator1, Iterator2)
const;
1388 std::is_nothrow_default_constructible_v<InternalEqualTo>&&
noexcept(
1391 void copy_generators_from_elements(
size_t);
1403 template <
typename Iterator1,
typename Iterator2>
1404 void add_generators_before_start(Iterator1, Iterator2);
1406 template <
typename Iterator1,
typename Iterator2>
1407 void add_generators_after_start(Iterator1, Iterator2);
1414 void init_idempotents();
1415 void idempotents(enumerate_index_type,
1416 enumerate_index_type,
1417 enumerate_index_type,
1421 struct DerefPairFirst;
1422 struct AddressOfPairFirst;
1423 struct IteratorPairFirstTraits;
1430 using const_iterator_pair_first
1431 = detail::ConstIteratorStateless<IteratorPairFirstTraits>;
1602 void run_impl()
override;
1604 void report_progress();
1606 bool finished_impl()
const override;
1613 template <
typename Iterator1,
typename Iterator2>
1636 template <
typename Container>
1639 Container
const& gens) {
1655 template <
typename Element>
1672 template <
typename Container>
1674 Container
const& coll) {
1690 template <
typename Container>
1693 Container
const& coll) {
1719 template <
typename Element>
1737 template <
typename Element>
1758 template <
typename Container>
1761 Container
const& coll) {
1781 template <
typename Container>
1785 Container
const& coll) {
1804 template <
typename Element>
1826 template <
typename Element>
1844 template <
typename Container>
1846 Container
const& coll) {
1861 template <
typename Container>
1863 Container
const& coll) {
1878 template <
typename Element>
1895 template <
typename Element>
1915 template <
typename Container>
1918 Container
const& coll) {
1936 template <
typename Container>
1939 Container
const& coll) {
1958 template <
typename Element>
1980 template <
typename Element>
2038 template <
typename Element,
typename Traits>
2063 template <
typename Element,
typename Traits>
2090 template <
typename Element,
typename Traits>
2093 return rx::iterator_range(fp.
cbegin(), fp.
cend());
2114 template <
typename Element,
typename Traits>
2147 template <
typename Element,
typename Traits,
typename Word>
2158 template <
typename Element,
typename Traits,
typename T =
size_t>
2192 template <
typename Element,
typename Traits,
typename Word>
2202 template <
typename Element,
typename Traits,
typename T =
size_t>
2230 template <
typename Element,
typename Traits,
typename Word>
2259 template <
typename Element,
typename Traits,
typename Word>
2288 template <
typename Element,
typename Traits,
typename Word = word_type>
2312 template <
typename Element,
typename Traits,
typename Word>
2340 template <
typename Element,
typename Traits,
typename Word = word_type>
2367 template <
typename Element,
typename Traits,
typename Word>
2399 template <
template <
typename...>
typename Thing,
2401 typename Element =
typename Container::value_type>
2402 [[nodiscard]]
auto make(Container
const& gens)
2437 template <
template <
typename...>
typename Thing,
typename Element>
2467 template <
template <
typename...>
typename Thing,
2471 = std::decay_t<decltype(*std::declval<Iterator1>())>>
2472 [[nodiscard]]
auto make(Iterator1 first, Iterator2 last)
2476 std::is_same_v<std::decay_t<decltype(*std::declval<Iterator2>())>,
2500 template <
typename Element,
typename Traits>
2506#include "froidure-pin.tpp"
element_index_type current_position(Iterator1 first, Iterator2 last) const
Returns the position corresponding to a word.
Definition froidure-pin-base.hpp:311
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:1087
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:88
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:1156
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:1806
size_type generator_index_type
Alias for the index of a generator.
Definition froidure-pin-base.hpp:82
WordGraph< element_index_type > cayley_graph_type
Alias for the types of the left and right Cayley graphs.
Definition froidure-pin-base.hpp:91
uint32_t size_type
Alias for the type of the size of the enumerated semigroup.
Definition froidure-pin-base.hpp:76
Class implementing the Froidure-Pin algorithm.
Definition froidure-pin.hpp:190
typename detail::BruidhinnTraits< Element >::const_pointer const_pointer
Type of element const pointers.
Definition froidure-pin.hpp:272
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:269
typename Traits::EqualTo EqualTo
Adapter for testing equality.
Definition froidure-pin.hpp:294
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:835
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:1022
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:306
FroidurePin & closure(Iterator1 first, Iterator2 last)
Add non-redundant generators in collection.
Definition froidure-pin.hpp:1265
typename detail::BruidhinnTraits< Element >::const_reference const_reference
Type of element const references.
Definition froidure-pin.hpp:261
FroidurePinBase::element_index_type element_index_type
Alias for the index of an element.
Definition froidure-pin.hpp:279
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:291
typename Traits::Less Less
Adapter for comparisons.
Definition froidure-pin.hpp:303
typename detail::BruidhinnTraits< Element >::value_type element_type
Type of the elements.
Definition froidure-pin.hpp:249
FroidurePinBase::cayley_graph_type cayley_graph_type
Alias for the types of the left and right Cayley graphs.
Definition froidure-pin.hpp:282
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:780
typename Traits::Hash Hash
Adapter for hashing.
Definition froidure-pin.hpp:297
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:1346
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:285
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:276
const_iterator_pair_first const_iterator_idempotents
Return type of cbegin_idempotents and cend_idempotents.
Definition froidure-pin.hpp:1456
typename detail::BruidhinnTraits< Element >::rvalue_reference rvalue_reference
Type of element rvalue references.
Definition froidure-pin.hpp:265
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:312
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:288
FroidurePin copy_add_generators(Iterator1 first, Iterator2 last) const
Copy and add a collection of generators.
Definition froidure-pin.hpp:1199
typename Traits::Product Product
Adapter for the product of two elements.
Definition froidure-pin.hpp:309
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:254
FroidurePin copy_closure(Iterator1 first, Iterator2 last)
Copy and add non-redundant generators.
Definition froidure-pin.hpp:1330
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:257
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:636
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:1440
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:300
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:1447
FroidurePin()
Default constructor.
void run()
Run until finished.
enable_if_is_same< Return, Blocks > make(Container const &cont)
Check the arguments, construct a Blocks object, and check it.
Definition bipart.hpp:856
tril
Enum to indicate true, false or not currently knowable.
Definition types.hpp:54
@ TRUE
Value representing true.
Definition types.hpp:58
This namespace contains helper functions for the FroidurePin class template.
Definition froidure-pin-base.hpp:1844
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:1917
auto elements(FroidurePin< Element, Traits > &fp)
Returns a range object containing all of the elements.
Definition froidure-pin.hpp:2115
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:2260
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:1760
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:2194
void add_generators_no_checks(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Add collection of generators from container.
Definition froidure-pin.hpp:1692
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:2232
void closure_no_checks(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Add non-redundant generators from a container.
Definition froidure-pin.hpp:1862
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:1638
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:2149
void add_generators(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Add collection of generators from container.
Definition froidure-pin.hpp:1673
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:2305
auto current_elements(FroidurePin< Element, Traits > const &fp)
Returns a range object containing the so-far enumerated elements.
Definition froidure-pin.hpp:2092
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:1783
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:2205
auto idempotents(FroidurePin< Element, Traits > &fp)
Returns a range object containing all of the idempotents.
Definition froidure-pin.hpp:2039
void closure(FroidurePin< typename Container::value_type > &fp, Container const &coll)
Add non-redundant generators from a container.
Definition froidure-pin.hpp:1845
auto sorted_elements(FroidurePin< Element, Traits > &fp)
Returns a range object containing all of the elements.
Definition froidure-pin.hpp:2064
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:1938
Namespace for everything in the libsemigroups library.
Definition action.hpp:44
Adapter for the complexity of multiplication.
Definition adapters.hpp:128
Adapter for the degree of an element.
Definition adapters.hpp:166
Adapter for testing equality.
Definition adapters.hpp:420
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:453
Adapter for increasing the degree of an element.
Definition adapters.hpp:206
Adapter for comparisons.
Definition adapters.hpp:641
Adapter for the identity element of the given type.
Definition adapters.hpp:253
Adapter for the product of two elements.
Definition adapters.hpp:291
Adapter for swapping.
Definition adapters.hpp:673