mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
use coxeter notation parser for benchmark and tests
This commit is contained in:
@@ -40,27 +40,31 @@ namespace tc {
|
||||
}
|
||||
};
|
||||
|
||||
Cosets solve(const Group &group, const std::vector<Gen> &sub_gens, const Coset &bound) {
|
||||
auto ngens = group.ngens;
|
||||
Cosets solve(
|
||||
const Group &group,
|
||||
const std::vector<Gen> &sub_gens,
|
||||
const Coset &bound
|
||||
) {
|
||||
auto rank = group.rank;
|
||||
|
||||
// region Initialize Cosets Table
|
||||
Cosets cosets(ngens);
|
||||
Cosets cosets(rank);
|
||||
cosets.add_row();
|
||||
|
||||
if (ngens == 0) {
|
||||
if (rank == 0) {
|
||||
cosets.complete = true;
|
||||
return cosets;
|
||||
}
|
||||
|
||||
for (Coset g: sub_gens) {
|
||||
if (g < ngens)
|
||||
if (g < rank)
|
||||
cosets.put(0, g, 0);
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Initialize Relation Tables
|
||||
std::vector<std::tuple<Gen, Gen, Mult>> rels;
|
||||
for (const auto &[i, j, m]: group._mults) {
|
||||
for (const auto &[i, j, m]: group._orders) {
|
||||
// The algorithm only works for Coxeter groups; multiplicities m_ii=1 are assumed. Relation tables
|
||||
// _may_ be added for them, but they are redundant and hurt performance so are skipped.
|
||||
if (i == j) continue;
|
||||
@@ -75,7 +79,7 @@ namespace tc {
|
||||
}
|
||||
|
||||
Tables rel_tables(rels);
|
||||
std::vector<std::vector<size_t>> tables_for(ngens);
|
||||
std::vector<std::vector<size_t>> tables_for(rank);
|
||||
int rel_idx = 0;
|
||||
for (const auto &[i, j, m]: rels) {
|
||||
tables_for[i].push_back(rel_idx);
|
||||
@@ -146,8 +150,8 @@ namespace tc {
|
||||
|
||||
cosets.put(fact_idx, target);
|
||||
|
||||
coset = fact_idx / ngens;
|
||||
gen = fact_idx % ngens;
|
||||
coset = fact_idx / rank;
|
||||
gen = fact_idx % rank;
|
||||
|
||||
// If the product stays within the coset todo
|
||||
for (size_t table_idx: tables_for[gen]) {
|
||||
@@ -170,7 +174,7 @@ namespace tc {
|
||||
if (trow.gnr == m) {
|
||||
// loop is closed, but idempotent, so the target links to itself via the other generator.
|
||||
// todo might be able to move this logic up into the (target == coset) block and avoid those computations.
|
||||
facts.push(target * ngens + other_gen);
|
||||
facts.push(target * rank + other_gen);
|
||||
}
|
||||
} else {
|
||||
if (trow.gnr == m - 1) {
|
||||
@@ -180,7 +184,7 @@ namespace tc {
|
||||
// loop is closed. We know the last element in the loop must link with this one.
|
||||
lst = lst_vals[trow.lst_idx];
|
||||
// delete trow.lst_ptr;
|
||||
facts.push(lst * ngens + other_gen);
|
||||
facts.push(lst * rank + other_gen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace tc {
|
||||
return res;
|
||||
}
|
||||
|
||||
Group vcoxeter(const std::string &symbol, 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) {
|
||||
|
||||
@@ -80,7 +80,7 @@ struct codegen {
|
||||
void loop() {
|
||||
ops.emplace_back(Op::LOOP);
|
||||
}
|
||||
|
||||
|
||||
void free() {
|
||||
ops.emplace_back(Op::FREE);
|
||||
}
|
||||
@@ -221,23 +221,18 @@ std::vector<Op> compile(const std::string &source) {
|
||||
return cg.ops;
|
||||
}
|
||||
|
||||
struct Graph {
|
||||
size_t rank{};
|
||||
std::vector<tc::Rel> edges{};
|
||||
};
|
||||
|
||||
Graph eval(const std::vector<Op> &ops) {
|
||||
tc::Graph eval(const std::vector<Op> &ops) {
|
||||
std::vector<std::stack<size_t>> stacks(1);
|
||||
|
||||
Graph g;
|
||||
tc::Graph g;
|
||||
stacks.back().emplace(g.rank++);
|
||||
|
||||
for (const auto &op: ops) {
|
||||
switch (op.code) {
|
||||
case Op::FREE:
|
||||
case Op::FREE:
|
||||
case Op::LINK: {
|
||||
tc::Mult order = tc::FREE;
|
||||
|
||||
|
||||
if (op.code == Op::LINK) {
|
||||
order = op.value;
|
||||
}
|
||||
@@ -287,20 +282,7 @@ Graph eval(const std::vector<Op> &ops) {
|
||||
namespace tc {
|
||||
Group coxeter(const std::string &symbol) {
|
||||
auto ops = compile(symbol);
|
||||
|
||||
// fmt::print("#ops: {}\n", ops.size());
|
||||
// for (const auto &op: ops) {
|
||||
// fmt::print(" {}\n", op);
|
||||
// }
|
||||
|
||||
auto diagram = eval(ops);
|
||||
|
||||
Group res((int) diagram.rank);
|
||||
|
||||
for (const auto &[i, j, order]: diagram.edges) {
|
||||
res.set({i, j, order});
|
||||
}
|
||||
|
||||
return res;
|
||||
return Group(diagram);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user