-
Notifications
You must be signed in to change notification settings - Fork 113
/
groups.jl
320 lines (274 loc) · 9.91 KB
/
groups.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
function PermGroup_to_polymake_array(G::PermGroup)
generators = gens(G)
d = degree(G)
return _group_generators_to_pm_arr_arr(generators, d)
end
function _group_generators_to_pm_arr_arr(generators::AbstractVector{PermGroupElem}, d::Int)
if length(generators) == 0
generators = elements(trivial_subgroup(symmetric_group(d))[1])
end
result = Polymake.Array{Polymake.Array{Polymake.to_cxx_type(Int)}}(length(generators))
i = 1
for g in generators
array = Polymake.Array{Polymake.to_cxx_type(Int)}(d)
for j in 1:d
array[j] = g(j) - 1
end
result[i] = array
i = i + 1
end
return result
end
function _gens_to_group(gens::Vector{PermGroupElem})
@req length(gens) > 0 "List of generators empty, could not deduce degree"
S = parent(gens[1])
return sub(S, gens)[1]
end
function _gens_to_group(gens::Dict{Symbol,Vector{PermGroupElem}})
return Dict{Symbol,PermGroup}([k => _gens_to_group(v) for (k, v) in gens])
end
function _pm_arr_arr_to_group_generators(M, n)
S = symmetric_group(n)
perm_bucket = Vector{Oscar.BasicGAPGroupElem{PermGroup}}()
for g in M
push!(perm_bucket, perm(S, Polymake.to_one_based_indexing(g)))
end
if length(M) == 0
push!(perm_bucket, perm(S, Int[]))
end
return perm_bucket
end
@doc raw"""
combinatorial_symmetries(P::Polyhedron)
Compute the combinatorial symmetries (i.e., automorphisms of the face lattice)
of a given polytope $P$. The result is given as permutations of the vertices
(or rather vertex indices) of $P$. This group contains the `linear_symmetries`
as a subgroup.
# Examples
The quadrangle one obtains from moving one vertex of the square out along the
diagonal has eight combinatorial symmetries, but only two linear symmetries.
```jldoctest
julia> quad = convex_hull([0 0; 1 0; 2 2; 0 1])
Polyhedron in ambient dimension 2
julia> G = combinatorial_symmetries(quad)
Permutation group of degree 4
julia> order(G)
8
julia> G = linear_symmetries(quad)
Permutation group of degree 4
julia> order(G)
2
```
"""
combinatorial_symmetries(P::Polyhedron) =
automorphism_group(P; type=:combinatorial, action=:on_vertices)
@doc raw"""
linear_symmetries(P::Polyhedron)
Get the group of linear symmetries on the vertices of a polyhedron. These are
morphisms of the form $x\mapsto Ax+b$,with $A$ a matrix and $b$ a vector, that
preserve the polyhedron $P$. The result is given as permutations of the
vertices (or rather vertex indices) of $P$.
# Examples
The 3-dimensional cube has 48 linear symmetries.
```jldoctest
julia> c = cube(3)
Polytope in ambient dimension 3
julia> G = linear_symmetries(c)
Permutation group of degree 8
julia> order(G)
48
```
The quadrangle one obtains from moving one vertex of the square out along the
diagonal has two linear symmetries.
```jldoctest
julia> quad = convex_hull([0 0; 1 0; 2 2; 0 1])
Polyhedron in ambient dimension 2
julia> G = linear_symmetries(quad)
Permutation group of degree 4
julia> order(G)
2
```
"""
linear_symmetries(P::Polyhedron) = automorphism_group(P; type=:linear, action=:on_vertices)
@doc raw"""
automorphism_group_generators(P::Polyhedron; type = :combinatorial, action = :all)
Compute generators of the group of automorphisms of a polyhedron.
The optional parameter `type` takes two values:
- `:combinatorial` (default) -- Return the combinatorial symmetries, the
automorphisms of the face lattice.
- `:linear` -- Return the linear automorphisms.
The optional parameter `action` takes three values:
- `:all` (default) -- Return the generators of the permutation action on both
vertices and facets as a Dict{Symbol, Vector{PermGroupElem}}.
- `:on_vertices` -- Only return generators of the permutation action on the
vertices.
- `:on_facets` -- Only return generators of the permutation action on the
facets.
The return value is a `Dict{Symbol, Vector{PermGroupElem}}` with two entries,
one for the key `:on_vertices` containing the generators for the action
permuting the vertices, and `:on_facets` for the facets.
# Examples
Compute the automorphisms of the 3dim cube:
```jldoctest
julia> c = cube(3)
Polytope in ambient dimension 3
julia> automorphism_group_generators(c)
Dict{Symbol, Vector{PermGroupElem}} with 2 entries:
:on_vertices => [(3,5)(4,6), (2,3)(6,7), (1,2)(3,4)(5,6)(7,8)]
:on_facets => [(3,5)(4,6), (1,3)(2,4), (1,2)]
julia> automorphism_group_generators(c; action = :on_vertices)
3-element Vector{PermGroupElem}:
(3,5)(4,6)
(2,3)(6,7)
(1,2)(3,4)(5,6)(7,8)
julia> automorphism_group_generators(c; action = :on_facets)
3-element Vector{PermGroupElem}:
(3,5)(4,6)
(1,3)(2,4)
(1,2)
```
Compute the automorphisms of a non-quadratic quadrangle. Since it has less
symmetry than the square, it has less linear symmetries.
```jldoctest
julia> quad = convex_hull([0 0; 1 0; 2 2; 0 1])
Polyhedron in ambient dimension 2
julia> automorphism_group_generators(quad)
Dict{Symbol, Vector{PermGroupElem}} with 2 entries:
:on_vertices => [(2,4), (1,2)(3,4)]
:on_facets => [(1,2)(3,4), (1,3)]
julia> automorphism_group_generators(quad; type = :combinatorial)
Dict{Symbol, Vector{PermGroupElem}} with 2 entries:
:on_vertices => [(2,4), (1,2)(3,4)]
:on_facets => [(1,2)(3,4), (1,3)]
julia> automorphism_group_generators(quad; type = :linear)
Dict{Symbol, Vector{PermGroupElem}} with 2 entries:
:on_vertices => [(2,4)]
:on_facets => [(1,2)(3,4)]
```
"""
function automorphism_group_generators(P::Polyhedron; type=:combinatorial, action=:all)
@req is_bounded(P) "Automorphism groups not supported for unbounded polyhedra."
if type == :combinatorial
IM = vertex_indices(facets(P))
if action == :all
result = automorphism_group_generators(IM; action=action)
return Dict{Symbol,Vector{PermGroupElem}}(
:on_vertices => result[:on_cols], :on_facets => result[:on_rows]
)
elseif action == :on_vertices
return automorphism_group_generators(IM; action=:on_cols)
elseif action == :on_facets
return automorphism_group_generators(IM; action=:on_rows)
else
throw(ArgumentError("Action $(action) not supported."))
end
elseif type == :linear
return _linear_symmetries_generators(P; action=action)
else
throw(ArgumentError("Action type $(type) not supported."))
end
return Dict{Symbol,Vector{PermGroupElem}}(
:on_vertices => vertex_action, :on_facets => facet_action
)
end
@doc raw"""
automorphism_group_generators(IM::IncidenceMatrix; action = :all)
Compute the generators of the group of automorphisms of an IncidenceMatrix.
The optional parameter `action` takes three values:
- `:all` (default) -- Return the generators of the permutation action on both
columns and rows as a Dict{Symbol, Vector{PermGroupElem}}.
- `:on_cols` -- Only return generators of the permutation action on the
columns.
- `:on_rows` -- Only return generators of the permutation action on the
rows.
# Examples
Compute the automorphisms of the incidence matrix of the 3dim cube:
```jldoctest
julia> c = cube(3)
Polytope in ambient dimension 3
julia> IM = vertex_indices(facets(c))
6×8 IncidenceMatrix
[1, 3, 5, 7]
[2, 4, 6, 8]
[1, 2, 5, 6]
[3, 4, 7, 8]
[1, 2, 3, 4]
[5, 6, 7, 8]
julia> automorphism_group_generators(IM)
Dict{Symbol, Vector{PermGroupElem}} with 2 entries:
:on_cols => [(3,5)(4,6), (2,3)(6,7), (1,2)(3,4)(5,6)(7,8)]
:on_rows => [(3,5)(4,6), (1,3)(2,4), (1,2)]
julia> automorphism_group_generators(IM; action = :on_rows)
3-element Vector{PermGroupElem}:
(3,5)(4,6)
(1,3)(2,4)
(1,2)
julia> automorphism_group_generators(IM; action = :on_cols)
3-element Vector{PermGroupElem}:
(3,5)(4,6)
(2,3)(6,7)
(1,2)(3,4)(5,6)(7,8)
```
"""
function automorphism_group_generators(IM::IncidenceMatrix; action=:all)
gens = Polymake.graph.automorphisms(IM)
rows_action = _pm_arr_arr_to_group_generators(
[first(g) for g in gens], Polymake.nrows(IM)
)
if action == :on_rows
return rows_action
end
cols_action = _pm_arr_arr_to_group_generators([last(g) for g in gens], Polymake.ncols(IM))
if action == :on_cols
return cols_action
elseif action == :all
return Dict{Symbol,Vector{PermGroupElem}}(
:on_rows => rows_action, :on_cols => cols_action
)
else
throw(ArgumentError("Action $(action) not supported."))
end
end
function _linear_symmetries_generators(P::Polyhedron; action=:all)
if is_bounded(P)
gp = Polymake.polytope.linear_symmetries(vertices(P))
vaction = gp.PERMUTATION_ACTION
if action == :on_vertices
return _pm_arr_arr_to_group_generators(vaction.GENERATORS, vaction.DEGREE)
end
hgens = Polymake.group.induced_permutations(
vaction.GENERATORS, vertex_indices(facets(P))
)
if action == :on_facets
return _pm_arr_arr_to_group_generators(hgens, n_facets(P))
end
return Dict{Symbol,Vector{PermGroupElem}}(
:on_vertices => _pm_arr_arr_to_group_generators(vaction.GENERATORS, vaction.DEGREE),
:on_facets => _pm_arr_arr_to_group_generators(hgens, n_facets(P)),
)
else
throw(ArgumentError("Linear symmetries supported for bounded polyhedra only"))
end
end
@doc raw"""
automorphism_group(P::Polyhedron; type = :combinatorial, action = :all)
Compute the group of automorphisms of a polyhedron. The parameters and return
values are the same as for [`automorphism_group_generators(P::Polyhedron; type
= :combinatorial, action = :all)`](@ref) except that groups are returned
instead of generators of groups.
"""
function automorphism_group(P::Polyhedron; type=:combinatorial, action=:all)
result = automorphism_group_generators(P; type=type, action=action)
return _gens_to_group(result)
end
@doc raw"""
automorphism_group(IM::IncidenceMatrix; action = :all)
Compute the group of automorphisms of an IncidenceMatrix. The parameters and
return values are the same as for
[`automorphism_group_generators(IM::IncidenceMatrix; action = :all)`](@ref)
except that groups are returned instead of generators of groups.
"""
function automorphism_group(IM::IncidenceMatrix; action=:all)
result = automorphism_group_generators(IM; action=action)
return _gens_to_group(result)
end