diff --git a/example/bench.cpp b/example/bench.cpp index 4be5049..25d75f3 100644 --- a/example/bench.cpp +++ b/example/bench.cpp @@ -17,7 +17,7 @@ int main() { tc::group::E(7), tc::group::B(6), tc::group::B(7), - tc::group::B(8), + tc::group::B(8) }; for (const auto &group : groups) { diff --git a/example/path.cpp b/example/path.cpp index f18f6a2..9f4cd1e 100644 --- a/example/path.cpp +++ b/example/path.cpp @@ -9,7 +9,7 @@ int main() { for (size_t target = 1; target < vars.size(); target++) { auto &action = vars.path[target]; - std::cout << action.coset << " * " << action.gen << " = " << target << std::endl; + std::cout << action.from_idx << " * " << action.gen << " = " << target << std::endl; } return 0; diff --git a/include/tc/core.hpp b/include/tc/core.hpp index ef196c5..9666ea2 100644 --- a/include/tc/core.hpp +++ b/include/tc/core.hpp @@ -6,15 +6,14 @@ namespace tc { struct Action { - int coset = -1; + int from_idx = -1; int gen = -1; - int target = -1; Action() = default; Action(const Action &) = default; - Action(int coset, int gen, int target); + Action(int from_idx, int gen); }; struct Cosets { @@ -52,6 +51,8 @@ namespace tc { [[nodiscard]] Rel shift(int off) const; }; + struct SubGroup; + struct Group { const int ngens; std::vector> _mults; @@ -67,11 +68,20 @@ namespace tc { [[nodiscard]] std::vector rels() const; + [[nodiscard]] SubGroup subgroup(const std::vector &gens) const; + [[nodiscard]] Group product(const Group &other) const; [[nodiscard]] Group power(int p) const; - [[nodiscard]] Cosets solve(const std::vector& sub_gens = {}) const; + [[nodiscard]] Cosets solve(const std::vector &sub_gens = {}) const; + }; + + struct SubGroup : public Group { + const std::vector gen_map; + const Group &parent; + + SubGroup(const Group &parent, const std::vector &gen_map); }; Group operator*(const Group &g, const Group &h); diff --git a/src/core.cpp b/src/core.cpp index dcffb3b..c59f55c 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -4,8 +4,8 @@ #include namespace tc { - Action::Action(int coset, int gen, int target) - : coset(coset), gen(gen), target(target) { + Action::Action(int from_idx, int gen) + : from_idx(from_idx), gen(gen) { } Cosets::Cosets(int ngens) @@ -21,8 +21,8 @@ namespace tc { data[coset * ngens + gen] = target; data[target * ngens + gen] = coset; - if (path[target].coset == -1) { - path[target] = Action(coset, gen, target); + if (path[target].from_idx == -1) { + path[target] = Action(coset, gen); } } @@ -32,8 +32,8 @@ namespace tc { data[idx] = target; data[target * ngens + gen] = coset; - if (path[target].coset == -1) { - path[target] = Action(coset, gen, target); + if (path[target].from_idx == -1) { + path[target] = Action(coset, gen); } } @@ -89,6 +89,10 @@ namespace tc { return res; } + SubGroup Group::subgroup(const std::vector &gens) const { + return SubGroup(*this, gens); + } + Group Group::product(const Group &other) const { std::stringstream ss; ss << name << "*" << other.name; @@ -115,4 +119,15 @@ namespace tc { return g; } -} \ No newline at end of file + + SubGroup::SubGroup(const Group &parent, const std::vector &gen_map) + : Group(gen_map.size()), parent(parent), gen_map(gen_map) { + + for (size_t i = 0; i < gen_map.size(); ++i) { + for (size_t j = 0; j < gen_map.size(); ++j) { + int mult = parent.get(gen_map[i], gen_map[j]); + set(Rel(i, j, mult)); + } + } + } +}