Skip to content

handle permutations in S_n with n > 2^16 #39999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/sage/groups/perm_gps/permgroup_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ import sage.interfaces.abc

from sage.libs.gap.libgap import libgap
from sage.libs.gap.gap_includes cimport (UInt, UInt2, UInt4, T_PERM2, T_PERM4,
NEW_PERM2, TNUM_OBJ, DEG_PERM2, DEG_PERM4, CONST_ADDR_PERM2,
CONST_ADDR_PERM4, ADDR_PERM2)
NEW_PERM2, NEW_PERM4, TNUM_OBJ, DEG_PERM2, DEG_PERM4, CONST_ADDR_PERM2,
CONST_ADDR_PERM4, ADDR_PERM2, ADDR_PERM4)
from sage.libs.gap.util cimport initialize
from sage.libs.gap.element cimport (GapElement, GapElement_List,
GapElement_String, GapElement_Permutation, make_GapElement_Permutation)
Expand Down Expand Up @@ -890,16 +890,32 @@ cdef class PermutationGroupElement(MultiplicativeGroupElement):
sage: p = SymmetricGroup(0).an_element()
sage: p._libgap_()
()

Test that we handle large permutations :issue:`39998`::

sage: SymmetricGroup(2**17)((2**16,2**17-1))._libgap_()
(65536,131071)
"""
if self._libgap is not None:
return self._libgap
initialize()

cdef Obj res = NEW_PERM2(self.n)
cdef UInt2* p = ADDR_PERM2(res)
cdef UInt i
for i in range(self.n):
p[i] = self.perm[i]
cdef Obj res
cdef UInt2* p2
cdef UInt4* p4
if self.n < 1<<16:
# make a new (small) permutation
res = NEW_PERM2(self.n)
p2 = ADDR_PERM2(res)
for i in range(self.n):
p2[i] = self.perm[i]
else:
# make a new (large) permutation
res = NEW_PERM4(self.n)
p4 = ADDR_PERM4(res)
for i in range(self.n):
p4[i] = self.perm[i]
self._libgap = make_GapElement_Permutation(libgap, res)
return self._libgap

Expand Down
Loading