-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgroup.cc
153 lines (123 loc) · 3.74 KB
/
group.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <iostream>
#include <vector>
#include <cmath>
#include <exception>
#include "group.h"
#include "permutation.h"
// #include "action.h"
#include "fhl.h"
Permutation _Group::one() const {
int n = degree();
std::vector<int> o( n );
for( int i = 0; i < n; i++ )
o[i] = i;
return Permutation( std::move(o) );
}
bool _Group::hasSubgroup( Group H ) const {
for( const auto& gen : H->generators() )
if( !contains( gen ) )
return false;
return true;
}
std::vector<int> _Group::domain() const {
std::vector<int> d( degree() );
for( int i = 0; i < degree(); i++ )
d[i] = i;
return d;
}
Group _Group::stabilizer( int x ) const {
return Group( new Subgroup( share(), [x]( const Permutation& sigma ) { return sigma(x) == x; } ) );
}
Group _Group::share() const {
return shared_from_this();
}
_Group::~_Group() {
}
// ----------------------------------------------------------------------------
bool Subgroup::contains( const Permutation& alpha ) const {
if( !_fhl )
_fhl.create( generators(), degree() );
return _fhl.contains( alpha );
}
Subgroup::Subgroup( Group G, std::vector<Permutation> gens ) {
swap( _supergroup, G );
swap( _generators, gens );
}
Subgroup::Subgroup( Group G, std::function<bool(Permutation)> c ) : Subgroup( SubgroupGenerator( G, c ).subgroup() ) {
}
std::vector<Coset> _Group::allCosets( Group N ) const {
SubgroupGenerator sg( share(), [&]( const Permutation& p ) -> bool { return N->contains( p ); } );
const auto& R = sg.cosetRepresentatives();
std::vector<Coset> cs;
cs.reserve( R.size() );
for( Permutation sigma : R )
cs.emplace_back( share(), N, sigma, false );
return cs;
}
bool Subgroup::isGiant() const {
if( not _fhl )
_fhl.create( generators(), degree() );
return _fhl.isGiant();
}
Subgroup::~Subgroup() {
}
Group Subgroup::supergroup() const {
return _supergroup;
}
std::vector<Permutation> Subgroup::generators() const {
return _generators;
}
int Subgroup::degree() const {
return supergroup()->degree();
}
__int128_t Subgroup::order() const {
if( !_fhl )
_fhl.create( generators(), degree() );
return _fhl.order();
}
Group Subgroup::join( std::deque<Permutation>&& P ) const {
std::vector<Permutation> new_generators;
new_generators.reserve( generators().size() + P.size() );
new_generators.insert( new_generators.end(), _generators.cbegin(), _generators.cend() );
for( int i = P.size() - 1; i >= 0; --i )
new_generators.push_back( std::move( P[i] ) );
return Group( new Subgroup( supergroup(), new_generators ) );
}
// ----------------------------------------------------------------------------
bool SymmetricGroup::contains( const Permutation& sigma ) const {
return degree() == sigma.degree();
}
int SymmetricGroup::degree() const {
return _degree;
}
__int128_t SymmetricGroup::order() const {
return std::tgamma( _degree + 1 ) + .9;
}
Group SymmetricGroup::join( std::deque<Permutation>&& P ) const {
for( const Permutation& sigma : P )
if( not contains( sigma ) )
throw;
return share();
}
std::vector<Permutation> SymmetricGroup::generators() const {
std::vector<int> cycle( degree() );
std::vector<int> transposition( degree() );
for( int i = 0; i < degree(); i++ ) {
cycle[i] = (i+1) % degree();
transposition[i] = i;
}
Permutation sigma( std::move( cycle ) );
if( degree() <= 2 )
return std::vector<Permutation>({ sigma });
std::swap( transposition[0], transposition[1] );
Permutation tau( std::move( transposition ) );
return std::vector<Permutation>({ sigma, tau });
}
SymmetricGroup::SymmetricGroup( int n ) {
_degree = n;
}
SymmetricGroup::~SymmetricGroup() {
}
bool SymmetricGroup::isGiant() const {
return true;
}