mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
ENH: Remove template Group<> and Cosets<>
This commit is contained in:
@@ -11,18 +11,9 @@ namespace tc {
|
||||
using Mult = std::uint16_t;
|
||||
constexpr Mult FREE = 0;
|
||||
|
||||
/**
|
||||
* @brief Mapping from "global" generator names or objects to indexes used for value lookup.
|
||||
* @tparam Gen_
|
||||
*/
|
||||
template<typename Gen_=void>
|
||||
struct Index;
|
||||
|
||||
/**
|
||||
* @brief Complete representation of a quotient group. Describes the action of each generator on each coset.
|
||||
* @tparam Gen_
|
||||
*/
|
||||
template<typename Gen_=void>
|
||||
struct Cosets;
|
||||
|
||||
/**
|
||||
@@ -42,7 +33,6 @@ namespace tc {
|
||||
* @see
|
||||
* <a href="https://en.wikipedia.org/wiki/Coxeter_group#Definition">Coxeter Group (Wikipedia)</a>
|
||||
*/
|
||||
template<typename Gen_=void>
|
||||
struct Group;
|
||||
|
||||
/**
|
||||
@@ -52,33 +42,7 @@ namespace tc {
|
||||
template<typename Gen_=void>
|
||||
struct Path;
|
||||
|
||||
template<>
|
||||
struct Index<> {
|
||||
size_t operator()(size_t const &idx) const {
|
||||
return idx;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Gen_>
|
||||
struct Index {
|
||||
using Gen = Gen_;
|
||||
|
||||
std::vector<Gen> _gens{};
|
||||
|
||||
explicit Index(std::vector<Gen> gens) : _gens(gens) {}
|
||||
|
||||
template<typename It>
|
||||
Index(It begin, It end) : _gens(begin, end) {}
|
||||
|
||||
size_t operator()(Gen const &gen) const {
|
||||
auto it = std::find(_gens.begin(), _gens.end(), gen);
|
||||
assert(it != _gens.end());
|
||||
return it - _gens.begin();
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Cosets<> {
|
||||
struct Cosets {
|
||||
static constexpr size_t UNSET = std::numeric_limits<size_t>::max();
|
||||
|
||||
private:
|
||||
@@ -108,7 +72,7 @@ namespace tc {
|
||||
|
||||
[[nodiscard]] size_t size() const;
|
||||
|
||||
friend Group<>; // only constructible via Group<>::solve
|
||||
friend Group; // only constructible via Group<>::solve
|
||||
|
||||
private:
|
||||
explicit Cosets(size_t rank);
|
||||
@@ -122,8 +86,7 @@ namespace tc {
|
||||
[[nodiscard]] bool isset(size_t idx) const;
|
||||
};
|
||||
|
||||
template<>
|
||||
struct Group<> {
|
||||
struct Group {
|
||||
using Rel = std::tuple<size_t, size_t, Mult>;
|
||||
|
||||
private:
|
||||
@@ -147,7 +110,7 @@ namespace tc {
|
||||
|
||||
[[nodiscard]] Group sub(std::vector<size_t> const &idxs) const;
|
||||
|
||||
[[nodiscard]] Cosets<> solve(std::vector<size_t> const &idxs = {}, size_t bound = SIZE_MAX) const;
|
||||
[[nodiscard]] Cosets solve(std::vector<size_t> const &idxs = {}, size_t bound = SIZE_MAX) const;
|
||||
};
|
||||
|
||||
template<>
|
||||
@@ -160,7 +123,7 @@ namespace tc {
|
||||
public:
|
||||
// todo be smarter about move semantics
|
||||
|
||||
explicit Path(Cosets<> const &cosets) : _data() {
|
||||
explicit Path(Cosets const &cosets) : _data() {
|
||||
_data.resize(cosets.order());
|
||||
|
||||
std::vector<bool> complete(cosets.order(), false);
|
||||
@@ -206,101 +169,21 @@ namespace tc {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Gen_>
|
||||
struct Cosets : public Cosets<> {
|
||||
using Gen = Gen_;
|
||||
|
||||
private:
|
||||
Index<Gen> _index;
|
||||
|
||||
friend Path<Gen>;
|
||||
|
||||
public:
|
||||
Cosets(Cosets<> g, std::vector<Gen> gens) : Cosets<>(g), _index(gens) {}
|
||||
|
||||
void set(size_t coset, Gen const &gen, size_t target) {
|
||||
Cosets<>::set(coset, _index(gen), target);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t get(size_t coset, Gen const &gen) const {
|
||||
return Cosets<>::get(coset, _index(gen));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isset(size_t coset, Gen const &gen) const {
|
||||
return Cosets<>::isset(coset, _index(gen));
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<Gen> gens() const {
|
||||
return _index._gens;
|
||||
}
|
||||
|
||||
private:
|
||||
Cosets(size_t rank, std::vector<Gen> gens) : Cosets<>(rank), _index(gens) {}
|
||||
};
|
||||
|
||||
template<typename Gen_>
|
||||
struct Group : public Group<> {
|
||||
using Gen = Gen_;
|
||||
using Rel = std::tuple<Gen, Gen, Mult>;
|
||||
|
||||
private:
|
||||
Index<Gen> _index;
|
||||
|
||||
public:
|
||||
Group(Group const &) = default;
|
||||
|
||||
Group(Group &&) noexcept = default;
|
||||
|
||||
Group(Group<> g, std::vector<Gen> gens) : Group<>(g), _index(gens) {}
|
||||
|
||||
Group(size_t rank, std::vector<Gen> gens) : Group<>(rank), _index(gens) {}
|
||||
|
||||
~Group() = default;
|
||||
|
||||
void set(Gen const &u, Gen const &v, Mult m) {
|
||||
Group<>::set(_index(u), _index(v), m);
|
||||
}
|
||||
|
||||
[[nodiscard]] Mult get(Gen const &u, Gen const &v) const {
|
||||
return Group<>::get(_index(u), _index(v));
|
||||
}
|
||||
|
||||
[[nodiscard]] std::vector<Gen> gens() const {
|
||||
return _index._gens;
|
||||
}
|
||||
|
||||
[[nodiscard]] Group sub(std::vector<Gen> const &gens) const {
|
||||
std::vector<size_t> idxs(gens.size());
|
||||
std::transform(gens.begin(), gens.end(), idxs.begin(), _index);
|
||||
return Group(Group<>::sub(idxs), gens);
|
||||
}
|
||||
|
||||
[[nodiscard]] Cosets<Gen> solve(std::vector<Gen> const &gens = {}, size_t bound = SIZE_MAX) const {
|
||||
std::vector<size_t> idxs(gens.size());
|
||||
std::transform(gens.begin(), gens.end(), idxs.begin(), _index);
|
||||
|
||||
return Cosets<Gen>(Group<>::solve(idxs, bound), _index._gens);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Gen_>
|
||||
struct Path : public Path<> {
|
||||
using Gen = Gen_;
|
||||
|
||||
private:
|
||||
Index<Gen> _index;
|
||||
std::vector<Gen> _index;
|
||||
|
||||
public:
|
||||
// todo be smarter about move semantics
|
||||
explicit Path(Cosets<Gen> const &cosets) : Path<>(cosets), _index(cosets._index) {}
|
||||
|
||||
template<typename T>
|
||||
Path(Cosets<> const &cosets, T const &gens)
|
||||
: Path<>(cosets), _index(gens.begin(), gens.end()) {}
|
||||
Path(Cosets const &cosets, T &&gens)
|
||||
: Path<>(cosets), _index(std::forward<T>(gens).begin(), std::forward<T>(gens).end()) {}
|
||||
|
||||
template<typename Elem, typename BinaryOp, std::random_access_iterator It>
|
||||
void walk(Elem const &start, BinaryOp op, It out) {
|
||||
Path<>::walk(start, op, out, _index._gens.begin());
|
||||
Path<>::walk(start, op, out, _index.begin());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ namespace tc {
|
||||
* Construct a group from a (simplified) Schlafli Symbol of the form [a, b, ..., c]
|
||||
* @param mults: The sequence of multiplicites between adjacent generators.
|
||||
*/
|
||||
Group<> schlafli(const std::vector<unsigned int> &mults);
|
||||
Group schlafli(const std::vector<unsigned int> &mults);
|
||||
|
||||
Group<> coxeter(const std::string &symbol);
|
||||
Group coxeter(const std::string &symbol);
|
||||
|
||||
Group<> vcoxeter(const std::string &symbol, const std::vector<unsigned int> &values);
|
||||
Group vcoxeter(const std::string &symbol, const std::vector<unsigned int> &values);
|
||||
|
||||
template<typename ...Args>
|
||||
Group<> coxeter(const std::string &symbol, const Args &... args) {
|
||||
Group coxeter(const std::string &symbol, const Args &... args) {
|
||||
std::vector<unsigned int> values = {{args...}};
|
||||
return vcoxeter(symbol, values);
|
||||
}
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
#include <tc/core.hpp>
|
||||
|
||||
namespace tc {
|
||||
Cosets<>::Cosets(size_t rank)
|
||||
Cosets::Cosets(size_t rank)
|
||||
: _rank(rank), _order(0), _complete(false), _data() {}
|
||||
|
||||
void Cosets<>::set(size_t coset, size_t gen, size_t target) {
|
||||
void Cosets::set(size_t coset, size_t gen, size_t target) {
|
||||
set(coset * rank() + gen, target);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t Cosets<>::get(size_t coset, size_t gen) const {
|
||||
[[nodiscard]] size_t Cosets::get(size_t coset, size_t gen) const {
|
||||
return get(coset * rank() + gen);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Cosets<>::isset(size_t coset, size_t gen) const {
|
||||
[[nodiscard]] bool Cosets::isset(size_t coset, size_t gen) const {
|
||||
return isset(coset * rank() + gen);
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t Cosets<>::rank() const {
|
||||
[[nodiscard]] size_t Cosets::rank() const {
|
||||
return _rank;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t Cosets<>::order() const {
|
||||
[[nodiscard]] size_t Cosets::order() const {
|
||||
return _order;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Cosets<>::complete() const {
|
||||
[[nodiscard]] bool Cosets::complete() const {
|
||||
return _complete;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t Cosets<>::size() const {
|
||||
[[nodiscard]] size_t Cosets::size() const {
|
||||
return _data.size();
|
||||
}
|
||||
|
||||
void Cosets<>::add_row() {
|
||||
void Cosets::add_row() {
|
||||
_data.resize(_data.size() + rank(), UNSET);
|
||||
_order++;
|
||||
}
|
||||
|
||||
void Cosets<>::set(size_t idx, size_t target) {
|
||||
void Cosets::set(size_t idx, size_t target) {
|
||||
size_t coset = idx / rank();
|
||||
size_t gen = idx % rank();
|
||||
_data[idx] = target;
|
||||
_data[target * rank() + gen] = coset;
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t Cosets<>::get(size_t idx) const {
|
||||
[[nodiscard]] size_t Cosets::get(size_t idx) const {
|
||||
return _data[idx];
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Cosets<>::isset(size_t idx) const {
|
||||
[[nodiscard]] bool Cosets::isset(size_t idx) const {
|
||||
return get(idx) != UNSET;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
#include <cassert>
|
||||
|
||||
namespace tc {
|
||||
Group<>::Group(size_t rank) : _rank(rank), _mults(_rank * _rank, 2) {
|
||||
Group::Group(size_t rank) : _rank(rank), _mults(_rank * _rank, 2) {
|
||||
for (int idx = 0; idx < rank; ++idx) {
|
||||
set(idx, idx, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void Group<>::set(size_t u, size_t v, Mult m) {
|
||||
void Group::set(size_t u, size_t v, Mult m) {
|
||||
assert(u < rank());
|
||||
assert(v < rank());
|
||||
|
||||
@@ -17,19 +17,19 @@ namespace tc {
|
||||
_mults[v * rank() + u] = m;
|
||||
}
|
||||
|
||||
[[nodiscard]] Mult Group<>::get(size_t u, size_t v) const {
|
||||
[[nodiscard]] Mult Group::get(size_t u, size_t v) const {
|
||||
assert(u < rank());
|
||||
assert(v < rank());
|
||||
|
||||
return _mults[u * rank() + v];
|
||||
}
|
||||
|
||||
[[nodiscard]] size_t Group<>::rank() const {
|
||||
[[nodiscard]] size_t Group::rank() const {
|
||||
return _rank;
|
||||
}
|
||||
|
||||
[[nodiscard]] Group<> Group<>::sub(std::vector<size_t> const &idxs) const {
|
||||
Group<> res(idxs.size());
|
||||
[[nodiscard]] Group Group::sub(std::vector<size_t> const &idxs) const {
|
||||
Group res(idxs.size());
|
||||
|
||||
for (int i = 0; i < idxs.size(); ++i) {
|
||||
for (int j = i; j < idxs.size(); ++j) {
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
#include <numeric>
|
||||
|
||||
namespace tc {
|
||||
Group<> schlafli(const std::vector<unsigned int> &mults) {
|
||||
Group<> res(mults.size() + 1);
|
||||
Group schlafli(const std::vector<unsigned int> &mults) {
|
||||
Group res(mults.size() + 1);
|
||||
for (size_t i = 0; i < mults.size(); ++i) {
|
||||
res.set(i, i + 1, mults[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Group<> vcoxeter(const std::string &symbol, const std::vector<unsigned int> &values) {
|
||||
Group vcoxeter(const std::string &symbol, const std::vector<unsigned int> &values) {
|
||||
fmt::dynamic_format_arg_store<fmt::format_context> ds;
|
||||
|
||||
for (const auto &value: values) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
struct Graph {
|
||||
size_t rank{};
|
||||
std::vector<tc::Group<>::Rel> edges{};
|
||||
std::vector<tc::Group::Rel> edges{};
|
||||
};
|
||||
|
||||
struct Op {
|
||||
@@ -287,10 +287,10 @@ Graph eval(const std::vector<Op> &ops) {
|
||||
}
|
||||
|
||||
namespace tc {
|
||||
Group<> coxeter(const std::string &symbol) {
|
||||
Group coxeter(const std::string &symbol) {
|
||||
auto ops = compile(symbol);
|
||||
auto diagram = eval(ops);
|
||||
Group<> res(diagram.rank);
|
||||
Group res(diagram.rank);
|
||||
for (const auto &[i, j, m]: diagram.edges) {
|
||||
res.set(i, j, m);
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ namespace tc {
|
||||
};
|
||||
|
||||
struct Tables {
|
||||
std::vector<Group<>::Rel> rels;
|
||||
std::vector<Group::Rel> rels;
|
||||
std::vector<std::vector<Row>> rows;
|
||||
|
||||
explicit Tables(std::vector<Group<>::Rel> rels)
|
||||
explicit Tables(std::vector<Group::Rel> rels)
|
||||
: rels(std::move(rels)), rows() {
|
||||
}
|
||||
|
||||
@@ -36,9 +36,9 @@ namespace tc {
|
||||
}
|
||||
};
|
||||
|
||||
[[nodiscard]] Cosets<> Group<>::solve(std::vector<size_t> const &idxs, size_t bound) const {
|
||||
[[nodiscard]] Cosets Group::solve(std::vector<size_t> const &idxs, size_t bound) const {
|
||||
// region Initialize Cosets Table
|
||||
Cosets<> cosets(rank());
|
||||
Cosets cosets(rank());
|
||||
cosets.add_row();
|
||||
|
||||
if (rank() == 0) {
|
||||
@@ -53,7 +53,7 @@ namespace tc {
|
||||
// endregion
|
||||
|
||||
// region Initialize Relation Tables
|
||||
std::vector<Group<>::Rel> rels;
|
||||
std::vector<Group::Rel> rels;
|
||||
for (int i = 0; i < rank(); ++i) {
|
||||
for (int j = i + 1; j < rank(); ++j) {
|
||||
// The algorithm only works for Coxeter groups; multiplicities m_ii=1 are assumed. Relation tables
|
||||
|
||||
@@ -11,7 +11,7 @@ testing::AssertionResult AssertSolveOrder(
|
||||
const char *group_expr,
|
||||
const char *sub_gens_expr,
|
||||
const char *expected_order_expr,
|
||||
const tc::Group<> &group,
|
||||
const tc::Group &group,
|
||||
const std::vector<size_t> &sub_gens,
|
||||
size_t expected_order
|
||||
) {
|
||||
@@ -50,43 +50,43 @@ testing::AssertionResult AssertSolveOrder(
|
||||
|
||||
using v = std::vector<size_t>;
|
||||
|
||||
tc::Group<> A(unsigned int n) {
|
||||
tc::Group A(unsigned int n) {
|
||||
return tc::vcoxeter("3 * {}", {n - 1});
|
||||
}
|
||||
|
||||
tc::Group<> B(unsigned int n) {
|
||||
tc::Group B(unsigned int n) {
|
||||
return tc::vcoxeter("4 3 * {}", {n - 2});
|
||||
}
|
||||
|
||||
tc::Group<> D(unsigned int n) {
|
||||
tc::Group D(unsigned int n) {
|
||||
return tc::vcoxeter("3 * [1 1 {}]", {n - 3});
|
||||
}
|
||||
|
||||
tc::Group<> E(unsigned int n) {
|
||||
tc::Group E(unsigned int n) {
|
||||
return tc::vcoxeter("3 * [1 2 {}]", {n - 4});
|
||||
}
|
||||
|
||||
tc::Group<> F4() {
|
||||
tc::Group F4() {
|
||||
return tc::coxeter("3 4 3");
|
||||
}
|
||||
|
||||
tc::Group<> G2() {
|
||||
tc::Group G2() {
|
||||
return tc::coxeter("6");
|
||||
}
|
||||
|
||||
tc::Group<> H(unsigned int n) {
|
||||
tc::Group H(unsigned int n) {
|
||||
return tc::vcoxeter("5 3 * {}", {n - 2});
|
||||
}
|
||||
|
||||
tc::Group<> I2(unsigned int n) {
|
||||
tc::Group I2(unsigned int n) {
|
||||
return tc::vcoxeter("{}", {n});
|
||||
}
|
||||
|
||||
tc::Group<> T(unsigned int m, unsigned int n) {
|
||||
tc::Group T(unsigned int m, unsigned int n) {
|
||||
return tc::vcoxeter("{} 2 {}", {m, n});
|
||||
}
|
||||
|
||||
tc::Group<> T(unsigned int n) {
|
||||
tc::Group T(unsigned int n) {
|
||||
return T(n, n);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user