54 constexpr std::array<int, N>
decode(uint64_t binary_representation) {
56 for (
int i = 0; i < N; ++i) result[i] = (binary_representation >> (4 * i)) & 0b1111ull;
71 constexpr uint64_t
encode(std::array<int, N>
const &a) {
73 for (
int i = 0; i < N; ++i) {
74 EXPECTS(0 <= a[i] and a[i] <= 15);
75 result += (
static_cast<uint64_t
>(a[i]) << (4 * i));
84namespace nda::permutations {
102 template <std::
integral Int,
size_t N>
103 constexpr bool is_valid(std::array<Int, N>
const &p) {
106 if (idx < 0 or idx > N - 1 or idx_counts[idx] > 0)
return false;
124 template <std::
integral Int,
size_t N>
125 constexpr std::array<Int, N>
compose(std::array<Int, N>
const &p1, std::array<Int, N>
const &p2) {
129 for (
int u = 0; u < N; ++u) result[u] = p1[p2[u]];
144 template <std::
integral Int,
size_t N>
145 constexpr std::array<Int, N>
inverse(std::array<Int, N>
const &p) {
148 for (
int u = 0; u < N; ++u) result[p[u]] = u;
164 template <
typename T, std::
integral Int,
size_t N>
165 constexpr std::array<T, N>
apply_inverse(std::array<Int, N>
const &p, std::array<T, N>
const &a) {
168 for (
int u = 0; u < N; ++u) result[p[u]] = a[u];
185 template <
typename T, std::
integral Int,
size_t N>
186 constexpr std::array<T, N>
apply(std::array<Int, N>
const &p, std::array<T, N>
const &a) {
189 for (
int u = 0; u < N; ++u) result[u] = a[p[u]];
202 for (
int i = 0; i < N; ++i) result[i] = i;
215 for (
int i = 0; i < N; ++i) result[i] = N - 1 - i;
249 constexpr std::array<int, N>
cycle(
int p,
int pos = N) {
251 pos = std::clamp(pos, 0,
static_cast<int>(N));
252 for (
int i = 0; i < N; ++i) result[i] = (i < pos ? (pos + i - p) % pos : i);
Provides utility functions for std::array.
constexpr std::array< int, N > transposition(int i, int j)
Get the permutation representing a single given transposition.
constexpr std::array< Int, N > inverse(std::array< Int, N > const &p)
Inverse of a permutation.
constexpr std::array< int, N > decode(uint64_t binary_representation)
Decode a uint64_t into a std::array<int, N>.
constexpr bool is_valid(std::array< Int, N > const &p)
Check if a given array is a valid permutation.
constexpr std::array< T, N > apply_inverse(std::array< Int, N > const &p, std::array< T, N > const &a)
Apply the inverse of a permutation to a std::array.
constexpr std::array< int, N > identity()
Get the identity permutation.
constexpr uint64_t encode(std::array< int, N > const &a)
Encode a std::array<int, N> in a uint64_t.
constexpr std::array< int, N > reverse_identity()
Get the reverse identity permutation.
constexpr std::array< int, N > cycle(int p, int pos=N)
Perform a forward (partial) cyclic permutation of the identity p times.
constexpr std::array< Int, N > compose(std::array< Int, N > const &p1, std::array< Int, N > const &p2)
Composition of two permutations.
constexpr std::array< T, N > apply(std::array< Int, N > const &p, std::array< T, N > const &a)
Apply a permutation to a std::array.
constexpr std::array< T, R > make_initialized_array(T v)
Create a new std::array object initialized with a specific value.
Macros used in the nda library.
Provides missing concepts for older compiler versions.