Skip to content

Commit 8b3883d

Browse files
author
Release Manager
committed
gh-35881: `sage.groups.perm_gps.partn_ref*`: Modularization fixes <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description <!-- Describe your changes here in detail. --> `partn_ref2` depends on `sage.libs.gap`. We restore the independence of `partn_ref` from `sage.libs.gap` by creating a separate function for the case of `PS_first_smallest` with non-`None` `partn_ref_alg` in `partn_ref2`. We also remove the compile-time dependency on flint. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> - Part of: #29705 - Cherry-picked from: #35095 <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35881 Reported by: Matthias Köppe Reviewer(s): David Coudert, Matthias Köppe
2 parents f2abd5a + 526efac commit 8b3883d

File tree

4 files changed

+56
-15
lines changed

4 files changed

+56
-15
lines changed

src/sage/groups/perm_gps/partn_ref/data_structures.pxd

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ from sage.data_structures.bitset_base cimport *
1313
from libc.string cimport memcpy
1414
from libc.stdlib cimport rand
1515
from sage.libs.gmp.mpz cimport *
16-
from sage.groups.perm_gps.partn_ref2.refinement_generic cimport PartitionRefinement_generic
1716

1817

1918
cdef enum:
@@ -260,8 +259,7 @@ cdef PS_print(PartitionStack *PS)
260259

261260
cdef void PS_unit_partition(PartitionStack *PS)
262261

263-
cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=?,
264-
PartitionRefinement_generic partn_ref_alg=?)
262+
cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=?)
265263

266264
cdef PartitionStack *PS_from_list(list L)
267265

src/sage/groups/perm_gps/partn_ref/data_structures.pyx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ from cysignals.memory cimport sig_malloc, sig_calloc, sig_realloc, sig_free
3333

3434
from sage.data_structures.bitset_base cimport *
3535
from sage.rings.integer cimport Integer
36-
from sage.libs.flint.ulong_extras cimport n_is_prime
36+
# from sage.libs.flint.ulong_extras cimport n_is_prime
37+
# -- avoid modularization obstruction -- function is only used for a doctest helper
38+
from sage.arith.misc import is_prime as n_is_prime
39+
3740

3841
# OrbitPartition (OP)
3942

@@ -281,19 +284,17 @@ cdef PS_print_partition(PartitionStack *PS, int k):
281284
s = s[:-1] + ')'
282285
print(s)
283286

284-
cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=NULL,
285-
PartitionRefinement_generic partn_ref_alg=None):
287+
cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=NULL):
286288
"""
287289
Find the first occurrence of the smallest cell of size greater than one,
288290
which is admissible (checked by the function ``test_allowance``).
289291
Its entries are stored to b and its minimum element is returned.
290292
"""
291293
cdef int i = 0, j = 0, location = 0, n = PS.degree
292294
bitset_zero(b)
293-
while 1:
295+
while True:
294296
if PS.levels[i] <= PS.depth:
295-
if i != j and n > i - j + 1 and (partn_ref_alg is None or
296-
partn_ref_alg._minimization_allowed_on_col(PS.entries[j])):
297+
if i != j and n > i - j + 1:
297298
n = i - j + 1
298299
location = j
299300
j = i + 1
@@ -303,19 +304,18 @@ cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=NULL,
303304
# location now points to the beginning of the first, smallest,
304305
# nontrivial cell
305306
i = location
306-
while 1:
307+
while True:
307308
bitset_flip(b, PS.entries[i])
308309
if PS.levels[i] <= PS.depth:
309310
break
310311
i += 1
311312

312313
if second_pos != NULL:
313-
if n==2:
314-
second_pos[0] = PS.entries[location+1]
314+
if n == 2:
315+
second_pos[0] = PS.entries[location + 1]
315316
else:
316317
second_pos[0] = -1
317318

318-
319319
return PS.entries[location]
320320

321321

src/sage/groups/perm_gps/partn_ref2/refinement_generic.pxd

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# http://www.gnu.org/licenses/
88
#*******************************************************************************
99

10+
from sage.data_structures.bitset_base cimport *
1011
from sage.groups.perm_gps.partn_ref.data_structures cimport OrbitPartition, PartitionStack
1112
from sage.libs.gap.element cimport GapElement, GapElement_Permutation
1213
from sage.structure.parent cimport Parent
@@ -82,3 +83,7 @@ cdef class PartitionRefinement_generic:
8283
bint* inner_group_changed, bint* changed_partition,
8384
str refine_name)
8485
cdef int len(self)
86+
87+
88+
cdef int PS_first_smallest_PR(PartitionStack *PS, bitset_t b, int *second_pos=?,
89+
PartitionRefinement_generic partn_ref_alg=?)

src/sage/groups/perm_gps/partn_ref2/refinement_generic.pyx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ cdef class PartitionRefinement_generic:
684684
bitset_init(b, self._n)
685685
PS_move_all_mins_to_front(self._part)
686686
cdef int second_pos
687-
cdef int smallest = PS_first_smallest(self._part, b, &second_pos,
688-
self)
687+
cdef int smallest = PS_first_smallest_PR(self._part, b, &second_pos, self)
689688
if second_pos != -1:
690689
self._fixed_not_minimized.append(second_pos)
691690
cdef int pos = smallest
@@ -941,3 +940,42 @@ cdef class PartitionRefinement_generic:
941940
"""
942941
if BACKTRACK_WITHLATEX_DEBUG:
943942
self._latex_debug_string += "]\n"
943+
944+
945+
cdef int PS_first_smallest_PR(PartitionStack *PS, bitset_t b, int *second_pos=NULL,
946+
PartitionRefinement_generic partn_ref_alg=None):
947+
"""
948+
Find the first occurrence of the smallest cell of size greater than one,
949+
which is admissible (checked by the function ``test_allowance``).
950+
Its entries are stored to b and its minimum element is returned.
951+
952+
This generalizes :func:`sage.groups.perm_gps.partn_ref.data_structures.PS_first_smallest`.
953+
"""
954+
cdef int i = 0, j = 0, location = 0, n = PS.degree
955+
bitset_zero(b)
956+
while True:
957+
if PS.levels[i] <= PS.depth:
958+
if i != j and n > i - j + 1 and (partn_ref_alg is None or
959+
partn_ref_alg._minimization_allowed_on_col(PS.entries[j])):
960+
n = i - j + 1
961+
location = j
962+
j = i + 1
963+
if PS.levels[i] == -1:
964+
break
965+
i += 1
966+
# location now points to the beginning of the first, smallest,
967+
# nontrivial cell
968+
i = location
969+
while True:
970+
bitset_flip(b, PS.entries[i])
971+
if PS.levels[i] <= PS.depth:
972+
break
973+
i += 1
974+
975+
if second_pos != NULL:
976+
if n == 2:
977+
second_pos[0] = PS.entries[location + 1]
978+
else:
979+
second_pos[0] = -1
980+
981+
return PS.entries[location]

0 commit comments

Comments
 (0)