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;
186 template <
typename Element,
typename Traits = Fro
idurePinTraits<Element>>
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
204 std::is_const_v<internal_const_element_type>
206 std::remove_pointer_t<internal_const_element_type>>,
207 "internal_const_element_type must be const or pointer to const");
221 using enumerate_index_type = FroidurePinBase::enumerate_index_type;
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));
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));
248 using element_type =
typename detail::BruidhinnTraits<Element>::value_type;
257 typename detail::BruidhinnTraits<Element>::const_value_type;
261 typename detail::BruidhinnTraits<Element>::const_reference;
265 typename detail::BruidhinnTraits<Element>::rvalue_reference;
268 using reference =
typename detail::BruidhinnTraits<Element>::reference;
272 typename detail::BruidhinnTraits<Element>::const_pointer;
284 using state_type =
typename Traits::state_type;
287 using Complexity =
typename Traits::Complexity;
290 using Degree =
typename Traits::Degree;
293 using EqualTo =
typename Traits::EqualTo;
296 using Hash =
typename Traits::Hash;
302 using Less =
typename Traits::Less;
305 using One =
typename Traits::One;
308 using Product =
typename Traits::Product;
311 using Swap =
typename Traits::Swap;
314 template <
typename T>
315 static constexpr bool IsState
316 = ((!std::is_void_v<T>) &&std::is_same_v<state_type, T>);
324 internal_element_type _id;
330 mutable internal_element_type _tmp_product;
336 size_t tid = 0)
const {
337 if constexpr (std::is_void_v<state_type>) {
380 template <
typename State,
typename = std::enable_if_t<IsState<State>>>
396 template <
typename State,
typename = std::enable_if_t<IsState<State>>>
418 template <
typename State,
typename = std::enable_if_t<IsState<State>>>
433 template <
typename State,
typename = std::enable_if_t<IsState<State>>>
458 template <
typename Iterator1,
typename Iterator2>
477 template <
typename Iterator1,
typename Iterator2>
539 template <
typename Iterator1,
typename Iterator2>
541 Iterator2 last)
const;
572 template <
typename Iterator1,
typename Iterator2>
574 Iterator2 last)
const;
600 template <
typename Iterator1,
607 Iterator4 last2)
const;
631 template <
typename Iterator1,
635 [[nodiscard]]
bool equal_to(Iterator1 first1,
638 Iterator4 last2)
const {
724#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
994#ifndef LIBSEMIGROUPS_PARSED_BY_DOXYGEN
1043 template <
typename Iterator1,
typename Iterator2>
1062 template <
typename Iterator1,
typename Iterator2>
1167 template <
typename Iterator1,
typename Iterator2>
1195 template <
typename Iterator1,
typename Iterator2>
1197 Iterator2 last)
const {
1198 throw_if_degree_too_small(first, last);
1236 template <
typename Iterator1,
typename Iterator2>
1261 template <
typename Iterator1,
typename Iterator2>
1263 throw_if_degree_too_small(first, last);
1295 template <
typename Iterator1,
typename Iterator2>
1326 template <
typename Iterator1,
typename Iterator2>
1328 throw_if_degree_too_small(first, last);
1362 template <
typename Iterator1,
typename Iterator2>
1372 template <
typename Iterator1,
typename Iterator2>
1373 void throw_if_bad_degree(Iterator1, Iterator2)
const;
1375 template <
typename Iterator1,
typename Iterator2>
1376 void throw_if_degree_too_small(Iterator1, Iterator2)
const;
1384 std::is_nothrow_default_constructible_v<InternalEqualTo>&&
noexcept(
1387 void copy_generators_from_elements(
size_t);
1399 template <
typename Iterator1,
typename Iterator2>
1400 void add_generators_before_start(Iterator1, Iterator2);
1402 template <
typename Iterator1,
typename Iterator2>
1403 void add_generators_after_start(Iterator1, Iterator2);
1410 void init_idempotents();
1411 void idempotents(enumerate_index_type,
1412 enumerate_index_type,
1413 enumerate_index_type,
1417 struct DerefPairFirst;
1418 struct AddressOfPairFirst;
1419 struct IteratorPairFirstTraits;
1426 using const_iterator_pair_first
1427 = detail::ConstIteratorStateless<IteratorPairFirstTraits>;
1598 void run_impl()
override;
1600 void report_progress();
1602 bool finished_impl()
const override;
1609 template <
typename Iterator1,
typename Iterator2>
1632 template <
typename Container>
1635 Container
const& gens) {
1651 template <
typename Element>
1668 template <
typename Container>
1670 Container
const& coll) {
1686 template <
typename Container>
1689 Container
const& coll) {
1715 template <
typename Element>
1733 template <
typename Element>
1754 template <
typename Container>
1757 Container
const& coll) {
1777 template <
typename Container>
1781 Container
const& coll) {
1800 template <
typename Element>
1822 template <
typename Element>
1840 template <
typename Container>
1842 Container
const& coll) {
1857 template <
typename Container>
1859 Container
const& coll) {
1874 template <
typename Element>
1891 template <
typename Element>
1911 template <
typename Container>
1914 Container
const& coll) {
1932 template <
typename Container>
1935 Container
const& coll) {
1954 template <
typename Element>
1976 template <
typename Element>
2034 template <
typename Element,
typename Traits>
2059 template <
typename Element,
typename Traits>
2086 template <
typename Element,
typename Traits>
2089 return rx::iterator_range(fp.
cbegin(), fp.
cend());
2110 template <
typename Element,
typename Traits>
2143 template <
typename Element,
typename Traits,
typename Word>
2154 template <
typename Element,
typename Traits,
typename T =
size_t>
2188 template <
typename Element,
typename Traits,
typename Word>
2198 template <
typename Element,
typename Traits,
typename T =
size_t>
2226 template <
typename Element,
typename Traits,
typename Word>
2255 template <
typename Element,
typename Traits,
typename Word>
2284 template <
typename Element,
typename Traits,
typename Word = word_type>
2308 template <
typename Element,
typename Traits,
typename Word>
2336 template <
typename Element,
typename Traits,
typename Word = word_type>
2363 template <
typename Element,
typename Traits,
typename Word>
2395 template <
template <
typename...>
typename Thing,
2397 typename Element =
typename Container::value_type>
2398 [[nodiscard]]
auto make(Container
const& gens)
2433 template <
template <
typename...>
typename Thing,
typename Element>
2463 template <
template <
typename...>
typename Thing,
2467 = std::decay_t<decltype(*std::declval<Iterator1>())>>
2468 [[nodiscard]]
auto make(Iterator1 first, Iterator2 last)
2472 std::is_same_v<std::decay_t<decltype(*std::declval<Iterator2>())>,
2496 template <
typename Element,
typename Traits>
2502#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: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.
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
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