forked from oscar-system/Oscar.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgsets.jl
More file actions
1633 lines (1274 loc) · 51.2 KB
/
gsets.jl
File metadata and controls
1633 lines (1274 loc) · 51.2 KB
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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# This file contains code related to G-sets
# The idea of the implementation is that available GAP functionality
# for computing orbits, permutations, actions, etc. can be used,
# but that local replacements by pure Julia code (independent of GAP)
# are welcome.
import Hecke.orbit
# G-sets are "sets" (in a very general sense, these do not need to be objects of type `Set`)
# with an action by a group G::T.
# Alternatively one can define G-sets as a union of G-orbits.
# Potential examples include:
# - orbits of integers under a permutation
# - conjugacy classes of group elements
# - conjugacy classes of subgroups
# - block system
# TODO: add lots of concrete subtypes constructors, e.g. for
# - regular action of a group on itself
# - action of a perm group on its moved points
# - ...
"""
GSetByElements{T,S} <: GSet{T,S}
Objects of this type represent G-sets that are willing to write down
orbits and elements lists as vectors.
These G-sets are created by default by [`gset`](@ref).
The fields are
- the group that acts, of type `T`,
- the Julia function (for example `on_tuples`) that describes the action,
- the seeds (something iterable of eltype `S`) whose closure under the action is the G-set
- the dictionary used to store attributes (orbits, elements, ...).
"""
@attributes mutable struct GSetByElements{T,S} <: GSet{T,S}
group::T
action_function::Function
seeds
function GSetByElements(G::T, fun::Function, seeds; closed::Bool = false, check::Bool = true) where {T<:Union{Group, FinGenAbGroup}}
@req !isempty(seeds) "seeds for G-set must be nonempty"
check && @req hasmethod(fun, (typeof(first(seeds)), elem_type(T))) "action function does not fit to seeds"
Omega = new{T,eltype(seeds)}(G, fun, seeds, Dict{Symbol,Any}())
closed && set_attribute!(Omega, :elements => unique!(collect(seeds)))
return Omega
end
end
#TODO: How can I specify that `seeds` should be an iterable object?
function Base.show(io::IO, ::MIME"text/plain", x::GSetByElements)
println(io, "G-set of")
io = pretty(io)
print(io, Indent())
println(io, Lowercase(), x.group)
io = IOContext(io, :typeinfo => typeof(x.seeds))
print(io, "with seeds ", x.seeds)
print(io, Dedent())
end
function Base.show(io::IO, x::GSetByElements)
if is_terse(io)
print(io, "G-set")
else
print(io, "G-set of ")
io = IOContext(pretty(io), :typeinfo => typeof(x.seeds))
print(terse(io), Lowercase(), x.group, " with seeds ", x.seeds)
end
end
"""
acting_group(Omega::GSetByElements)
Return the group `G` acting on `Omega`.
# Examples
```jldoctest
julia> G = symmetric_group(4);
julia> acting_group(gset(G, [1])) == G
true
```
"""
acting_group(Omega::GSetByElements) = Omega.group
@doc raw"""
action_function(Omega::GSetByElements)
Return the function $f: \Omega \times G \to \Omega$ that defines the G-set.
# Examples
```jldoctest
julia> G = symmetric_group(4);
julia> action_function(gset(G, [1])) == ^
true
julia> action_function(gset(G, [[1, 2]])) == on_tuples
true
julia> action_function(gset(G, on_sets, [[1, 2]])) == on_sets
true
```
"""
action_function(Omega::GSetByElements) = Omega.action_function
# The following works for all G-set types that support attributes
# and for which the number of elements is an `Int`.
@attr PermGroup function action_range(Omega::GSet)
return symmetric_group(length(Int, Omega))
end
#############################################################################
##
## general method with explicit action function
"""
gset(G::Union{Group, FinGenAbGroup}[, fun::Function], seeds, closed::Bool = false, check::Bool = true)
Return the G-set `Omega` that consists of the closure of the seeds `seeds`
under the action of `G` defined by `fun`.
This means that `Omega` contains all elements `fun(omega, g)`
for `omega` in `seeds` and `g` in `G`.
`fun` can be omitted if the element type of `seeds` implies
a reasonable default,
for example, if `G` is a `PermGroup` and `seeds` is a `Vector{T}`
where `T` is one of `Int`, `Set{Int}`, `Vector{Int}`.
If `check` is set to `false` then it is *not* checked whether the entries
of `seeds` are valid as the first argument of `fun`.
If `closed` is set to `true` then `seeds` is assumed to be closed
under the action of `G`.
In this case, `collect(Omega)` is guaranteed to be equal to `collect(seeds)`;
in particular, the ordering of points in `seeds` (if applicable) is kept.
Note that the indexing of points in `Omega` is used by
[`action_homomorphism`](@ref).
# Examples
```jldoctest
julia> G = symmetric_group(4);
julia> length(gset(G, [1])) # natural action
4
julia> length(gset(G, [[1, 2]])) # action on ordered pairs
12
julia> length(gset(G, on_sets, [[1, 2]])) # action on unordered pairs
6
```
"""
function gset(G::Union{Group, FinGenAbGroup}, fun::Function, seeds; closed::Bool = false, check::Bool = true)
return GSetByElements(G, fun, seeds; closed = closed, check = check)
end
#############################################################################
##
## G-sets where the action function can be omitted
##
## (We use an indirection via `gset_by_type`, in order to admit specifying
## a default action depending on the element type of `seeds` (which can be
## any iterable collection.)
gset(G::T, seeds; closed::Bool = false) where T<:Group = gset_by_type(G, seeds, eltype(seeds); closed = closed)
## natural action of permutations on positive integers
function gset_by_type(G::PermGroup, Omega, ::Type{T}; closed::Bool = false) where T<:IntegerUnion
return GSetByElements(G, ^, Omega; closed = closed, check = false)
end
## action of permutations on sets of positive integers
function gset_by_type(G::PermGroup, Omega, ::Type{T}; closed::Bool = false) where T<:Set{T2} where T2<:IntegerUnion
return GSetByElements(G, on_sets, Omega; closed = closed, check = false)
end
## action of permutations on vectors of positive integers
function gset_by_type(G::PermGroup, Omega, ::Type{T}; closed::Bool = false) where T<:Vector{T2} where T2<:IntegerUnion
return GSetByElements(G, on_tuples, Omega; closed = closed, check = false)
end
## action of permutations on tuples of positive integers
function gset_by_type(G::PermGroup, Omega, ::Type{T}; closed::Bool = false) where T<:Tuple{T2,Vararg{T2}} where T2<:IntegerUnion
return GSetByElements(G, on_tuples, Omega; closed = closed, check = false)
end
## action of matrices on vectors via right multiplication
function gset_by_type(G::MatrixGroup{E, M}, Omega, ::Type{AbstractAlgebra.Generic.FreeModuleElem{E}}; closed::Bool = false) where E where M
return GSetByElements(G, *, Omega; closed = closed, check = false)
end
## action of matrices on sets of vectors via right multiplication
function gset_by_type(G::MatrixGroup{E, M}, Omega, ::Type{T}; closed::Bool = false) where T <: Set{AbstractAlgebra.Generic.FreeModuleElem{E}} where E where M
return GSetByElements(G, on_sets, Omega; closed = closed, check = false)
end
## action of matrices on vectors of vectors via right multiplication
function gset_by_type(G::MatrixGroup{E, M}, Omega, ::Type{T}; closed::Bool = false) where T <: Vector{AbstractAlgebra.Generic.FreeModuleElem{E}} where E where M
return GSetByElements(G, on_tuples, Omega; closed = closed, check = false)
end
## action of matrices on subspaces via right multiplication
function gset_by_type(G::MatrixGroup{E, M}, Omega, ::Type{T}; closed::Bool = false) where T <: AbstractAlgebra.Generic.Submodule{E} where E where M
return GSetByElements(G, ^, Omega; closed = closed, check = false)
end
## action of matrices on polynomials via `on_indeterminates`
function gset_by_type(G::MatrixGroup{E, M}, Omega, ::Type{T}; closed::Bool = false) where T <: MPolyRingElem{E} where E where M
return GSetByElements(G, on_indeterminates, Omega; closed = closed, check = false)
end
## (add more such actions: on sets of sets, on sets of tuples, ...)
#############################################################################
##
## natural method with implicit action function
"""
natural_gset(G::PermGroup)
Return the G-set `Omega` that consists of integers 1, ..., degree
under the natural action of `G`.
# Examples
```jldoctest
julia> G = symmetric_group(4);
julia> length(natural_gset(G))
4
```
"""
natural_gset(G::PermGroup) = gset(G, 1:G.deg; closed = true)
"""
natural_gset(G::MatrixGroup{T, MT}) where {MT, T <: FinFieldElem}
Return the G-set `Omega` that consists of vectors under the
natural action of `G` over a finite field.
# Examples
```jldoctest
julia> G = matrix_group(GF(2), 2);
julia> length(natural_gset(G))
4
```
"""
function natural_gset(G::MatrixGroup{T, MT}) where {MT, T <: FinFieldElem}
V = free_module(base_ring(G), degree(G))
return gset(G, collect(V); closed = true)
end
#############################################################################
##
#TODO: Compute membership without writing down all elements,
# using what is called `RepresentativeAction` in GAP.
function Base.in(omega::S, Omega::GSetByElements{T,S}) where {T,S}
omega in Omega.seeds && return true
return omega in elements(Omega)
end
#############################################################################
##
## G-sets given by the complete set
function as_gset(G::T, fun::Function, Omega) where T<:Union{Group, FinGenAbGroup}
return GSetByElements(G, fun, Omega; closed = true)
end
as_gset(G::T, Omega) where T<:Union{GAPGroup,FinGenAbGroup} = as_gset(G, ^, Omega)
#############################################################################
##
## induce G-sets along homomorphisms
@doc raw"""
induced_action_function(Omega::GSetByElements{T, S}, phi::GAPGroupHomomorphism{U, T}) where {T<:Group, U<:Group, S}
Return the action function of the G-set that is obtained by inducing the G-set `Omega` along `phi`.
That means, given a ``G``-set ``\Omega`` with action function ``f: \Omega \times G \to \Omega``
and a homomorphism ``\phi: H \to G``, construct the action function
$\Omega \times H \to \Omega, (\omega, h) \mapsto f(\omega, \phi(h))$.
This function is semantically equivalent to `action_function(induce(Omega, phi))`,
but it is more efficient as it avoids the construction of the induced G-set.
"""
function induced_action_function(Omega::GSetByElements{T, S}, phi::GAPGroupHomomorphism{U, T}) where {T<:Group, U<:Group, S}
return _induced_action_function(Omega, phi)
end
# This method is not documented as we need `phi` to be a group homomorphism, but in many cases
# there is no dedicated type for this (WeylGroup, FinGenAbGroup, etc.).
# This should be restricted to group homomorphisms once we have a type for them.
function induced_action_function(Omega::GSetByElements{T, S}, phi::Map{U, T}) where {T<:Union{Group,FinGenAbGroup}, U<:Union{Group,FinGenAbGroup}, S}
return _induced_action_function(Omega, phi)
end
function _induced_action_function(Omega::GSetByElements{T, S}, phi::Map{U, T}) where {T<:Union{Group,FinGenAbGroup}, U<:Union{Group,FinGenAbGroup}, S}
@req acting_group(Omega) == codomain(phi) "acting group of Omega must be the codomain of phi"
return induced_action(action_function(Omega), phi)
end
@doc raw"""
induce(Omega::GSetByElements{T, S}, phi::GAPGroupHomomorphism{U, T}) where {T<:Group, U<:Group, S}
Return the G-set that is obtained by inducing the G-set `Omega` along `phi`.
That means, given a ``G``-set ``\Omega`` with action function ``f: \Omega \times G \to \Omega``
and a homomorphism ``\phi: H \to G``, construct the ``H``-set ``\Omega'`` with action function
$\Omega' \times H \to \Omega', (\omega, h) \mapsto f(\omega, \phi(h))$.
"""
function induce(Omega::GSetByElements{T, S}, phi::GAPGroupHomomorphism{U, T}) where {T<:Group, U<:Group, S}
return _induce(Omega, phi)
end
# This method is not documented as we need `phi` to be a group homomorphism, but in many cases
# there is no dedicated type for this (WeylGroup, FinGenAbGroup, etc.).
# This should be restricted to group homomorphisms once we have a type for them.
function induce(Omega::GSetByElements{T, S}, phi::Map{U, T}) where {T<:Union{Group,FinGenAbGroup}, U<:Union{Group,FinGenAbGroup}, S}
return _induce(Omega, phi)
end
function _induce(Omega::GSetByElements{T, S}, phi::Map{U, T}) where {T<:Union{Group,FinGenAbGroup}, U<:Union{Group,FinGenAbGroup}, S}
@req acting_group(Omega) == codomain(phi) "acting group of Omega must be the codomain of phi"
return GSetByElements(domain(phi), induced_action_function(Omega, phi), Omega; closed=true, check=false)
end
#############################################################################
##
## wrapper objects for elements of G-sets,
## with fields `gset` (the G-set) and `objects` (the unwrapped object)
##
## These objects are optional ("syntactic sugar"), they can be used to
## - apply group elements via `^`,
## not via the action function stored in the G-set,
## - write something like `orbit(omega)`, `stabilizer(omega)`.
struct ElementOfGSet{T, S, G <: GSet{T, S}}
gset::G
obj::S
end
function (Omega::GSet{T, S})(obj::S) where {T, S}
return ElementOfGSet(Omega, obj)
end
function ^(omega::ElementOfGSet, g::T) where {T<:GroupElem}
Omega = omega.gset
fun = action_function(Omega)
return ElementOfGSet(Omega, fun(omega.obj, g))
end
==(omega1::ElementOfGSet, omega2::ElementOfGSet) =
((omega1.gset == omega2.gset) && (omega1.obj == omega2.obj))
function Base.hash(omega::ElementOfGSet, h::UInt)
b = 0x4dd1b3e65edeab89 % UInt
h = hash(omega.gset, h)
h = hash(omega.obj, h)
return xor(h, b)
end
Base.in(omega::ElementOfGSet, Omega::GSet) = Base.in(omega.obj, Omega)
Base.in(omega::ElementOfGSet, Omega::GSetByElements) = Base.in(omega.obj, Omega)
orbit(omega::ElementOfGSet) = orbit(omega.gset, omega.obj)
unwrap(omega::Any) = omega
unwrap(omega::ElementOfGSet) = omega.obj
#############################################################################
##
## `:orbit`
"""
orbit(G::Union{GAPGroup, FinGenAbGroup}[, fun::Function], omega)
Return the G-set that consists of the images of `omega`
under the action of `G` defined by `fun`.
This means that the result contains all elements `fun(omega, g)`
for `g` in `G`.
`fun` can be omitted if the type of `Omega` implies a reasonable default,
for example, if `G` is a `PermGroup` and `omega` is
one of `Int`, `Set{Int}`, `Vector{Int}`.
# Examples
```jldoctest
julia> G = symmetric_group(4);
julia> length(orbit(G, 1))
4
julia> length(orbit(G, [1, 2]))
12
julia> length(orbit(G, on_sets, [1, 2]))
6
```
"""
orbit(G::GAPGroup, omega) = gset_by_type(G, [omega], typeof(omega))
orbit(G::Union{GAPGroup, FinGenAbGroup}, fun::Function, omega) = GSetByElements(G, fun, [omega])
function gap_action_function(Omega::GSet)
f = action_function(Omega)
(f == ^) && return GAP.Globals.OnPoints
f == on_tuples && return GAP.Globals.OnTuples
f == on_sets && return GAP.Globals.OnSets
# etc.
return GapObj(f) # generic fallback
end
"""
orbit(Omega::GSet, omega)
Return the G-set that consists of the elements `fun(omega, g)` where
`g` is in the group of `Omega` and `fun` is the underlying action of `Omega`.
# Examples
```jldoctest
julia> G = sylow_subgroup(symmetric_group(6), 2)[1]
Permutation group of degree 6 and order 16
julia> Omega = gset(G, [1, 5]);
julia> length(orbit(Omega, 1))
4
```
"""
orbit(Omega::GSetByElements{<:GAPGroup, S}, omega::S) where S = _orbit_generic(Omega, omega)
function _orbit_generic(Omega::GSetByElements{<:GAPGroup, S}, omega::S) where S
# In this generic function, we delegate the loop to GAP, but we act
# with Julia group elements on Julia objects via Julia functions.
G = acting_group(Omega)
acts = GapObj(gens(G))
gfun = GapObj(action_function(Omega))
# The following works only because GAP does not check
# whether the given (dummy) group 'GapObj(G)' fits to the given generators,
# or whether the elements of 'acts' are group elements.
orb = Vector{S}(GAP.Globals.Orbit(GapObj(G), omega, acts, acts, gfun)::GapObj)
res = as_gset(acting_group(Omega), action_function(Omega), orb)
# We know that this G-set is transitive.
set_attribute!(res, :orbits => [res])
return res
end
#T check whether omega lies in Omega?
# special cases where we convert the objects to GAP
# (the group elements as well as the objects they act on),
# in order to use better methods on the GAP side:
# - orbit of a perm. group on integers via `^`
# - orbit of a perm. group on vectors of integers via `on_tuples`
# - orbit of a perm. group on sets of integers via `on_sets`
function orbit(Omega::GSetByElements{PermGroup, S}, omega::S) where S <: IntegerUnion
(action_function(Omega) == ^) || return _orbit_generic(Omega, omega)
return _orbit_special_GAP(Omega, omega)
end
function orbit(Omega::GSetByElements{PermGroup, S}, omega::S) where S <: Vector{<: IntegerUnion}
action_function(Omega) == on_tuples || return _orbit_generic(Omega, omega)
return _orbit_special_GAP(Omega, omega)
end
function orbit(Omega::GSetByElements{PermGroup, S}, omega::S) where S <: Set{<: IntegerUnion}
action_function(Omega) == on_sets || return _orbit_generic(Omega, omega)
return _orbit_special_GAP(Omega, omega)
end
function _orbit_special_GAP(Omega::GSetByElements{<:GAPGroup, S}, omega::S) where S
G = acting_group(Omega)
gfun = gap_action_function(Omega)
orb = Vector{S}(GAP.Globals.Orbit(GapObj(G), GapObj(omega), gfun)::GapObj)
res = as_gset(acting_group(Omega), action_function(Omega), orb)
# We know that this G-set is transitive.
set_attribute!(res, :orbits => [res])
return res
end
function orbit(Omega::GSetByElements{T, S}, omega::S) where {T<:Union{Group, FinGenAbGroup}, S}
return orbit_via_Julia(Omega, omega)
end
# simpleminded alternative directly in Julia
function orbit_via_Julia(Omega::GSet{T,S}, omega::S) where {T,S}
acts = gens(acting_group(Omega))
orb = IndexedSet([omega])
fun = action_function(Omega)
for p in orb
for g in acts
img = fun(p, g)::S
if !(img in orb)
push!(orb, img)
end
end
end
res = as_gset(acting_group(Omega), action_function(Omega), orb)
# We know that this G-set is transitive.
set_attribute!(res, :orbits => [res])
return res
end
#############################################################################
##
## `:orbits` a vector of G-sets
"""
orbits(Omega::GSet)
Return the vector of transitive G-sets in `Omega`.
# Examples
```jldoctest
julia> G = sylow_subgroup(symmetric_group(6), 2)[1]
Permutation group of degree 6 and order 16
julia> orbs = orbits(natural_gset(G));
julia> map(collect, orbs)
2-element Vector{Vector{Int64}}:
[1, 2, 3, 4]
[5, 6]
```
"""
@attr Vector{GSetByElements{T,S}} function orbits(Omega::GSetByElements{T,S}) where {T <: Union{Group, FinGenAbGroup},S}
orbs = GSetByElements{T,S}[]
for p_ in Omega.seeds
p = p_::S
if all(o -> !(p in o), orbs)
push!(orbs, orbit(Omega, p))
end
end
return orbs
end
"""
orbits(G::PermGroup)
Return the orbits of the natural G-set of `G`.
# Examples
```jldoctest
julia> G = sylow_subgroup(symmetric_group(6), 2)[1]
Permutation group of degree 6 and order 16
julia> orbs = orbits(G);
julia> map(length, orbs)
2-element Vector{Int64}:
4
2
```
"""
@attr Vector{GSetByElements{PermGroup, Int}} orbits(G::PermGroup) = orbits(natural_gset(G))
"""
stabilizer(Omega::GSet{T,S})
stabilizer(Omega::GSet{T,S}, omega::S = representative(Omega); check::Bool = true) where {T,S}
stabilizer(Omega::GSet{T,S}, omega::Set{S}; check::Bool = true) where {T,S}
stabilizer(Omega::GSet{T,S}, omega::Vector{S}; check::Bool = true) where {T,S}
stabilizer(Omega::GSet{T,S}, omega::Tuple{S,Vararg{S}}; check::Bool = true) where {T,S}
Return the subgroup of `G = acting_group(Omega)` that fixes `omega`,
together with the embedding of this subgroup into `G`.
If `omega` is a `Set` of points in `Omega`
then `stabilizer` means the setwise stabilizer of the entries in `omega`.
If `omega` is a `Vector` or a `Tuple` of points in `Omega`
then `stabilizer` means the pointwise stabilizer of the entries in `omega`.
If `check` is `false` then it is not checked whether `omega` is in `Omega`.
# Examples
```jldoctest
julia> Omega = natural_gset(symmetric_group(4));
julia> stabilizer(Omega)
(Permutation group of degree 4 and order 6, Hom: permutation group -> Sym(4))
julia> stabilizer(Omega, [1, 2])
(Permutation group of degree 4 and order 2, Hom: permutation group -> Sym(4))
```
"""
@attr Tuple{sub_type(T), Map{sub_type(T), T}} function stabilizer(Omega::GSet{T,S}) where {T,S}
return stabilizer(Omega, representative(Omega), check = false)
end
# generic method: delegate from the G-set to the underlying group
function stabilizer(Omega::GSet{T,S}, omega::S; check::Bool = true) where {T,S}
check && @req omega in Omega "omega must be an element of Omega"
G = acting_group(Omega)
gfun = action_function(Omega)
return stabilizer(G, omega, gfun)
end
# support `stabilizer` under "derived" actions:
# - If the given point is a set of the element type of the G-set
# then compute the setwise stabilizer.
# - If the given point is a tuple or vector of the element type of the G-set
# then compute the pointwise stabilizer.
# In these cases, if the action function of the given G-set is `^` then
# call `stabilizer` for `on_sets` or `on_tuples`, respectively,
# in order to choose a more efficient GAP method.
function stabilizer(Omega::GSet{T,S}, omega::Set{S}; check::Bool = true) where {T,S}
check && @req all(in(Omega), omega) "omega must be a set of elements of Omega"
G = acting_group(Omega)
gfun = action_function(Omega)
derived_fun = (gfun === ^) ? on_sets : (function(x, g) return Set(gfun(y, g) for y in x); end)
return stabilizer(G, omega, derived_fun)
end
function stabilizer(Omega::GSet{T,S}, omega::Vector{S}; check::Bool = true) where {T,S}
check && @req all(in(Omega), omega) "omega must be a vector of elements of Omega"
G = acting_group(Omega)
gfun = action_function(Omega)
derived_fun = (gfun === ^) ? on_tuples : (function(x, g) return [gfun(y, g) for y in x]; end)
return stabilizer(G, omega, derived_fun)
end
function stabilizer(Omega::GSet{T,S}, omega::Tuple{S,Vararg{S}}; check::Bool = true) where {T,S}
check && @req all(in(Omega), omega) "omega must be a tuple of elements of Omega"
G = acting_group(Omega)
gfun = action_function(Omega)
derived_fun = (gfun === ^) ? on_tuples : (function(x, g) return Tuple([gfun(y, g) for y in x]); end)
return stabilizer(G, omega, derived_fun)
end
#############################################################################
##
## `:elements` a vector of points;
## if `:seeds` is known to be closed under the action then
## keep its ordering of points
@attr Vector{S} function elements(Omega::GSetByElements{T,S}) where {T,S}
orbs = orbits(Omega)
return union(map(collect, orbs)...)
end
#############################################################################
##
# In fact, '<:GAPGroup' is not used at all in this function.
"""
permutation(Omega::GSetByElements{T}, g::BasicGAPGroupElem{T}) where T<:GAPGroup
Return the element of the permutation group that describes the action
of `g` on `Omega`, where `g` is an element of `acting_group(Omega)`.
# Examples
```jldoctest
julia> G = symmetric_group(4);
julia> Omega = gset(G, [[1, 2]]);
julia> x = gen(G, 1)
(1,2,3,4)
julia> permutation(Omega, x)
(1,2,4,7)(3,6,9,12)(5,8,10,11)
```
"""
function permutation(Omega::GSetByElements{T}, g::Union{GAPGroupElem, FinGenAbGroupElem}) where T<:Union{GAPGroup, FinGenAbGroup}
omega_list = GAP.Obj(elements(Omega))
gfun = GAP.Obj(action_function(Omega))
# The following works only because GAP does not check
# whether the given group element 'g' is a group element.
pi = GAP.Globals.PermutationOp(g, omega_list, gfun)
@req pi !== GAP.Globals.fail "no permutation is induced by $g"
return group_element(action_range(Omega), pi)
end
@doc raw"""
GSetBySubgroupTransversal{T, S, E} <: GSet{T}
Objects of this type represent G-sets that describe the left or right cosets
of a subgroup $H$ in a group $G$.
The group $G$ acts on the G-set by multiplication from the right or (after
taking inverses) from the left.
These G-sets store just transversals,
see [`right_transversal`](@ref) and [`left_transversal`](@ref).
The construction of explicit right or left cosets is not necessary in order
to compute the permutation action of elements of $G$ on the cosets.
The fields are
- the group that acts, of type `T`, with elements of type `E`,
- the subgroup whose cosets are the elements, of type `S`,
- the side from which the group acts (`:right` or `:left`),
- the (left or right) transversal, of type `SubgroupTransversal{T, S, E}`,
- the dictionary used to store attributes (orbits, elements, ...).
"""
@attributes mutable struct GSetBySubgroupTransversal{T, S, E} <: GSet{T,GroupCoset{T, S, E}}
group::T
subgroup::S
side::Symbol
transversal::SubgroupTransversal{T, S, E}
function GSetBySubgroupTransversal(G::T, H::S, side::Symbol; check::Bool = true) where {T<:GAPGroup, S<:GAPGroup}
check && @req is_subgroup(H, G)[1] "H must be a subgroup of G"
E = eltype(G)
if side == :right
tr = right_transversal(G, H)
elseif side == :left
tr = left_transversal(G, H)
else
throw(ArgumentError("side must be :right or :left"))
end
return new{T, S, E}(G, H, side, tr, Dict{Symbol,Any}())
end
end
function Base.show(io::IO, ::MIME"text/plain", x::GSetBySubgroupTransversal)
side = (x.side == :right ? "Right" : "Left")
println(io, "$side cosets of")
io = pretty(io)
print(io, Indent())
println(io, Lowercase(), x.subgroup, " in")
print(io, Lowercase(), x.group)
print(io, Dedent())
end
function Base.show(io::IO, x::GSetBySubgroupTransversal)
side = (x.side == :right ? "Right" : "Left")
if is_terse(io)
print(io, "$side cosets of groups")
else
print(io, "$side cosets of ")
io = pretty(io)
print(terse(io), Lowercase(), x.subgroup, " in ", Lowercase(), x.group)
end
end
acting_group(Omega::GSetBySubgroupTransversal) = Omega.group
action_function(Omega::GSetBySubgroupTransversal) = ((Omega.side == :right) ? (Base.:*) : function(omega, g) return inv(g)*omega; end)
function Base.in(omega::GroupCoset, Omega::GSetBySubgroupTransversal)
return omega.side == Omega.side &&
omega.G == Omega.group && omega.H == Omega.subgroup
end
Base.length(Omega::GSetBySubgroupTransversal) = index(Int, Omega.group, Omega.subgroup)
Base.length(::Type{T}, Omega::GSetBySubgroupTransversal) where T <: IntegerUnion = index(T, Omega.group, Omega.subgroup)
Base.lastindex(Omega::GSetBySubgroupTransversal) = length(Omega)
Base.keys(Omega::GSetBySubgroupTransversal) = keys(1:length(Omega))
function representative(Omega::GSetBySubgroupTransversal)
if Omega.side == :right
return right_coset(Omega.subgroup, one(Omega.group))
else
return left_coset(Omega.subgroup, one(Omega.group))
end
end
function Base.iterate(Omega::GSetBySubgroupTransversal, state = 1)
T = Omega.transversal
state > length(T) && return nothing
if Omega.side == :right
return (right_coset(Omega.subgroup, T[state]), state+1)
else
return (left_coset(Omega.subgroup, T[state]), state+1)
end
end
Base.eltype(::Type{GSetBySubgroupTransversal{T, S, E}}) where {S, T, E} = GroupCoset{T, S, E}
function Base.getindex(Omega::GSetBySubgroupTransversal, i::Int)
if Omega.side == :right
return right_coset(Omega.subgroup, Omega.transversal[i])
else
return left_coset(Omega.subgroup, Omega.transversal[i])
end
end
is_transitive(Omega::GSetBySubgroupTransversal) = true
function orbit(G::T, omega::GroupCoset{T, TH, S}) where {T <: GAPGroup, TH <: GAPGroup, S}
@req G == omega.G "omega must be a left or right coset in G"
return GSetBySubgroupTransversal(G, omega.H, omega.side, check = false)
end
# We could admit the more general `is_subset(G, omega.G)`.
# One problem would be that `omega` would not be a point in the orbit,
# according to the definition of equality for cosets.
function orbit(Omega::GSetBySubgroupTransversal{T, S, E}, omega::GroupCoset{T, S, E}) where {T <: GAPGroup, S <: GAPGroup, E}
@req (Omega.group == omega.G && Omega.subgroup == omega.H && Omega.side == omega.side) "omega is not in Omega"
return Omega
end
orbits(Omega::GSetBySubgroupTransversal) = [Omega]
function permutation(Omega::GSetBySubgroupTransversal{T, S, E}, g::E) where T <: GAPGroup where S <: GAPGroup where E
# The following works because GAP uses its `PositionCanonical`.
# Note that we use `GAP.Globals.OnRight` also for the case of
# a left transversal, since a right transversal is used on the GAP side.
pi = GAP.Globals.PermutationOp(GapObj(g), Omega.transversal.X, GAP.Globals.OnRight)::GapObj
return group_element(action_range(Omega), pi)
end
@attr GAPGroupHomomorphism{T, PermGroup} function action_homomorphism(Omega::GSetBySubgroupTransversal{T, S, E}) where T <: GAPGroup where S <: GAPGroup where E
G = Omega.group
# The following works because GAP uses its `PositionCanonical`.
# Note that we use `GAP.Globals.OnRight` also for the case of
# a left transversal, since a right transversal is used on the GAP side.
acthom = GAP.Globals.ActionHomomorphism(GapObj(G), Omega.transversal.X, GAP.Globals.OnRight)::GapObj
# See the comment about `SetJuliaData` in the `action_homomorphism` method
# for `GSetByElements`.
GAP.Globals.SetJuliaData(acthom, GAP.Obj([Omega, G]))
return GAPGroupHomomorphism(G, action_range(Omega), acthom)
end
############################################################################
##
## action homomorphisms
"""
action_homomorphism(Omega::GSetByElements{T}) where T<:GAPGroup
Return the group homomorphism `act` with domain `G = acting_group(Omega)`
and codomain `symmetric_group(n)` that describes the permutation action
of `G` on `Omega`, where `Omega` has `n` elements.
This means that if an element `g` in `G` maps `collect(Omega)[i]` to
`collect(Omega)[j]` then `act(g)` maps `i` to `j`.
# Examples
```jldoctest
julia> G = symmetric_group(6);
julia> Omega = gset(G, [Set([1, 2])]); # action on unordered pairs
julia> acthom = action_homomorphism(Omega)
Group homomorphism
from Sym(6)
to Sym(15)
julia> g = gen(G, 1)
(1,2,3,4,5,6)
julia> elms = collect(Omega);
julia> actg = acthom(g)
(1,2,3,5,7,10)(4,6,8,11,14,13)(9,12,15)
julia> elms[1]^g == elms[2]
true
julia> 1^actg == 2
true
```
"""
@attr GAPGroupHomomorphism{T, PermGroup} function action_homomorphism(Omega::GSetByElements{T}) where T<:GAPGroup
G = acting_group(Omega)
omega_list = GAP.Obj(collect(Omega))
gap_gens = GapObj(gens(G); recursive = true)
gfun = GAP.Obj(action_function(Omega))
# The following works only because GAP does not check
# whether the given generators in GAP and Julia fit together.
acthom = GAP.Globals.ActionHomomorphism(GapObj(G), omega_list, gap_gens, GAP.Obj(gens(G)), gfun)::GapObj
# The first difficulty on the GAP side is `ImagesRepresentative`
# (which is the easy direction of the action homomorphism):
# In the method in question, GAP does not really know how to compute
# the group element that actually acts from the given group element;
# there is only a rudimentary `FunctionAction` inside the
# `UnderlyingExternalSet` of the GAP homomorphism object `acthom`.
# We could replace this function here,
# but this would introduce overhead for mapping each point.
# Thus we install a special `ImagesRepresentative` method in GAP;
# note that we know how to get the Julia "actor" from the GAP group
# element, by wrapping it into the corresponding Julia group element.
# (Yes, this is also overhead.
# The alternative would be to create a new type of Oscar homomorphism,
# which uses `permutation` or something better for mapping elements.)
GAP.Globals.SetJuliaData(acthom, GAP.Obj([Omega, G]))
return GAPGroupHomomorphism(G, action_range(Omega), acthom)
end
# for convenience: create the G-set on the fly
# (Here we assume that `Omega` is closed, this is dangerous.)
function action_homomorphism(G::PermGroup, Omega)
return action_homomorphism(gset_by_type(G, Omega, eltype(Omega); closed = true))
end
function action_homomorphism(G::PermGroup, fun::Function, Omega; check = true)
return action_homomorphism(GSetByElements(G, fun, Omega, closed = true, check = check))
end
"""
is_conjugate(Omega::GSet, omega1, omega2)
Return `true` if `omega1`, `omega2` are in the same orbit of `Omega`,
and `false` otherwise.
To also obtain a conjugating element use [`is_conjugate_with_data`](@ref).
# Examples
```jldoctest
julia> G = sylow_subgroup(symmetric_group(6), 2)[1]
Permutation group of degree 6 and order 16
julia> Omega = natural_gset(G);
julia> is_conjugate(Omega, 1, 2)
true
julia> is_conjugate(Omega, 1, 5)
false
```
"""
is_conjugate(Omega::GSet, omega1, omega2) = omega2 in orbit(Omega, omega1)
"""
is_conjugate_with_data(Omega::GSet, omega1, omega2)
Determine whether `omega1`, `omega2` are in the same orbit of `Omega`.
If yes, return `(true, g)` where `g` is an element in the group `G` of
`Omega` that maps `omega1` to `omega2`.
If not, return `(false, nothing)`.
If the conjugating element `g` is not needed, use [`is_conjugate`](@ref).
# Examples
```jldoctest
julia> G = sylow_subgroup(symmetric_group(6), 2)[1]
Permutation group of degree 6 and order 16
julia> Omega = natural_gset(G);
julia> is_conjugate_with_data(Omega, 1, 2)
(true, (1,2))
julia> is_conjugate_with_data(Omega, 1, 5)
(false, ())
```
"""
function is_conjugate_with_data(Omega::GSet, omega1, omega2)
# We do not call GAP's 'RepresentativeAction' with points, generators,
# and actors.
# The method in question would create a new 'ExternalSet' object
# with a useless 'FunctionAction' value.
# Instead, we delegate to the image of the action homomorphism.
# (For that, we write down the elements of the G-set.
# Computing the orbit of `omega1` or `omega2` would in principle suffice.)
G = acting_group(Omega)
acthom = action_homomorphism(Omega)
elms = collect(Omega)
pos1 = findfirst(isequal(omega1), elms)
pos1 === nothing && return false, one(G)
pos2 = findfirst(isequal(omega2), elms)
pos2 === nothing && return false, one(G)
img = GAP.Globals.RepresentativeAction(GapObj(image(acthom)[1]), pos1, pos2)
img == GAP.Globals.fail && return false, one(G)
pre = has_preimage_with_preimage(acthom, group_element(image(acthom)[1], img))
@assert(pre[1])
return true, pre[2]
end
############################################################################