@@ -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,53 +3197,45 @@ 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
- permutations = {0 : [S_f .one (), S_v .one ()]}
3203
+ permutations = {0 : [S_f .one (), S_v .one ()]}
3213
3204
for j in range (n_v ):
3214
- m = index_of_max (
3215
- [(PM .with_permuted_columns (permutations [0 ][1 ]))[0 ][i ]
3216
- for i in range (j , n_v )])
3205
+ m = index_of_max (PM [0 , i ] for i in range (j , n_v ))
3217
3206
if m > 0 :
3218
- 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 ]
3219
3208
first_row = list (PM [0 ])
3220
3209
3221
3210
# Arrange other rows one by one and compare with first row
3222
3211
for k in range (1 , n_f ):
3223
3212
# Error for k == 1 already!
3224
3213
permutations [n_s ] = [S_f .one (), S_v .one ()]
3225
- m = index_of_max (PM . with_permuted_columns ( permutations [n_s ][1 ])[ k ] )
3214
+ m = index_of_max (PM [ k , permutations [n_s ][1 ]( j + 1 ) - 1 ] for j in range ( n_v ) )
3226
3215
if m > 0 :
3227
- permutations [n_s ][1 ] = PGE ( S_v , 1 , m + 1 ) * permutations [n_s ][1 ]
3228
- d = (( PM . with_permuted_columns ( permutations [n_s ][1 ]))[ k ][ 0 ]
3216
+ permutations [n_s ][1 ] = S_v (( 1 , m + 1 ), check = False ) * permutations [n_s ][1 ]
3217
+ d = (PM [ k , permutations [n_s ][1 ]( 1 ) - 1 ]
3229
3218
- permutations [0 ][1 ](first_row )[0 ])
3230
3219
if d < 0 :
3231
3220
# The largest elt of this row is smaller than largest elt
3232
3221
# in 1st row, so nothing to do
3233
3222
continue
3234
3223
# otherwise:
3235
3224
for i in range (1 , n_v ):
3236
- m = index_of_max (
3237
- [PM .with_permuted_columns (permutations [n_s ][1 ])[k ][j ]
3238
- 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 ))
3239
3226
if m > 0 :
3240
- 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 ) \
3241
3228
* permutations [n_s ][1 ]
3242
3229
if d == 0 :
3243
- d = (PM . with_permuted_columns ( permutations [n_s ][1 ])[ k ][ i ]
3230
+ d = (PM [ k , permutations [n_s ][1 ]( i + 1 ) - 1 ]
3244
3231
- permutations [0 ][1 ](first_row )[i ])
3245
3232
if d < 0 :
3246
3233
break
3247
3234
if d < 0 :
3248
3235
# This row is smaller than 1st row, so nothing to do
3249
3236
del permutations [n_s ]
3250
3237
continue
3251
- 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 ]
3252
3239
if d == 0 :
3253
3240
# This row is the same, so we have a symmetry!
3254
3241
n_s += 1
@@ -3258,9 +3245,9 @@ def index_of_max(iterable):
3258
3245
first_row = list (PM [k ])
3259
3246
permutations = {0 : permutations [n_s ]}
3260
3247
n_s = 1
3261
- permutations = {k :permutations [k ] for k in permutations if k < n_s }
3248
+ permutations = {k : permutations [k ] for k in permutations if k < n_s }
3262
3249
3263
- b = PM . with_permuted_rows_and_columns ( * permutations [0 ]) [0 ]
3250
+ b = tuple ( PM [ permutations [0 ][ 0 ]( 1 ) - 1 , permutations [0 ][ 1 ]( j + 1 ) - 1 ] for j in range ( n_v ))
3264
3251
# Work out the restrictions the current permutations
3265
3252
# place on other permutations as a automorphisms
3266
3253
# of the first row
@@ -3294,34 +3281,35 @@ def index_of_max(iterable):
3294
3281
# between 0 and S(0)
3295
3282
for s in range (l , n_f ):
3296
3283
for j in range (1 , S [0 ]):
3297
- v = PM . with_permuted_rows_and_columns (
3298
- * permutations_bar [n_p ])[ s ]
3299
- if v [ 0 ] < v [ j ] :
3300
- permutations_bar [n_p ][1 ] = PGE ( S_v , 1 , j + 1 ) * permutations_bar [n_p ][1 ]
3284
+ v0 = PM [ permutations_bar [ n_p ][ 0 ]( s + 1 ) - 1 , permutations_bar [ n_p ][ 1 ]( 1 ) - 1 ]
3285
+ vj = PM [ permutations_bar [ n_p ][ 0 ]( s + 1 ) - 1 , permutations_bar [n_p ][ 1 ]( j + 1 ) - 1 ]
3286
+ if v0 < vj :
3287
+ permutations_bar [n_p ][1 ] = S_v (( 1 , j + 1 ), check = False ) * permutations_bar [n_p ][1 ]
3301
3288
if ccf == 0 :
3302
- l_r [0 ] = PM . with_permuted_rows_and_columns (
3303
- * permutations_bar [ n_p ])[ s ][ 0 ]
3304
- permutations_bar [n_p ][0 ] = PGE ( S_f , l + 1 , s + 1 ) * permutations_bar [n_p ][0 ]
3289
+ l_r [0 ] = PM [ permutations_bar [ n_p ][ 0 ]( s + 1 ) - 1 , permutations_bar [ n_p ][ 1 ]( 1 ) - 1 ]
3290
+ if s != l :
3291
+ permutations_bar [n_p ][0 ] = S_f (( l + 1 , s + 1 ), check = False ) * permutations_bar [n_p ][0 ]
3305
3292
n_p += 1
3306
3293
ccf = 1
3307
3294
permutations_bar [n_p ] = copy (permutations [k ])
3308
3295
else :
3309
- d1 = PM .with_permuted_rows_and_columns (
3310
- * permutations_bar [n_p ])[s ][0 ]
3296
+ d1 = PM [permutations_bar [n_p ][0 ](s + 1 ) - 1 , permutations_bar [n_p ][1 ](1 ) - 1 ]
3311
3297
d = d1 - l_r [0 ]
3312
3298
if d < 0 :
3313
3299
# We move to the next line
3314
3300
continue
3315
3301
elif d == 0 :
3316
3302
# Maximal values agree, so possible symmetry
3317
- 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 ]
3318
3305
n_p += 1
3319
3306
permutations_bar [n_p ] = copy (permutations [k ])
3320
3307
else :
3321
3308
# We found a greater maximal value for first entry.
3322
3309
# It becomes our new reference:
3323
3310
l_r [0 ] = d1
3324
- 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 ]
3325
3313
# Forget previous work done
3326
3314
cf = 0
3327
3315
permutations_bar = {0 :copy (permutations_bar [n_p ])}
@@ -3343,18 +3331,16 @@ def index_of_max(iterable):
3343
3331
s -= 1
3344
3332
# Find the largest value in this symmetry block
3345
3333
for j in range (c + 1 , h ):
3346
- v = PM . with_permuted_rows_and_columns (
3347
- * permutations_bar [s ])[ l ]
3348
- if (v [ c ] < v [ j ] ):
3349
- permutations_bar [s ][1 ] = PGE ( S_v , c + 1 , j + 1 ) * permutations_bar [s ][1 ]
3334
+ vc = PM [( permutations_bar [ s ][ 0 ])( l + 1 ) - 1 , ( permutations_bar [ s ][ 1 ])( c + 1 ) - 1 ]
3335
+ vj = PM [( permutations_bar [ s ][ 0 ])( l + 1 ) - 1 , ( permutations_bar [s ][ 1 ])( j + 1 ) - 1 ]
3336
+ if (vc < vj ):
3337
+ permutations_bar [s ][1 ] = S_v (( c + 1 , j + 1 ), check = False ) * permutations_bar [s ][1 ]
3350
3338
if ccf == 0 :
3351
3339
# Set reference and carry on to next permutation
3352
- l_r [c ] = PM .with_permuted_rows_and_columns (
3353
- * permutations_bar [s ])[l ][c ]
3340
+ l_r [c ] = PM [(permutations_bar [s ][0 ])(l + 1 ) - 1 , (permutations_bar [s ][1 ])(c + 1 ) - 1 ]
3354
3341
ccf = 1
3355
3342
else :
3356
- d1 = PM .with_permuted_rows_and_columns (
3357
- * permutations_bar [s ])[l ][c ]
3343
+ d1 = PM [(permutations_bar [s ][0 ])(l + 1 ) - 1 , (permutations_bar [s ][1 ])(c + 1 ) - 1 ]
3358
3344
d = d1 - l_r [c ]
3359
3345
if d < 0 :
3360
3346
n_p -= 1
@@ -3383,7 +3369,7 @@ def index_of_max(iterable):
3383
3369
# the restrictions the last worked out
3384
3370
# row imposes.
3385
3371
c = 0
3386
- M = (PM . with_permuted_rows_and_columns ( * permutations [0 ]))[ l ]
3372
+ M = tuple (PM [ permutations [0 ][ 0 ]( l + 1 ) - 1 , permutations [ 0 ][ 1 ]( j + 1 ) - 1 ] for j in range ( n_v ))
3387
3373
while c < n_v :
3388
3374
s = S [c ] + 1
3389
3375
S [c ] = c + 1
@@ -5196,11 +5182,10 @@ def _palp_canonical_order(V, PM_max, permutations):
5196
5182
in 2-d lattice M, (1,3,2,4))
5197
5183
"""
5198
5184
n_v = PM_max .ncols ()
5199
- n_f = PM_max .nrows ()
5200
5185
S_v = SymmetricGroup (n_v )
5201
5186
p_c = S_v .one ()
5202
- M_max = [max ([ PM_max [ i ][ j ] for i in range ( n_f )] ) for j in range (n_v )]
5203
- 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 )
5204
5189
for i in range (n_v ):
5205
5190
k = i
5206
5191
for j in range (i + 1 , n_v ):
@@ -5213,13 +5198,15 @@ def _palp_canonical_order(V, PM_max, permutations):
5213
5198
p_c = S_v ((1 + i , 1 + k ), check = False ) * p_c
5214
5199
# Create array of possible NFs.
5215
5200
permutations = [p_c * l [1 ] for l in permutations .values ()]
5216
- Vs = [(V .column_matrix ().with_permuted_columns (sig ).hermite_form (), sig )
5201
+ Vmatrix = V .column_matrix ()
5202
+ Vs = [(Vmatrix .with_permuted_columns (sig ).hermite_form (), sig )
5217
5203
for sig in permutations ]
5218
5204
Vmin = min (Vs , key = lambda x :x [0 ])
5219
- vertices = [V .module ()(_ ) for _ in Vmin [0 ].columns ()]
5205
+ Vmodule = V .module ()
5206
+ vertices = [Vmodule (_ ) for _ in Vmin [0 ].columns ()]
5220
5207
for v in vertices :
5221
5208
v .set_immutable ()
5222
- return (PointCollection (vertices , V . module () ), Vmin [1 ])
5209
+ return (PointCollection (vertices , Vmodule ), Vmin [1 ])
5223
5210
5224
5211
5225
5212
def _palp_convert_permutation (permutation ):
0 commit comments