Skip to content

Commit 96cf8eb

Browse files
author
Release Manager
committed
sagemathgh-39999: handle permutations in S_n with n > 2^16 This resolves sagemath#39998, as the issue is gap having small and large permutations: https://github.com/gap-system/gap/blob/f0b438db8fa5786d19975e6040076fd46 b08bd85/src/permutat.h#L18-L26 ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation and checked the documentation preview. URL: sagemath#39999 Reported by: Edgar Costa Reviewer(s): Dima Pasechnik, Julian Rüth, Travis Scrimshaw
2 parents 5c8e867 + 4306a45 commit 96cf8eb

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/sage/groups/perm_gps/permgroup_element.pyx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ import sage.interfaces.abc
135135

136136
from sage.libs.gap.libgap import libgap
137137
from sage.libs.gap.gap_includes cimport (UInt, UInt2, UInt4, T_PERM2, T_PERM4,
138-
NEW_PERM2, TNUM_OBJ, DEG_PERM2, DEG_PERM4, CONST_ADDR_PERM2,
139-
CONST_ADDR_PERM4, ADDR_PERM2)
138+
NEW_PERM2, NEW_PERM4, TNUM_OBJ, DEG_PERM2, DEG_PERM4, CONST_ADDR_PERM2,
139+
CONST_ADDR_PERM4, ADDR_PERM2, ADDR_PERM4)
140140
from sage.libs.gap.util cimport initialize
141141
from sage.libs.gap.element cimport (GapElement, GapElement_List,
142142
GapElement_String, GapElement_Permutation, make_GapElement_Permutation)
@@ -890,16 +890,32 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement):
890890
sage: p = SymmetricGroup(0).an_element()
891891
sage: p._libgap_()
892892
()
893+
894+
A minimal test that we handle permutations of degree larger than 2^16 :issue:`39998`::
895+
896+
sage: SymmetricGroup(2**16+1)((2**16,2**16+1))._libgap_() # long time (100 mb)
897+
(65536,65537)
893898
"""
894899
if self._libgap is not None:
895900
return self._libgap
896901
initialize()
897902

898-
cdef Obj res = NEW_PERM2(self.n)
899-
cdef UInt2* p = ADDR_PERM2(res)
900903
cdef UInt i
901-
for i in range(self.n):
902-
p[i] = self.perm[i]
904+
cdef Obj res
905+
cdef UInt2* p2
906+
cdef UInt4* p4
907+
if self.n < 1<<16:
908+
# make a new (small) permutation
909+
res = NEW_PERM2(self.n)
910+
p2 = ADDR_PERM2(res)
911+
for i in range(self.n):
912+
p2[i] = self.perm[i]
913+
else:
914+
# make a new (large) permutation
915+
res = NEW_PERM4(self.n)
916+
p4 = ADDR_PERM4(res)
917+
for i in range(self.n):
918+
p4[i] = self.perm[i]
903919
self._libgap = make_GapElement_Permutation(libgap, res)
904920
return self._libgap
905921

0 commit comments

Comments
 (0)