mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
ENH: Simplify solving logic
This is a combination of multiple WIP commits: - Semantic group names - G, H - Simplify fan<>() - Template int deduction - Remove _recontext_gens - Move g_gens logic into caller - Move subgroup logic into caller - Move recontext logic into coller - Move _generators, _recontext_gens to anonymous namespace - Simplify hull, tile
This commit is contained in:
@@ -92,6 +92,7 @@ namespace tc {
|
||||
private:
|
||||
size_t _rank;
|
||||
std::vector<size_t> _mults;
|
||||
std::vector<size_t> _gens;
|
||||
|
||||
public:
|
||||
Group(Group const &) = default;
|
||||
@@ -108,7 +109,11 @@ namespace tc {
|
||||
|
||||
[[nodiscard]] size_t rank() const;
|
||||
|
||||
[[nodiscard]] Group sub(std::vector<size_t> const &idxs) const;
|
||||
[[nodiscard]] std::vector<size_t> gens() const;
|
||||
|
||||
[[nodiscard]] Group sub(std::vector<size_t> const &gens) const;
|
||||
|
||||
[[nodiscard]] std::vector<Group> subs(size_t rank) const;
|
||||
|
||||
[[nodiscard]] Cosets solve(std::vector<size_t> const &idxs = {}, size_t bound = SIZE_MAX) const;
|
||||
};
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include <tc/core.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <numeric>
|
||||
|
||||
namespace tc {
|
||||
Group::Group(size_t rank) : _rank(rank), _mults(_rank * _rank, 2) {
|
||||
Group::Group(size_t rank) : _rank(rank), _mults(_rank * _rank, 2), _gens(_rank) {
|
||||
std::iota(_gens.begin(), _gens.end(), 0);
|
||||
|
||||
for (int idx = 0; idx < rank; ++idx) {
|
||||
set(idx, idx, 1);
|
||||
}
|
||||
@@ -28,15 +31,42 @@ namespace tc {
|
||||
return _rank;
|
||||
}
|
||||
|
||||
[[nodiscard]] Group Group::sub(std::vector<size_t> const &idxs) const {
|
||||
Group res(idxs.size());
|
||||
[[nodiscard]] std::vector<size_t> Group::gens() const {
|
||||
return _gens;
|
||||
}
|
||||
|
||||
for (int i = 0; i < idxs.size(); ++i) {
|
||||
for (int j = i; j < idxs.size(); ++j) {
|
||||
res.set(i, j, get(idxs[i], idxs[j]));
|
||||
[[nodiscard]] Group Group::sub(std::vector<size_t> const &gens) const {
|
||||
Group res(gens.size());
|
||||
res._gens = gens;
|
||||
|
||||
for (int i = 0; i < gens.size(); ++i) {
|
||||
for (int j = i; j < gens.size(); ++j) {
|
||||
res.set(i, j, get(gens[i], gens[j]));
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<Group> Group::subs(size_t rank) const {
|
||||
std::vector<bool> mask(_rank, false);
|
||||
std::fill(mask.begin(), mask.begin() + rank, true);
|
||||
|
||||
std::vector<size_t> sub_gens(rank);
|
||||
|
||||
std::vector<Group> res;
|
||||
|
||||
do {
|
||||
for (int i = 0, j = 0; i < _rank; ++i) {
|
||||
if (mask[i]) sub_gens[j++] = i;
|
||||
}
|
||||
res.push_back(sub(sub_gens));
|
||||
} while (std::next_permutation(
|
||||
mask.begin(),
|
||||
mask.end(),
|
||||
std::greater<>()
|
||||
));
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user