Skip to content
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

sage.groups.perm_gps.partn_ref*: Modularization fixes #35881

Merged
merged 5 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions src/sage/groups/perm_gps/partn_ref/data_structures.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ from sage.data_structures.bitset_base cimport *
from libc.string cimport memcpy
from libc.stdlib cimport rand
from sage.libs.gmp.mpz cimport *
from sage.groups.perm_gps.partn_ref2.refinement_generic cimport PartitionRefinement_generic


cdef enum:
Expand Down Expand Up @@ -260,8 +259,7 @@ cdef PS_print(PartitionStack *PS)

cdef void PS_unit_partition(PartitionStack *PS)

cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=?,
PartitionRefinement_generic partn_ref_alg=?)
cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=?)

cdef PartitionStack *PS_from_list(list L)

Expand Down
20 changes: 10 additions & 10 deletions src/sage/groups/perm_gps/partn_ref/data_structures.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ from cysignals.memory cimport sig_malloc, sig_calloc, sig_realloc, sig_free

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


# OrbitPartition (OP)

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

cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=NULL,
PartitionRefinement_generic partn_ref_alg=None):
cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=NULL):
"""
Find the first occurrence of the smallest cell of size greater than one,
which is admissible (checked by the function ``test_allowance``).
Its entries are stored to b and its minimum element is returned.
"""
cdef int i = 0, j = 0, location = 0, n = PS.degree
bitset_zero(b)
while 1:
while True:
if PS.levels[i] <= PS.depth:
if i != j and n > i - j + 1 and (partn_ref_alg is None or
partn_ref_alg._minimization_allowed_on_col(PS.entries[j])):
if i != j and n > i - j + 1:
n = i - j + 1
location = j
j = i + 1
Expand All @@ -303,19 +304,18 @@ cdef int PS_first_smallest(PartitionStack *PS, bitset_t b, int *second_pos=NULL,
# location now points to the beginning of the first, smallest,
# nontrivial cell
i = location
while 1:
while True:
bitset_flip(b, PS.entries[i])
if PS.levels[i] <= PS.depth:
break
i += 1

if second_pos != NULL:
if n==2:
second_pos[0] = PS.entries[location+1]
if n == 2:
second_pos[0] = PS.entries[location + 1]
else:
second_pos[0] = -1


return PS.entries[location]


Expand Down
5 changes: 5 additions & 0 deletions src/sage/groups/perm_gps/partn_ref2/refinement_generic.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# http://www.gnu.org/licenses/
#*******************************************************************************

from sage.data_structures.bitset_base cimport *
from sage.groups.perm_gps.partn_ref.data_structures cimport OrbitPartition, PartitionStack
from sage.libs.gap.element cimport GapElement, GapElement_Permutation
from sage.structure.parent cimport Parent
Expand Down Expand Up @@ -82,3 +83,7 @@ cdef class PartitionRefinement_generic:
bint* inner_group_changed, bint* changed_partition,
str refine_name)
cdef int len(self)


cdef int PS_first_smallest_PR(PartitionStack *PS, bitset_t b, int *second_pos=?,
PartitionRefinement_generic partn_ref_alg=?)
42 changes: 40 additions & 2 deletions src/sage/groups/perm_gps/partn_ref2/refinement_generic.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,7 @@ cdef class PartitionRefinement_generic:
bitset_init(b, self._n)
PS_move_all_mins_to_front(self._part)
cdef int second_pos
cdef int smallest = PS_first_smallest(self._part, b, &second_pos,
self)
cdef int smallest = PS_first_smallest_PR(self._part, b, &second_pos, self)
if second_pos != -1:
self._fixed_not_minimized.append(second_pos)
cdef int pos = smallest
Expand Down Expand Up @@ -941,3 +940,42 @@ cdef class PartitionRefinement_generic:
"""
if BACKTRACK_WITHLATEX_DEBUG:
self._latex_debug_string += "]\n"


cdef int PS_first_smallest_PR(PartitionStack *PS, bitset_t b, int *second_pos=NULL,
PartitionRefinement_generic partn_ref_alg=None):
"""
Find the first occurrence of the smallest cell of size greater than one,
which is admissible (checked by the function ``test_allowance``).
Its entries are stored to b and its minimum element is returned.

This generalizes :func:`sage.groups.perm_gps.partn_ref.data_structures.PS_first_smallest`.
"""
cdef int i = 0, j = 0, location = 0, n = PS.degree
bitset_zero(b)
while True:
if PS.levels[i] <= PS.depth:
if i != j and n > i - j + 1 and (partn_ref_alg is None or
partn_ref_alg._minimization_allowed_on_col(PS.entries[j])):
n = i - j + 1
location = j
j = i + 1
if PS.levels[i] == -1:
break
i += 1
# location now points to the beginning of the first, smallest,
# nontrivial cell
i = location
while True:
bitset_flip(b, PS.entries[i])
if PS.levels[i] <= PS.depth:
break
i += 1

if second_pos != NULL:
if n == 2:
second_pos[0] = PS.entries[location + 1]
else:
second_pos[0] = -1

return PS.entries[location]
Loading