24#ifndef LIBSEMIGROUPS_BMAT8_HPP_
25#define LIBSEMIGROUPS_BMAT8_HPP_
38#include "adapters.hpp"
40#include "exception.hpp"
42#ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED
92 constexpr BitRef(uint64_t& data,
size_t index) noexcept
93 : _data(data), _mask(
static_cast<uint64_t
>(1) << (63 - index)) {}
96 constexpr BitRef&
operator=(
bool val)
noexcept {
97 _data ^= (-val ^ _data) & _mask;
102 [[nodiscard]]
constexpr operator bool()
const {
103 return _data & _mask;
131 constexpr explicit
BMat8(uint64_t mat) noexcept : _data(mat) {}
202 [[nodiscard]] constexpr
bool operator==(
BMat8 const& that) const noexcept {
203 return _data == that._data;
221 return _data != that._data;
239 return _data < that._data;
257 return *
this < that || *
this == that;
275 return _data > that._data;
293 return *
this > that || *
this == that;
322 [[nodiscard]]
constexpr bool operator()(
size_t r,
size_t c)
const noexcept {
323 LIBSEMIGROUPS_ASSERT(r < 8);
324 LIBSEMIGROUPS_ASSERT(c < 8);
325 return (_data << (8 * r + c)) >> 63;
353 [[nodiscard]]
constexpr uint8_t
operator()(
size_t r)
const noexcept {
354 LIBSEMIGROUPS_ASSERT(r < 8);
355 return static_cast<uint8_t
>(
to_int() << 8 * r >> 56);
381 [[nodiscard]] uint8_t
at(
size_t r)
const;
410 [[nodiscard]]
constexpr BitRef
operator()(
size_t r,
size_t c) {
411 return BitRef(_data, 8 * r + c);
428 [[nodiscard]]
bool at(
size_t r,
size_t c)
const;
444 [[nodiscard]] BitRef
at(
size_t r,
size_t c);
461 [[nodiscard]]
constexpr inline uint64_t
to_int() const noexcept {
543 return BMat8(_data | that._data);
631 template <
typename T>
632 [[nodiscard]]
constexpr T
one(
size_t dim = 8) {
633#ifdef LIBSEMIGROUPS_HPCOMBI_ENABLED
634 static_assert(std::is_same_v<T, BMat8>
635 || std::is_same_v<T, HPCombi::BMat8>);
637 static_assert(std::is_same_v<T, BMat8>);
641 "the argument (dimension) must be at most 8, found {}", dim);
671 [[nodiscard]]
constexpr BMat8 one(
size_t dim = 8) {
720 uint64_t y = x.to_int();
721 uint64_t z = (y ^ (y >> 7)) & 0xAA00AA00AA00AA;
722 y = y ^ z ^ (z << 7);
723 z = (y ^ (y >> 14)) & 0xCCCC0000CCCC;
724 y = y ^ z ^ (z << 14);
725 z = (y ^ (y >> 28)) & 0xF0F0F0F0;
726 y = y ^ z ^ (z << 28);
786 for (
size_t i = 0; i < 8; ++i) {
787 if (x.to_int() << (8 * i) >> 56 > 0) {
905 template <
typename Container>
907 static_assert(std::is_same_v<typename Container::value_type, uint8_t>);
908 for (
size_t i = 0; i < 8; ++i) {
909 rows.push_back(x(i));
984 BMat8 const& x)
noexcept {
995 struct hash<libsemigroups::BMat8> {
996 size_t operator()(libsemigroups::BMat8
const& bm)
const {
1019 [[nodiscard]]
constexpr inline size_t
1033 [[nodiscard]]
constexpr inline size_t
1079 size_t = 0) const noexcept {
1096 BMat8 const& x)
const noexcept {
1113 BMat8 const& x)
const noexcept {
Fast boolean matrices of dimension up to 8 x 8.
Definition bmat8.hpp:81
BMat8() noexcept=default
Default constructor.
constexpr bool operator>=(BMat8 const &that) const noexcept
Greater than or equal operator.
Definition bmat8.hpp:292
BitRef at(size_t r, size_t c)
Access entries in a matrix (with bound checks).
constexpr uint64_t to_int() const noexcept
Returns the integer representation of this.
Definition bmat8.hpp:461
constexpr BMat8(BMat8 &&) noexcept=default
Default move constructor.
BMat8 & operator*=(BMat8 const &that) noexcept
Multiply this by that in-place.
constexpr bool operator<(BMat8 const &that) const noexcept
Less than operator.
Definition bmat8.hpp:238
BMat8 operator*(BMat8 const &that) const noexcept
Returns the matrix product of this and that.
constexpr BMat8 & operator+=(BMat8 const &that) noexcept
Sum BMat8 objects (in-place).
Definition bmat8.hpp:560
constexpr BMat8 operator+(BMat8 const &that) const noexcept
Sum BMat8 objects.
Definition bmat8.hpp:542
constexpr BMat8 & operator*=(bool scalar) noexcept
Multiply a BMat8 by a scalar (in-place).
Definition bmat8.hpp:521
constexpr uint8_t operator()(size_t r) const noexcept
Access a row of a BMat8 (no bound checks).
Definition bmat8.hpp:353
constexpr bool operator!=(BMat8 const &that) const noexcept
Inequality operator.
Definition bmat8.hpp:220
constexpr bool operator()(size_t r, size_t c) const noexcept
Access entries in a matrix (no bound checks).
Definition bmat8.hpp:322
uint8_t at(size_t r) const
Access a row of a BMat8 (with bound checks).
BMat8(std::vector< std::vector< bool > > const &mat)
A constructor.
constexpr bool operator<=(BMat8 const &that) const noexcept
Less than or equal operator.
Definition bmat8.hpp:256
constexpr BMat8 & operator=(BMat8 const &) noexcept=default
Default copy assignment operator.
void swap(BMat8 &that) noexcept
Swaps this with that.
Definition bmat8.hpp:593
constexpr BMat8 operator*(bool scalar) const noexcept
Multiply a BMat8 by a scalar.
Definition bmat8.hpp:498
bool at(size_t r, size_t c) const
Access entries in a matrix (with bound checks).
constexpr BitRef operator()(size_t r, size_t c)
Access entries in a matrix (no bound checks).
Definition bmat8.hpp:410
constexpr BMat8(BMat8 const &) noexcept=default
Default copy constructor.
constexpr bool operator>(BMat8 const &that) const noexcept
Greater than operator.
Definition bmat8.hpp:274
std::string to_human_readable_repr(Action< Element, Point, Func, Traits, LeftOrRight > const &action)
Return a human readable representation of an Action object.
Bipartition operator*(Bipartition const &x, Bipartition const &y)
Multiply two bipartitions.
std::ostringstream & operator<<(std::ostringstream &os, BMat8 const &x)
Insertion operator.
#define LIBSEMIGROUPS_EXCEPTION(...)
Throw a LibsemigroupsException.
Definition exception.hpp:99
Namespace for BMat8 helper functions.
Definition bmat8.hpp:610
std::vector< bool > to_vector(uint8_t row)
Convert a uint8_t to a vector.
size_t minimum_dim(BMat8 const &x) noexcept
Returns the minimum dimension of a BMat8.
bool is_regular_element(BMat8 const &x) noexcept
Checks whether a BMat8 is regular in the monoid of all BMat8 objects.
BMat8 random()
Construct a random BMat8.
void push_back_rows(Container &rows, BMat8 const &x)
Push the rows of a BMat8 into the back of a container.
Definition bmat8.hpp:906
constexpr T one(size_t dim=8)
Returns the identity boolean matrix of a given dimension.
Definition bmat8.hpp:632
BMat8 col_space_basis(BMat8 const &x) noexcept
Find a basis for the column space of a BMat8.
Definition bmat8.hpp:762
size_t row_space_size(BMat8 const &x)
Returns the size of the row space of a BMat8.
std::vector< uint8_t > rows(BMat8 const &x)
Returns a vector of the rows of a BMat8.
constexpr BMat8 transpose(BMat8 const &x) noexcept
Returns the transpose of a BMat8.
Definition bmat8.hpp:719
size_t col_space_size(BMat8 const &x)
Returns the size of the column space of a BMat8.
Definition bmat8.hpp:850
constexpr size_t number_of_cols(BMat8 const &x) noexcept
Returns the number of non-zero columns in a BMat8.
Definition bmat8.hpp:815
constexpr size_t number_of_rows(BMat8 const &x) noexcept
Returns the number of non-zero rows in a BMat8.
Definition bmat8.hpp:784
BMat8 row_space_basis(BMat8 const &x) noexcept
Find a basis for the row space of a BMat8.
Namespace for everything in the libsemigroups library.
Definition action.hpp:44
constexpr size_t operator()(BMat8 const &) const noexcept
Returns 0; BMat8 multiplication is constant complexity.
Definition bmat8.hpp:1020
Adapter for the complexity of multiplication.
Definition adapters.hpp:128
constexpr size_t operator()(BMat8 const &) const noexcept
Returns 8; all BMat8s have degree 8.
Definition bmat8.hpp:1034
Adapter for the degree of an element.
Definition adapters.hpp:166
void operator()(BMat8 &res, BMat8 const &pt, BMat8 const &x) const noexcept
Definition bmat8.hpp:1111
Adapter for the value of a left action.
Definition adapters.hpp:357
void operator()(BMat8 &res, BMat8 const &pt, BMat8 const &x) const noexcept
Definition bmat8.hpp:1094
Adapter for the value of a right action.
Definition adapters.hpp:399
void operator()(BMat8 const &, size_t) const noexcept
Does nothing.
Definition bmat8.hpp:1048
Adapter for increasing the degree of an element.
Definition adapters.hpp:206
BMat8 operator()(BMat8 const &x) const noexcept
Returns the group inverse of x.
Definition bmat8.hpp:1126
Adapter for the inverse of an element.
Definition adapters.hpp:326
void operator()(BMat8 &res, BMat8 const &x) const noexcept
Definition bmat8.hpp:1166
Adapter for the action on LambdaValue's.
Definition adapters.hpp:840
BMat8 type
Definition bmat8.hpp:1141
Adapter for lambda functions.
Definition adapters.hpp:800
BMat8 operator()(size_t dim=8) const
Returns bmat8::one(dim)
Definition bmat8.hpp:1063
BMat8 operator()(BMat8 const &) const noexcept
Returns x.one()
Definition bmat8.hpp:1059
Adapter for the identity element of the given type.
Definition adapters.hpp:253
void operator()(BMat8 &xy, BMat8 const &x, BMat8 const &y, size_t=0) const noexcept
Changes xy in place to hold the product of x and y.
Definition bmat8.hpp:1076
Adapter for the product of two elements.
Definition adapters.hpp:291
size_t operator()(BMat8 const &x) const noexcept
Definition bmat8.hpp:1194
Adapter for calculating ranks.
Definition adapters.hpp:937
void operator()(BMat8 &res, BMat8 const &x) const noexcept
Definition bmat8.hpp:1180
Adapter for the action on RhoValue's.
Definition adapters.hpp:861
BMat8 type
Definition bmat8.hpp:1153
Adapter for rho functions.
Definition adapters.hpp:819