Is there C++ template class that implements operations with permutations and permutation group? Such class has to implement finding product and inverse, multiplication, etc.
Asked
Active
Viewed 2,639 times
5
-
In modern C++, you would not use a class for this. You would probably use multiple function templates. One function template per operation you want to support, with the actual input ranges templatized. – MSalters Jul 30 '09 at 12:37
-
Functional programming is not an option. Object-oriented programming is good. I really need template class. – Alexey Malistov Jul 30 '09 at 12:47
-
3@MSalters: What's the "input range" for a function which takes two permutations, and returns the product of those permutations? Are you suggesting that permutations themselves are best represented to the client as iterator pairs rather than as opaque objects? I think Alexey is after something with more knowledge of group theory than std::next_permutation. – Steve Jessop Jul 30 '09 at 13:52
1 Answers
0
I don't know of one, but it should be easy enough to implement. Internally you could represent the permutation as a vector e.g. (1 3 4 2 7 5 6) being a perm of 1-7 sending 1->1, 2->3, 3->4, 4->2 etc. or as a set of cycles e.g. (1) (2 3 4) (5 7 6), and implement the operations in terms of these. Presumably the template argument would be the size of the permutation group.