22#ifndef LIBSEMIGROUPS_HPCOMBI_HPP_
23#define LIBSEMIGROUPS_HPCOMBI_HPP_
29#if defined(LIBSEMIGROUPS_HPCOMBI_ENABLED)
31#pragma GCC diagnostic push
32#pragma GCC diagnostic ignored "-Wpedantic"
33#pragma GCC diagnostic ignored "-Wswitch-default"
35#include "hpcombi/hpcombi.hpp"
37#pragma GCC diagnostic pop
41#include <unordered_map>
43#include "adapters.hpp"
44#include "constants.hpp"
46#include "exception.hpp"
50#include <unordered_map>
52#include "exception.hpp"
59 template <
typename Iterator>
60 void throw_if_duplicates(
63 std::unordered_map<std::decay_t<
decltype(*first)>,
size_t>& seen) {
65 for (
auto it = first; it != last; ++it) {
67 auto [pos, inserted] = seen.emplace(*it, seen.size());
70 "duplicate value, found {} in position {}, first "
71 "occurrence in position {}",
81 template <
typename Iterator>
82 void throw_if_duplicates(Iterator first, Iterator last) {
83 std::unordered_map<std::decay_t<
decltype(*first)>,
size_t> seen;
84 throw_if_duplicates(first, last, seen);
88#if defined(LIBSEMIGROUPS_HPCOMBI_ENABLED) \
89 || defined(LIBSEMIGROUPS_PARSED_BY_DOXYGEN)
111 template <
typename TPTransf16Sub
class>
113 std::enable_if_t<std::is_base_of_v<HPCombi::PTransf16,
114 TPTransf16Subclass>>> {
121 constexpr size_t operator()(TPTransf16Subclass
const&)
const noexcept {
134 template <
typename TPTransf16Sub
class>
136 std::enable_if_t<std::is_base_of_v<HPCombi::PTransf16,
137 TPTransf16Subclass>>> {
144 constexpr size_t operator()(TPTransf16Subclass
const&)
const noexcept {
157 template <
typename TPTransf16Sub
class>
158 struct One<TPTransf16Subclass,
160 std::is_base_of_v<HPCombi::PTransf16, TPTransf16Subclass>>> {
168 return TPTransf16Subclass::one();
176 TPTransf16Subclass
operator()(TPTransf16Subclass
const&)
const noexcept {
177 return TPTransf16Subclass::one();
192 template <
typename TPTransf16Sub
class>
194 std::enable_if_t<std::is_base_of_v<HPCombi::PTransf16,
195 TPTransf16Subclass>>> {
203 TPTransf16Subclass
const& x,
204 TPTransf16Subclass
const& y,
205 size_t = 0) const noexcept {
218 template <
typename TPTransf16Sub
class>
219 struct Swap<TPTransf16Subclass,
221 std::is_base_of_v<HPCombi::PTransf16, TPTransf16Subclass>>> {
229 TPTransf16Subclass& y)
const noexcept {
249 HPCombi::Perm16
operator()(HPCombi::Perm16
const& x)
const noexcept {
262 template <
typename TIntType>
265 std::enable_if_t<std::is_integral_v<TIntType>>> {
275 HPCombi::Perm16
const& p)
const noexcept {
276 LIBSEMIGROUPS_ASSERT(pt < 16);
277 res =
static_cast<TIntType
>(p[pt]);
282 HPCombi::Perm16
const& p)
const noexcept {
283 LIBSEMIGROUPS_ASSERT(pt < 16);
307 HPCombi::PPerm16
const& x,
308 HPCombi::PPerm16
const& y)
const noexcept {
331 HPCombi::PPerm16
const& x,
332 HPCombi::PPerm16
const& y)
const noexcept {
350 constexpr inline size_t operator()(HPCombi::BMat8
const&)
const noexcept {
367 constexpr inline size_t operator()(HPCombi::BMat8
const&)
const noexcept {
386 inline void operator()(HPCombi::BMat8
const&)
const noexcept {}
401 inline HPCombi::BMat8
operator()(HPCombi::BMat8
const& x)
const noexcept {
407 inline HPCombi::BMat8
operator()(
size_t = 0) const noexcept {
408 return HPCombi::BMat8::one();
425 HPCombi::BMat8
const& x,
426 HPCombi::BMat8
const& y,
427 size_t = 0) const noexcept {
448 HPCombi::BMat8
const& pt,
449 HPCombi::BMat8
const& x)
const noexcept {
450 res = (pt * x).row_space_basis();
471 HPCombi::BMat8 x)
const noexcept {
472 res = (x * pt).col_space_basis();
488 inline HPCombi::BMat8
operator()(HPCombi::BMat8
const& x)
const noexcept {
489 LIBSEMIGROUPS_ASSERT(x * x.transpose() == x.one());
490 return x.transpose();
543 HPCombi::BMat8
const& x)
const noexcept {
544 res = x.row_space_basis();
562 HPCombi::BMat8
const& x)
const noexcept {
563 res = x.col_space_basis();
579 inline size_t operator()(HPCombi::BMat8
const& x)
const noexcept {
580 return x.row_space_size();
625 struct Lambda<HPCombi::PPerm16, HPCombi::PPerm16> {
633 HPCombi::PPerm16
const& x)
const noexcept {
644 struct Rho<HPCombi::PPerm16, HPCombi::PPerm16> {
649 HPCombi::PPerm16
const& x)
const noexcept {
673 HPCombi::Transf16
const& x,
674 HPCombi::PTransf16
const& y)
const noexcept {
675 res = (y *
static_cast<HPCombi::PTransf16
>(
static_cast<HPCombi::epu8
>(x)))
695 HPCombi::Transf16
const& x,
696 HPCombi::Vect16
const& y)
const noexcept {
697 HPCombi::Vect16 buf = {0xff,
714 for (
size_t i = 0; i < 16; ++i) {
715 if (buf[x[y[i]]] == 0xff) {
716 buf[x[y[i]]] = next++;
718 res[i] = buf[x[y[i]]];
736 using type = HPCombi::PTransf16;
762 struct Lambda<HPCombi::Transf16, HPCombi::PTransf16> {
771 HPCombi::Transf16
const& x)
const noexcept {
784 struct Rho<HPCombi::Transf16, HPCombi::Vect16> {
792 HPCombi::Transf16
const& x)
const noexcept {
793 HPCombi::Vect16 buf = {0xff,
810 for (
size_t i = 0; i < 16; ++i) {
811 if (buf[x[i]] == 0xff) {
828 template <
typename T>
830 std::enable_if_t<std::is_base_of_v<HPCombi::PTransf16, T>,
866 template <
typename Return,
typename Container>
869 if (cont.size() > 16) {
871 "most 16, but found {}",
874 auto result = HPCombi::Transf16(cont);
875 if (!result.validate()) {
878 [](
auto const& val) {
return val > 15; });
880 "[0, 16), found {} in position {}",
909 template <
typename Return,
typename Container>
912 if (cont.size() > 16) {
914 "most 16, but found {}",
917 auto result = HPCombi::Perm16(cont);
918 if (!result.HPCombi::Transf16::validate()) {
921 [](
auto const& val) {
return val > 15; });
923 "[0, 16), found {} in position {}",
927 if (!result.validate()) {
956 template <
typename Return,
typename Container>
959 if (cont.size() > 16) {
961 "most 16, but found {}",
964 auto result = HPCombi::PPerm16(cont);
965 if (!result.HPCombi::PTransf16::validate()) {
968 return val != 0xFF && val > 15;
971 "[0, 16) or 0xFF (= {}), found {} in position {}",
976 if (!result.validate()) {
1005 template <
typename Return>
1012 "the 3rd argument is not valid, expected <=16, found {}", deg);
1013 }
else if (dom.
size() != ran.
size()) {
1015 "size {} but range has size {}",
1018 }
else if (!(dom.
empty()
1021 "domain value out of bounds, found {}, must be less than {}",
1027 detail::throw_if_duplicates(dom.
cbegin(), dom.
cend(), seen);
1028 detail::throw_if_duplicates(ran.
cbegin(), ran.
cend(), seen);
1029 HPCombi::PPerm16 result(dom, ran, deg);
1030 LIBSEMIGROUPS_ASSERT(result.validate());
1057 template <
typename Return,
typename Int>
1088 template <
typename Return>
1089 [[nodiscard]] std::enable_if_t<std::is_base_of_v<HPCombi::PTransf16, Return>,
Fast boolean matrices of dimension up to 8 x 8.
Definition bmat8.hpp:74
Undefined const UNDEFINED
Value for something undefined.
#define LIBSEMIGROUPS_EXCEPTION(...)
Throw a LibsemigroupsException.
Definition exception.hpp:95
enable_if_is_same< Return, Blocks > make(Container const &cont)
Check the arguments, construct a Blocks object, and check it.
Definition bipart.hpp:798
PPerm< N, Scalar > left_one(PPerm< N, Scalar > const &f)
Returns the left one of a partial perm.
PPerm< N, Scalar > right_one(PPerm< N, Scalar > const &f)
Returns the right one of a partial perm.
std::enable_if_t< std::is_same_v< Given, Expected >, Expected > enable_if_is_same
Alias equal to the second template parameter if both template parameters are equal.
Definition types.hpp:50
Namespace for everything in the libsemigroups library.
Definition action.hpp:44
constexpr size_t operator()(HPCombi::BMat8 const &) const noexcept
Returns 0.
Definition hpcombi.hpp:350
constexpr size_t operator()(TPTransf16Subclass const &) const noexcept
Returns 0.
Definition hpcombi.hpp:121
Adapter for the complexity of multiplication.
Definition adapters.hpp:121
constexpr size_t operator()(HPCombi::BMat8 const &) const noexcept
Returns 8.
Definition hpcombi.hpp:367
constexpr size_t operator()(TPTransf16Subclass const &) const noexcept
Returns 16.
Definition hpcombi.hpp:144
Adapter for the degree of an element.
Definition adapters.hpp:159
void operator()(HPCombi::BMat8 &res, HPCombi::BMat8 pt, HPCombi::BMat8 x) const noexcept
Stores the image of pt under the left action of x.
Definition hpcombi.hpp:469
void operator()(HPCombi::PPerm16 &res, HPCombi::PPerm16 const &x, HPCombi::PPerm16 const &y) const noexcept
Stores the idempotent in res.
Definition hpcombi.hpp:330
void operator()(HPCombi::Vect16 &res, HPCombi::Transf16 const &x, HPCombi::Vect16 const &y) const noexcept
Store image of x under the left action of y.
Definition hpcombi.hpp:694
Adapter for the value of a left action.
Definition adapters.hpp:350
void operator()(HPCombi::BMat8 &res, HPCombi::BMat8 const &pt, HPCombi::BMat8 const &x) const noexcept
Store the image of pt under the right action of x.
Definition hpcombi.hpp:447
void operator()(HPCombi::PPerm16 &res, HPCombi::PPerm16 const &x, HPCombi::PPerm16 const &y) const noexcept
Stores the idempotent in res.
Definition hpcombi.hpp:306
TIntType operator()(TIntType const &pt, HPCombi::Perm16 const &p) const noexcept
Returns the image of pt under p.
Definition hpcombi.hpp:281
void operator()(TIntType &res, TIntType const &pt, HPCombi::Perm16 const &p) const noexcept
Stores the image of pt under p.
Definition hpcombi.hpp:273
void operator()(HPCombi::PTransf16 &res, HPCombi::Transf16 const &x, HPCombi::PTransf16 const &y) const noexcept
Store the image of x under the right action of y.
Definition hpcombi.hpp:672
Adapter for the value of a right action.
Definition adapters.hpp:392
void operator()(HPCombi::BMat8 const &) const noexcept
Does nothing.
Definition hpcombi.hpp:386
Adapter for increasing the degree of an element.
Definition adapters.hpp:199
HPCombi::BMat8 operator()(HPCombi::BMat8 const &x) const noexcept
Returns the group inverse of x.
Definition hpcombi.hpp:488
HPCombi::Perm16 operator()(HPCombi::Perm16 const &x) const noexcept
Returns the inverse of x.
Definition hpcombi.hpp:249
Adapter for the inverse of an element.
Definition adapters.hpp:319
void operator()(HPCombi::BMat8 &res, HPCombi::BMat8 const &x) const noexcept
Store the lambda value of x as used in the Konieczny algorithm.
Definition hpcombi.hpp:542
void operator()(HPCombi::PPerm16 &res, HPCombi::PPerm16 const &x) const noexcept
Definition hpcombi.hpp:632
void operator()(HPCombi::PTransf16 &res, HPCombi::Transf16 const &x) const noexcept
Stores the identity function on the image of x.
Definition hpcombi.hpp:770
Adapter for the action on LambdaValue's.
Definition adapters.hpp:833
HPCombi::BMat8 type
The type of Lambda value.
Definition hpcombi.hpp:511
HPCombi::PPerm16 type
The type of Lambda values.
Definition hpcombi.hpp:600
HPCombi::PTransf16 type
The type of Lambda values.
Definition hpcombi.hpp:736
Adapter for lambda functions.
Definition adapters.hpp:793
HPCombi::BMat8 operator()(HPCombi::BMat8 const &x) const noexcept
Returns x.one().
Definition hpcombi.hpp:401
HPCombi::BMat8 operator()(size_t=0) const noexcept
Returns HPCombi::BMat8::one.
Definition hpcombi.hpp:407
TPTransf16Subclass operator()(size_t=0) const noexcept
Returns the identity for HPCombi::PTransf16.
Definition hpcombi.hpp:167
TPTransf16Subclass operator()(TPTransf16Subclass const &) const noexcept
Returns the identity for HPCombi::PTransf16.
Definition hpcombi.hpp:176
Adapter for the identity element of the given type.
Definition adapters.hpp:246
void operator()(HPCombi::BMat8 &xy, HPCombi::BMat8 const &x, HPCombi::BMat8 const &y, size_t=0) const noexcept
Changes xy in-place to hold the product of x and y.
Definition hpcombi.hpp:424
void operator()(TPTransf16Subclass &xy, TPTransf16Subclass const &x, TPTransf16Subclass const &y, size_t=0) const noexcept
Modifies xy in-place to be the product of x and y.
Definition hpcombi.hpp:202
Adapter for the product of two elements.
Definition adapters.hpp:284
size_t operator()(HPCombi::BMat8 const &x) const noexcept
Returns the rank of x as used in the Konieczny algorithm.
Definition hpcombi.hpp:579
size_t operator()(T const &x) const noexcept
Returns the rank of x as used in the Konieczny algorithm.
Definition hpcombi.hpp:837
Adapter for calculating ranks.
Definition adapters.hpp:930
void operator()(HPCombi::BMat8 &res, HPCombi::BMat8 const &x) const noexcept
Store the rho value of x as used in the Konieczny algorithm.
Definition hpcombi.hpp:561
void operator()(HPCombi::PPerm16 &res, HPCombi::PPerm16 const &x) const noexcept
Definition hpcombi.hpp:648
void operator()(HPCombi::Vect16 &res, HPCombi::Transf16 const &x) const noexcept
Stores the kernel of x.
Definition hpcombi.hpp:791
Adapter for the action on RhoValue's.
Definition adapters.hpp:854
HPCombi::BMat8 type
The type of Rho values for HPCombi::BMat8.
Definition hpcombi.hpp:527
HPCombi::PPerm16 type
The type of Rho values.
Definition hpcombi.hpp:615
HPCombi::Vect16 type
The type of Rho value for HPCombi::Transf16.
Definition hpcombi.hpp:751
Adapter for rho functions.
Definition adapters.hpp:812
void operator()(TPTransf16Subclass &x, TPTransf16Subclass &y) const noexcept
Swap x and y.
Definition hpcombi.hpp:228
Adapter for swapping.
Definition adapters.hpp:666