@@ -3188,11 +3188,6 @@ def _palp_PM_max(self, check=False):
3188
3188
sage: all(results) # long time
3189
3189
True
3190
3190
"""
3191
- def PGE (S , u , v ):
3192
- if u == v :
3193
- return S .one ()
3194
- return S ((u , v ), check = False )
3195
-
3196
3191
PM = self .vertex_facet_pairing_matrix ()
3197
3192
n_v = PM .ncols ()
3198
3193
n_f = PM .nrows ()
@@ -3202,27 +3197,23 @@ def PGE(S, u, v):
3202
3197
# and find all the ways of making the first row of PM_max
3203
3198
def index_of_max (iterable ):
3204
3199
# returns the index of max of any iterable
3205
- m , x = 0 , iterable [0 ]
3206
- for k , l in enumerate (iterable ):
3207
- if l > x :
3208
- m , x = k , l
3209
- return m
3200
+ return max (enumerate (iterable ), key = lambda x : x [1 ])[0 ]
3210
3201
3211
3202
n_s = 1
3212
3203
permutations = {0 : [S_f .one (), S_v .one ()]}
3213
3204
for j in range (n_v ):
3214
- m = index_of_max ([ PM [0 ][ i ] for i in range (j , n_v )] )
3205
+ m = index_of_max (PM [0 , i ] for i in range (j , n_v ))
3215
3206
if m > 0 :
3216
- permutations [0 ][1 ] = PGE ( S_v , j + 1 , m + j + 1 ) * permutations [0 ][1 ]
3207
+ permutations [0 ][1 ] = S_v (( j + 1 , m + j + 1 ), check = False ) * permutations [0 ][1 ]
3217
3208
first_row = list (PM [0 ])
3218
3209
3219
3210
# Arrange other rows one by one and compare with first row
3220
3211
for k in range (1 , n_f ):
3221
3212
# Error for k == 1 already!
3222
3213
permutations [n_s ] = [S_f .one (), S_v .one ()]
3223
- m = index_of_max (tuple ( PM [k , permutations [n_s ][1 ](j + 1 ) - 1 ] for j in range (n_v ) ))
3214
+ m = index_of_max (PM [k , permutations [n_s ][1 ](j + 1 ) - 1 ] for j in range (n_v ))
3224
3215
if m > 0 :
3225
- permutations [n_s ][1 ] = PGE ( S_v , 1 , m + 1 ) * permutations [n_s ][1 ]
3216
+ permutations [n_s ][1 ] = S_v (( 1 , m + 1 ), check = False ) * permutations [n_s ][1 ]
3226
3217
d = (PM [k , permutations [n_s ][1 ](1 ) - 1 ]
3227
3218
- permutations [0 ][1 ](first_row )[0 ])
3228
3219
if d < 0 :
@@ -3231,9 +3222,9 @@ def index_of_max(iterable):
3231
3222
continue
3232
3223
# otherwise:
3233
3224
for i in range (1 , n_v ):
3234
- m = index_of_max (tuple ( PM [k , permutations [n_s ][1 ](j + 1 ) - 1 ] for j in range (i ,n_v ) ))
3225
+ m = index_of_max (PM [k , permutations [n_s ][1 ](j + 1 ) - 1 ] for j in range (i ,n_v ))
3235
3226
if m > 0 :
3236
- permutations [n_s ][1 ] = PGE ( S_v , i + 1 , m + i + 1 ) \
3227
+ permutations [n_s ][1 ] = S_v (( i + 1 , m + i + 1 ), check = False ) \
3237
3228
* permutations [n_s ][1 ]
3238
3229
if d == 0 :
3239
3230
d = (PM [k , permutations [n_s ][1 ](i + 1 ) - 1 ]
@@ -3244,7 +3235,7 @@ def index_of_max(iterable):
3244
3235
# This row is smaller than 1st row, so nothing to do
3245
3236
del permutations [n_s ]
3246
3237
continue
3247
- permutations [n_s ][0 ] = PGE ( S_f , 1 , k + 1 ) * permutations [n_s ][0 ]
3238
+ permutations [n_s ][0 ] = S_f (( 1 , k + 1 ), check = False ) * permutations [n_s ][0 ]
3248
3239
if d == 0 :
3249
3240
# This row is the same, so we have a symmetry!
3250
3241
n_s += 1
@@ -3293,10 +3284,11 @@ def index_of_max(iterable):
3293
3284
v0 = PM [permutations_bar [n_p ][0 ](s + 1 ) - 1 , permutations_bar [n_p ][1 ](1 ) - 1 ]
3294
3285
vj = PM [permutations_bar [n_p ][0 ](s + 1 ) - 1 , permutations_bar [n_p ][1 ](j + 1 ) - 1 ]
3295
3286
if v0 < vj :
3296
- permutations_bar [n_p ][1 ] = PGE ( S_v , 1 , j + 1 ) * permutations_bar [n_p ][1 ]
3287
+ permutations_bar [n_p ][1 ] = S_v (( 1 , j + 1 ), check = False ) * permutations_bar [n_p ][1 ]
3297
3288
if ccf == 0 :
3298
3289
l_r [0 ] = PM [permutations_bar [n_p ][0 ](s + 1 ) - 1 , permutations_bar [n_p ][1 ](1 ) - 1 ]
3299
- permutations_bar [n_p ][0 ] = PGE (S_f , l + 1 , s + 1 ) * permutations_bar [n_p ][0 ]
3290
+ if s != l :
3291
+ permutations_bar [n_p ][0 ] = S_f ((l + 1 , s + 1 ), check = False ) * permutations_bar [n_p ][0 ]
3300
3292
n_p += 1
3301
3293
ccf = 1
3302
3294
permutations_bar [n_p ] = copy (permutations [k ])
@@ -3308,14 +3300,16 @@ def index_of_max(iterable):
3308
3300
continue
3309
3301
elif d == 0 :
3310
3302
# Maximal values agree, so possible symmetry
3311
- permutations_bar [n_p ][0 ] = PGE (S_f , l + 1 , s + 1 ) * permutations_bar [n_p ][0 ]
3303
+ if s != l :
3304
+ permutations_bar [n_p ][0 ] = S_f ((l + 1 , s + 1 ), check = False ) * permutations_bar [n_p ][0 ]
3312
3305
n_p += 1
3313
3306
permutations_bar [n_p ] = copy (permutations [k ])
3314
3307
else :
3315
3308
# We found a greater maximal value for first entry.
3316
3309
# It becomes our new reference:
3317
3310
l_r [0 ] = d1
3318
- permutations_bar [n_p ][0 ] = PGE (S_f , l + 1 , s + 1 ) * permutations_bar [n_p ][0 ]
3311
+ if s != l :
3312
+ permutations_bar [n_p ][0 ] = S_f ((l + 1 , s + 1 ), check = False ) * permutations_bar [n_p ][0 ]
3319
3313
# Forget previous work done
3320
3314
cf = 0
3321
3315
permutations_bar = {0 :copy (permutations_bar [n_p ])}
@@ -3340,7 +3334,7 @@ def index_of_max(iterable):
3340
3334
vc = PM [(permutations_bar [s ][0 ])(l + 1 ) - 1 , (permutations_bar [s ][1 ])(c + 1 ) - 1 ]
3341
3335
vj = PM [(permutations_bar [s ][0 ])(l + 1 ) - 1 , (permutations_bar [s ][1 ])(j + 1 ) - 1 ]
3342
3336
if (vc < vj ):
3343
- permutations_bar [s ][1 ] = PGE ( S_v , c + 1 , j + 1 ) * permutations_bar [s ][1 ]
3337
+ permutations_bar [s ][1 ] = S_v (( c + 1 , j + 1 ), check = False ) * permutations_bar [s ][1 ]
3344
3338
if ccf == 0 :
3345
3339
# Set reference and carry on to next permutation
3346
3340
l_r [c ] = PM [(permutations_bar [s ][0 ])(l + 1 ) - 1 , (permutations_bar [s ][1 ])(c + 1 ) - 1 ]
@@ -5188,11 +5182,10 @@ def _palp_canonical_order(V, PM_max, permutations):
5188
5182
in 2-d lattice M, (1,3,2,4))
5189
5183
"""
5190
5184
n_v = PM_max .ncols ()
5191
- n_f = PM_max .nrows ()
5192
5185
S_v = SymmetricGroup (n_v )
5193
5186
p_c = S_v .one ()
5194
- M_max = [max ([ PM_max [ i ][ j ] for i in range ( n_f )] ) for j in range (n_v )]
5195
- S_max = [ sum ([ PM_max [ i ][ j ] for i in range ( n_f )]) for j in range ( n_v )]
5187
+ M_max = [max (row [ j ] for row in PM_max . rows () ) for j in range (n_v )]
5188
+ S_max = sum (PM_max )
5196
5189
for i in range (n_v ):
5197
5190
k = i
5198
5191
for j in range (i + 1 , n_v ):
0 commit comments