sisi4s
Loading...
Searching...
No Matches
Permutation.hpp
Go to the documentation of this file.
1#ifndef PERMUTATION_DEFINED
2#define PERMUTATION_DEFINED
3
4#include <iostream>
5#include <initializer_list>
6
7namespace sisi4s {
8template <int N>
9class Map {
10public:
11 Map() {}
12 Map(std::initializer_list<int> images_) {
13 std::copy(images_.begin(), images_.end(), images);
14 }
15 Map(const Map &p) {
16 for (int i(0); i < N; ++i) images[i] = p.images[i];
17 }
18
19 int operator()(int i) const { return images[i]; }
20 int &operator()(int i) { return images[i]; }
21
22 bool operator==(const Map &m) const {
23 for (int i(0); i < N; ++i)
24 if (images[i] != m.images[i]) return false;
25 return true;
26 }
27
28 int images[N];
29};
30
31template <int N>
32inline std::ostream &operator<<(std::ostream &stream, const Map<N> &f) {
33 stream << "(";
34 for (int i(0); i < N - 1; ++i) stream << f(i) << ",";
35 stream << f(N - 1) << ")";
36 return stream;
37}
38
39template <int N>
40class Permutation;
41
42template <int N>
43Permutation<N> operator*(const Permutation<N> &, const Permutation<N> &);
44template <int N>
45Permutation<N> operator/(const Permutation<N> &, const Permutation<N> &);
46template <int N>
47Permutation<N> operator/(const int, const Permutation<N> &);
48
49template <int N>
50class Permutation : public Map<N> {
51public:
52 Permutation(const int64_t p) {
53 Permutation<N - 1> subPermutation(p / N);
54 int i;
55 for (i = 0; i < p % N; ++i) {
56 this->images[i] = subPermutation.images[i] + 1;
57 }
58 this->images[p % N] = 0;
59 for (++i; i < N; ++i) {
60 this->images[i] = subPermutation.images[i - 1] + 1;
61 }
62 }
63
65 int count(0);
66 for (int i(0); i < N; ++i) count += this->images[i] == i;
67 return count;
68 }
69
70 static constexpr int64_t ORDER = N * Permutation<N - 1>::ORDER;
71
72private:
73 Permutation() {}
74 friend Permutation operator*<N>(const Permutation &, const Permutation &);
75 friend Permutation operator/<N>(const Permutation &, const Permutation &);
76 friend Permutation operator/<N>(const int, const Permutation &);
77};
78
79template <>
80class Permutation<1> : public Map<1> {
81public:
82 Permutation(const int64_t p) { images[0] = 0; }
83 static constexpr int64_t ORDER = 1;
84};
85
86// sigma after tau
87template <int N>
89 const Permutation<N> &tau) {
91 for (int i(0); i < N; ++i) pi(i) = sigma(tau(i));
92 return pi;
93}
94
95// general map f after tau
96template <int N>
97inline Map<N> operator*(const Map<N> &f, const Permutation<N> &tau) {
98 Map<N> g;
99 for (int i(0); i < N; ++i) g(i) = f(tau(i));
100 return g;
101}
102
103// inverse of a permutation tau
104template <int N>
105inline Permutation<N> operator/(const int, const Permutation<N> &tau) {
106 Permutation<N> tauInverse;
107 for (int i(0); i < N; ++i) tauInverse(tau(i)) = i;
108 return tauInverse;
109}
110
111// sigma after inverse of tau
112template <int N>
114 const Permutation<N> &tau) {
116 for (int i(0); i < N; ++i) pi(tau(i)) = sigma(i);
117 return pi;
118}
119} // namespace sisi4s
120
121#endif
std::ostream & operator<<(std::ostream &s, const FcidumpReader::FcidumpHeader &h)
Definition FcidumpWriter.cxx:25
Definition Permutation.hpp:9
Map(std::initializer_list< int > images_)
Definition Permutation.hpp:12
bool operator==(const Map &m) const
Definition Permutation.hpp:22
int images[N]
Definition Permutation.hpp:28
Map(const Map &p)
Definition Permutation.hpp:15
int operator()(int i) const
Definition Permutation.hpp:19
int & operator()(int i)
Definition Permutation.hpp:20
Map()
Definition Permutation.hpp:11
Permutation(const int64_t p)
Definition Permutation.hpp:82
Definition Permutation.hpp:50
int invariantElementsCount() const
Definition Permutation.hpp:64
static constexpr int64_t ORDER
Definition Permutation.hpp:70
Permutation(const int64_t p)
Definition Permutation.hpp:52
Definition Algorithm.hpp:10
Permutation< N > operator/(const Permutation< N > &, const Permutation< N > &)
Definition Permutation.hpp:113
std::string operator*(const std::string &s, const sisi4s::Permutation< N > &pi)
Definition CcsdPerturbativeTriples.cxx:24