-
Notifications
You must be signed in to change notification settings - Fork 126
/
types.jl
336 lines (279 loc) · 8.08 KB
/
types.jl
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
import Hecke:
abelian_group,
automorphism_group,
center,
codomain,
cokernel,
compose,
degree,
derived_series,
direct_product,
domain,
elem_type,
elements,
free_abelian_group,
gen,
gens,
haspreimage,
hom,
id_hom,
image,
index,
inv!,
isabelian,
isbijective,
ischaracteristic,
isconjugate,
iscyclic,
isinjective,
isinvertible,
isisomorphic,
isnormal,
issimple,
issubgroup,
issurjective,
kernel,
Map,
mul,
mul!,
ngens,
normal_closure,
one!,
order,
parent_type,
perm,
preimage,
quo,
representative,
SetMap,
small_group,
sub,
subgroups
import Base: ==, parent, show
import GAP: GapObj, GapInt
export
AutomorphismGroup,
DirectProductGroup,
DirectProductOfElem,
FPGroup,
FPGroupElem,
GAPGroupElem,
GAPGroupHomomorphism,
PcGroup,
PcGroupElem,
PermGroup,
PermGroupElem,
SemidirectProductGroup,
WreathProductGroup
@doc Markdown.doc"""
GAPGroup <: AbstractAlgebra.Group
Each object of the abstract type `GAPGroup` stores a group object from
the GAP system,
and thus can delegate questions about this object to GAP.
For expert usage, you can extract the underlying GAP object via `GapObj`,
i.e., if `G` is a `GAPGroup`, then `GapObj(G)` is the `GapObj` underlying `G`.
Concrete subtypes of `GAPGroup` are `PermGroup`, `FPGroup`, `PcGroup`,
and `MatrixGroup`.
"""
abstract type GAPGroup <: AbstractAlgebra.Group end
## `GapGroup` to GAP group
GAP.julia_to_gap(obj::GAPGroup) = obj.X
@doc Markdown.doc"""
GAPGroupElem <: AbstractAlgebra.GroupElem
Each object of the abstract type `GAPGroupElem` stores a group element
object from the GAP system,
and thus can delegate questions about this object to GAP.
For expert usage, you can extract the underlying GAP object via `GapObj`,
i.e., if `g` is a `GAPGroupElem`, then `GapObj(g)` is the `GapObj` underlying `g`.
"""
abstract type GAPGroupElem{T<:GAPGroup} <: AbstractAlgebra.GroupElem end
## `GapGroupElem` to GAP group element
GAP.julia_to_gap(obj::GAPGroupElem) = obj.X
@doc Markdown.doc"""
BasicGAPGroupElem{T<:GAPGroup} <: GAPGroupElem{T}
The type `BasicGAPGroupElem` gathers all types of group elements
described *only* by an underlying GAP object.
If $x$ is an element of the group `G` of type `T`,
then the type of $x$ is `BasicGAPGroupElem{T}`.
"""
struct BasicGAPGroupElem{T<:GAPGroup} <: GAPGroupElem{T}
parent::T
X::GapObj
end
Base.hash(x::GAPGroup, h::UInt) = h # FIXME
Base.hash(x::GAPGroupElem, h::UInt) = h # FIXME
"""
PermGroup
Groups of permutations.
Every group of this type is the subgroup of Sym(n) for some n.
# Examples
- `symmetric_group(n::Int)`: the symmetric group Sym(n)
- `alternating_group(n::Int)`: the alternating group Alt(n)
- subgroups of Sym(n)
- `dihedral_group(PermGroup, n::Int)`:
the dihedral group of order `n` as a group of permutations.
Same holds replacing `dihedral_group` by `quaternion_group`
"""
mutable struct PermGroup <: GAPGroup
X::GapObj
deg::Int64 # G < Sym(deg)
AbstractAlgebra.@declare_other
function PermGroup(G::GapObj)
@assert GAP.Globals.IsPermGroup(G)
n = GAP.Globals.LargestMovedPoint(G)::Int
z = new(G, n)
return z
end
function PermGroup(G::GapObj, deg::Int)
@assert GAP.Globals.IsPermGroup(G)
z = new(G, deg)
return z
end
end
"""
PermGroupElem
Element of a group of permutations.
It is displayed as product of disjoint cycles.
# Assumptions:
- for `x`,`y` in Sym(n), the product `xy` is read from left to right;
- for `x` in Sym(n) and `i` in {1,...,n}, `i^x` and `x(i)` return the image of `i` under the action of `x`.
"""
const PermGroupElem = BasicGAPGroupElem{PermGroup}
"""
PcGroup
Polycyclic group
# Examples
- `cyclic_group(n::Int)`: cyclic group of order `n`
- `abelian_group(PcGroup, v::Vector{Int})`:
direct product of cyclic groups of the orders
`v[1]`, `v[2]`, ..., `v[length(v)]`
"""
mutable struct PcGroup <: GAPGroup
X::GapObj
AbstractAlgebra.@declare_other
function PcGroup(G::GapObj)
@assert GAP.Globals.IsPcGroup(G)
z = new(G)
return z
end
end
"""
PcGroupElem
Element of a polycyclic group.
"""
const PcGroupElem = BasicGAPGroupElem{PcGroup}
"""
FPGroup
Finitely presented group.
Such groups can be constructed a factors of free groups,
see [`free_group`](@ref).
"""
mutable struct FPGroup <: GAPGroup
X::GapObj
AbstractAlgebra.@declare_other
function FPGroup(G::GapObj)
@assert GAP.Globals.IsSubgroupFpGroup(G)
z = new(G)
return z
end
end
"""
TODO: document this
"""
const FPGroupElem = BasicGAPGroupElem{FPGroup}
################################################################################
#
# Group Homomorphism
#
################################################################################
abstract type GAPMap <: SetMap end
struct GAPGroupHomomorphism{S<: GAPGroup, T<: GAPGroup} <: Map{S,T,GAPMap,GAPGroupHomomorphism{S,T}}
domain::S
codomain::T
map::GapObj
end
"""
AutomorphismGroup{T} <: GAPGroup
Group of automorphisms over a group of type `T`. It can be defined via the function `automorphism_group`.
"""
mutable struct AutomorphismGroup{T} <: GAPGroup
X::GapObj
G::T
AbstractAlgebra.@declare_other
function AutomorphismGroup{T}(G::GapObj, H::T) where T
@assert GAP.Globals.IsGroupOfAutomorphisms(G)
z = new{T}(G, H)
return z
end
end
################################################################################
#
# Composite Groups
#
################################################################################
"""
DirectProductGroup
Either direct product of two or more groups of any type, or subgroup of a direct product of groups.
"""
struct DirectProductGroup <: GAPGroup
X::GapObj
L::Vector{<:GAPGroup} # list of groups
Xfull::GapObj # direct product of the GAP groups of L
isfull::Bool # true if G is direct product of the groups of L, false if it is a proper subgroup
end
"""
SemidirectProductGroup{S,T}
Semidirect product of two groups of type `S` and `T` respectively, or
subgroup of a semidirect product of groups.
"""
struct SemidirectProductGroup{S<:GAPGroup, T<:GAPGroup} <: GAPGroup
X::GapObj
N::S # normal subgroup
H::T # group acting on N
f::GAPGroupHomomorphism{T,AutomorphismGroup{S}} # action of H on N
Xfull::GapObj # full semidirect product: X is a subgroup of Xfull.
isfull::Bool # true if X==Xfull
end
"""
WreathProductGroup
Wreath product of a group `G` and a group of permutations `H`, or a generic
group `H` together with the homomorphism `a` from `H` to a permutation
group.
"""
struct WreathProductGroup <: GAPGroup
X::GapObj
G::GAPGroup
H::GAPGroup
a::GAPGroupHomomorphism # morphism from H to the permutation group
Xfull::GapObj # if H does not move all the points, this is the wreath product of (G, Sym(degree(H))
isfull::Bool # true if Xfull == X
end
"""
elem_type(::Type{T}) where T <: GAPGroup
elem_type(::T) where T <: GAPGroup
`elem_type` maps (the type of) a group to the type of its elements.
For now, a group of type `T` has elements of type `BasicGAPGroupElem{T}`.
So we provide it mostly for consistency with other parts of OSCAR.
In the future, a more elaborate setup for group element types
might also be needed.
"""
elem_type(::Type{T}) where T <: GAPGroup = BasicGAPGroupElem{T}
elem_type(::T) where T <: GAPGroup = BasicGAPGroupElem{T}
Base.eltype(::Type{T}) where T <: GAPGroup = BasicGAPGroupElem{T}
# `parent_type` is defined and documented in AbstractAlgebra.
parent_type(::Type{T}) where T<:BasicGAPGroupElem{S} where S = S
parent_type(::T) where T<:BasicGAPGroupElem{S} where S = S
#
# The array _gap_group_types contains pairs (X,Y) where
# X is a GAP filter such as IsPermGroup, and Y is a corresponding
# Julia type such as `PermGroup`.
#
const _gap_group_types = Tuple{GAP.GapObj, Type}[]
function _get_type(G::GapObj)
for pair in _gap_group_types
if pair[1](G)
return pair[2]
end
end
error("Not a known type of group")
end