/
types.jl
495 lines (390 loc) · 14.3 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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
@doc raw"""
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 raw"""
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 raw"""
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
function Base.deepcopy_internal(x::BasicGAPGroupElem, dict::IdDict)
X = Base.deepcopy_internal(x.X, dict)
return BasicGAPGroupElem(x.parent, X)
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 a 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`
If `G` is a permutation group and `x` is a permutation,
`G(x)` returns a permutation `x` with parent `G`;
an exception is thrown if `x` does not embed into `G`.
```jldoctest
julia> G=symmetric_group(5)
Sym(5)
julia> x=cperm([1,2,3])
(1,2,3)
julia> parent(x)
Sym(3)
julia> y=G(x)
(1,2,3)
julia> parent(y)
Sym(5)
```
If `G` is a permutation group and `x` is a vector of integers,
`G(x)` returns a [`PermGroupElem`](@ref) with parent `G`;
an exception is thrown if the element does not embed into `G`.
# Examples
```jldoctest
julia> G = symmetric_group(6)
Sym(6)
julia> x = G([2,4,6,1,3,5])
(1,2,4)(3,6,5)
julia> parent(x)
Sym(6)
```
"""
@attributes mutable struct PermGroup <: GAPGroup
X::GapObj
deg::Int64 # G < Sym(deg)
function PermGroup(G::GapObj)
@assert GAPWrap.IsPermGroup(G)
n = GAPWrap.LargestMovedPoint(G)::Int
if n == 0
# We support only positive degrees.
# (`symmetric_group(0)` yields an error,
# and `symmetric_group(1)` yields a GAP group with `n == 0`.)
n = 1
end
z = new(G, n)
return z
end
function PermGroup(G::GapObj, deg::Int)
@assert GAPWrap.IsPermGroup(G) && deg > 0 && deg >= GAPWrap.LargestMovedPoint(G)::Int
z = new(G, deg)
return z
end
end
permutation_group(G::GapObj) = PermGroup(G)
permutation_group(G::GapObj, deg::Int) = PermGroup(G, deg)
"""
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, a group that is defined by a finite presentation
of a special kind, a so-called polycyclic presentation.
Contrary to arbitrary finitely presented groups
(see [Finitely presented groups](@ref)),
this presentation allows for efficient computations with the group elements.
# 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)]`
"""
@attributes mutable struct PcGroup <: GAPGroup
X::GapObj
function PcGroup(G::GapObj)
@assert GAPWrap.IsPcGroup(G) || GAP.Globals.IsPcpGroup(G)
z = new(G)
return z
end
end
pc_group(G::GapObj) = PcGroup(G)
"""
PcGroupElem
Element of a polycyclic group.
The generators of a polycyclic group are displayed as `f1`, `f2`, `f3`, etc.,
and every element of a polycyclic group is displayed as product of the
generators.
# Examples
```jldoctest
julia> G = abelian_group(PcGroup, [2, 4]);
julia> G[1], G[2]
(f1, f2)
julia> G[2]*G[1]
f1*f2
```
Note that this does not define Julia variables named `f1`, `f2`, etc.!
To get the generators of the group `G`, use `gens(G)`;
for convenience they can also be accessed as `G[1]`, `G[2]`,
as shown in Section [Elements of groups](@ref elements_of_groups).
"""
const PcGroupElem = BasicGAPGroupElem{PcGroup}
"""
FPGroup
Finitely presented group.
Such groups can be constructed a factors of free groups,
see [`free_group`](@ref).
"""
@attributes mutable struct FPGroup <: GAPGroup
X::GapObj
function FPGroup(G::GapObj)
@assert GAPWrap.IsSubgroupFpGroup(G)
z = new(G)
return z
end
end
fp_group(G::GapObj) = FPGroup(G)
"""
TODO: document this
"""
const FPGroupElem = BasicGAPGroupElem{FPGroup}
abstract type AbstractMatrixGroupElem <: GAPGroupElem{GAPGroup} end
# NOTE: always defined are deg, ring and at least one between { X, gens, descr }
"""
MatrixGroup{RE<:RingElem, T<:MatElem{RE}} <: GAPGroup
Type of groups `G` of `n x n` matrices over the ring `R`, where `n = degree(G)` and `R = base_ring(G)`.
"""
@attributes mutable struct MatrixGroup{RE<:RingElem, T<:MatElem{RE}} <: GAPGroup
deg::Int
ring::Ring
X::GapObj
gens::Vector{<:AbstractMatrixGroupElem}
descr::Symbol # e.g. GL, SL, symbols for isometry groups
ring_iso::MapFromFunc # Isomorphism from the Oscar base ring to the GAP base ring
function MatrixGroup{RE,T}(F::Ring, m::Int) where {RE,T}
G = new{RE, T}()
G.deg = m
G.ring = F
return G
end
end
# NOTE: at least one of the fields :elm and :X must always defined, but not necessarily both of them.
"""
MatrixGroupElem{RE<:RingElem, T<:MatElem{RE}} <: AbstractMatrixGroupElem
Elements of a group of type `MatrixGroup{RE<:RingElem, T<:MatElem{RE}}`
"""
mutable struct MatrixGroupElem{RE<:RingElem, T<:MatElem{RE}} <: AbstractMatrixGroupElem
parent::MatrixGroup{RE, T}
elm::T # Oscar matrix
X::GapObj # GAP matrix. If x isa MatrixGroupElem, then x.X = map_entries(x.parent.ring_iso, x.elm)
# full constructor
MatrixGroupElem{RE,T}(G::MatrixGroup{RE,T}, x::T, x_gap::GapObj) where {RE, T} = new{RE,T}(G, x, x_gap)
# constructor which leaves `X` undefined
MatrixGroupElem{RE,T}(G::MatrixGroup{RE,T}, x::T) where {RE, T} = new{RE,T}(G, x)
# constructor which leaves `elm` undefined
function MatrixGroupElem{RE,T}(G::MatrixGroup{RE,T}, x_gap::GapObj) where {RE, T}
z = new{RE,T}(G)
z.X = x_gap
return z
end
end
################################################################################
#
# Construct an Oscar group wrapping the GAP group `obj`
# *and* compatible with a given Oscar group `G`.
# default: ignore `G`
_oscar_group(obj::GapObj, G::T) where T <: GAPGroup = T(obj)
# `PermGroup`: set the degree of `G`
function _oscar_group(obj::GapObj, G::PermGroup)
n = GAPWrap.LargestMovedPoint(obj)
N = degree(G)
n <= N || error("requested degree ($N) is smaller than the largest moved point ($n)")
return permutation_group(obj, N)
end
# `MatrixGroup`: set dimension and ring of `G`
function _oscar_group(obj::GapObj, G::MatrixGroup)
d = GAP.Globals.DimensionOfMatrixGroup(obj)
d == G.deg || error("requested dimension of matrices ($(G.deg)) does not match the given matrix dimension ($d)")
R = G.ring
iso = _ring_iso(G)
GAPWrap.IsSubset(codomain(iso), GAP.Globals.FieldOfMatrixGroup(obj)) || error("matrix entries are not in the requested ring ($(codomain(iso)))")
M = matrix_group(R, d)
M.X = obj
M.ring = R
M.ring_iso = iso
return M
end
################################################################################
#
# "Coerce" an Oscar group `G` to one that is compatible with
# the given Oscar group `S`.
compatible_group(G::T, S::T) where T <: GAPGroup = _oscar_group(G.X, S)
################################################################################
abstract type GSet{T} end
################################################################################
#
# Conjugacy Classes
#
################################################################################
"""
GroupConjClass{T, S}
It can be either the conjugacy class of an element or of a subgroup of type `S`
in a group `G` of type `T`.
"""
abstract type GroupConjClass{T, S} <: GSet{T} end
################################################################################
#
# 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
function GAPGroupHomomorphism(G::S, H::T, mp::GapObj) where {S<: GAPGroup, T<: GAPGroup}
return new{S, T}(G, H, mp)
end
end
"""
AutomorphismGroup{T} <: GAPGroup
Group of automorphisms over a group of type `T`. It can be defined via the function `automorphism_group`
"""
@attributes mutable struct AutomorphismGroup{T} <: GAPGroup
X::GapObj
G::T
function AutomorphismGroup{T}(G::GapObj, H::T) where T
@assert GAPWrap.IsGroupOfAutomorphisms(G)
z = new{T}(G, H)
return z
end
end
function AutomorphismGroup(G::GapObj, H::T) where T
return AutomorphismGroup{T}(G, H)
end
(aut::AutomorphismGroup{T} where T)(x::GapObj) = group_element(aut,x)
const AutomorphismGroupElem{T} = BasicGAPGroupElem{AutomorphismGroup{T}} where T
function Base.show(io::IO, AGE::AutomorphismGroupElem{FinGenAbGroup})
print(io, "Automorphism of ", FinGenAbGroup, " with matrix representation ", matrix(AGE))
end
################################################################################
#
# Composite Groups
#
################################################################################
"""
DirectProductGroup
Either direct product of two or more groups of any type, or subgroup of a direct product of groups.
"""
@attributes mutable 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
function DirectProductGroup(X::GapObj, L::Vector{<:GAPGroup}, Xfull::GapObj, isfull::Bool)
return new(X, L, Xfull, isfull)
end
end
"""
SemidirectProductGroup{S,T}
Semidirect product of two groups of type `S` and `T` respectively, or
subgroup of a semidirect product of groups.
"""
@attributes mutable 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
function SemidirectProductGroup{S, T}(X::GapObj, N::S, H::T, f::GAPGroupHomomorphism{T,AutomorphismGroup{S}}, Xfull::GapObj, isfull::Bool) where {S<:GAPGroup, T<:GAPGroup}
return new{S, T}(X, N, H, f, Xfull, isfull)
end
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.
"""
@attributes mutable 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
function WreathProductGroup(X::GapObj, G::GAPGroup, H::GAPGroup, a::GAPGroupHomomorphism, Xfull::GapObj, isfull::Bool)
return new(X, G, H, a, Xfull, isfull)
end
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}
Base.eltype(::Type{T}) where T <: GAPGroup = BasicGAPGroupElem{T}
# `parent_type` is defined and documented in AbstractAlgebra.
parent_type(::Type{BasicGAPGroupElem{T}}) where T <: GAPGroup = T
#
# 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)
if pair[2] == MatrixGroup
#T HACK: We need more information in the case of matrix groups.
#T (Usually we should not need to guess the Oscar side of a GAP group.)
return function(dom::GAP.GapObj)
deg = GAP.Globals.DimensionOfMatrixGroup(dom)
iso = iso_gap_oscar(GAP.Globals.FieldOfMatrixGroup(dom))
ring = codomain(iso)
matgrp = matrix_group(ring, deg)
matgrp.ring_iso = inv(iso)
matgrp.X = dom
return matgrp
end
elseif pair[2] == AutomorphismGroup
return function(A::GAP.GapObj)
actdom_gap = GAP.Globals.AutomorphismDomain(A)
actdom_oscar = _get_type(actdom_gap)(actdom_gap)
return AutomorphismGroup(A, actdom_oscar)
end
else
return pair[2]
end
end
end
error("Not a known type of group")
end