@@ -3210,54 +3210,54 @@ def index_of_max(iterable):
3210
3210
return m
3211
3211
3212
3212
n_s = 1
3213
- permutations = {0 : [S_f .one (), S_v .one ()]}
3213
+ permutations_inv = {0 : [S_f .one (), S_v .one ()]}
3214
3214
for j in range (n_v ):
3215
3215
m = index_of_max ([PM [0 ][i ] for i in range (j , n_v )])
3216
3216
if m > 0 :
3217
- permutations [0 ][1 ] = PGE (S_v , j + 1 , m + j + 1 ) * permutations [ 0 ][ 1 ]
3217
+ permutations_inv [0 ][1 ] = permutations_inv [ 0 ][ 1 ] * PGE (S_v , j + 1 , m + j + 1 )
3218
3218
first_row = list (PM [0 ])
3219
3219
3220
3220
# Arrange other rows one by one and compare with first row
3221
3221
for k in range (1 , n_f ):
3222
3222
# Error for k == 1 already!
3223
- permutations [n_s ] = [S_f .one (), S_v .one ()]
3224
- m = index_of_max (PM [k , tuple ((permutations [n_s ][1 ]. inverse () )(j + 1 )- 1 for j in range (n_v ))])
3223
+ permutations_inv [n_s ] = [S_f .one (), S_v .one ()]
3224
+ m = index_of_max (PM [k , tuple ((permutations_inv [n_s ][1 ])(j + 1 )- 1 for j in range (n_v ))])
3225
3225
if m > 0 :
3226
- permutations [n_s ][1 ] = PGE (S_v , 1 , m + 1 ) * permutations [ n_s ][ 1 ]
3227
- d = (PM [k , (permutations [n_s ][1 ]. inverse () )(1 )- 1 ]
3228
- - permutations [0 ][1 ](first_row )[0 ])
3226
+ permutations_inv [n_s ][1 ] = permutations_inv [ n_s ][ 1 ] * PGE (S_v , 1 , m + 1 )
3227
+ d = (PM [k , (permutations_inv [n_s ][1 ])(1 )- 1 ]
3228
+ - ( permutations_inv [0 ][1 ]. inverse ()) (first_row )[0 ])
3229
3229
if d < 0 :
3230
3230
# The largest elt of this row is smaller than largest elt
3231
3231
# in 1st row, so nothing to do
3232
3232
continue
3233
3233
# otherwise:
3234
3234
for i in range (1 , n_v ):
3235
- m = index_of_max (PM [k , tuple ((permutations [n_s ][1 ]. inverse () )(j + 1 )- 1 for j in range (i ,n_v ))])
3235
+ m = index_of_max (PM [k , tuple ((permutations_inv [n_s ][1 ])(j + 1 )- 1 for j in range (i ,n_v ))])
3236
3236
if m > 0 :
3237
- permutations [n_s ][1 ] = PGE ( S_v , i + 1 , m + i + 1 ) \
3238
- * permutations [ n_s ][ 1 ]
3237
+ permutations_inv [n_s ][1 ] = permutations_inv [ n_s ][ 1 ] \
3238
+ * PGE ( S_v , i + 1 , m + i + 1 )
3239
3239
if d == 0 :
3240
- d = (PM [k , (permutations [n_s ][1 ]. inverse () )(i + 1 )- 1 ]
3241
- - permutations [0 ][1 ](first_row )[i ])
3240
+ d = (PM [k , (permutations_inv [n_s ][1 ])(i + 1 )- 1 ]
3241
+ - ( permutations_inv [0 ][1 ]. inverse ()) (first_row )[i ])
3242
3242
if d < 0 :
3243
3243
break
3244
3244
if d < 0 :
3245
3245
# This row is smaller than 1st row, so nothing to do
3246
- del permutations [n_s ]
3246
+ del permutations_inv [n_s ]
3247
3247
continue
3248
- permutations [n_s ][0 ] = PGE (S_f , 1 , k + 1 ) * permutations [ n_s ][ 0 ]
3248
+ permutations_inv [n_s ][0 ] = permutations_inv [ n_s ][ 0 ] * PGE (S_f , 1 , k + 1 )
3249
3249
if d == 0 :
3250
3250
# This row is the same, so we have a symmetry!
3251
3251
n_s += 1
3252
3252
else :
3253
3253
# This row is larger, so it becomes the first row and
3254
3254
# the symmetries reset.
3255
3255
first_row = list (PM [k ])
3256
- permutations = {0 : permutations [n_s ]}
3256
+ permutations_inv = {0 : permutations_inv [n_s ]}
3257
3257
n_s = 1
3258
- permutations = {k :permutations [k ] for k in permutations if k < n_s }
3258
+ permutations_inv = {k :permutations_inv [k ] for k in permutations_inv if k < n_s }
3259
3259
3260
- b = tuple (PM [(permutations [0 ][0 ]. inverse ()) (1 )- 1 , (permutations [0 ][1 ]. inverse () )(j + 1 )- 1 ] for j in range (n_v ))
3260
+ b = tuple (PM [(permutations_inv [0 ][0 ]) (1 )- 1 , (permutations_inv [0 ][1 ])(j + 1 )- 1 ] for j in range (n_v ))
3261
3261
# Work out the restrictions the current permutations
3262
3262
# place on other permutations as a automorphisms
3263
3263
# of the first row
@@ -3275,7 +3275,7 @@ def index_of_max(iterable):
3275
3275
# We determine the other rows of PM_max in turn by use of perms and
3276
3276
# aut on previous rows.
3277
3277
for l in range (1 , n_f - 1 ):
3278
- n_s = len (permutations )
3278
+ n_s = len (permutations_inv )
3279
3279
n_s_bar = n_s
3280
3280
cf = 0
3281
3281
l_r = [0 ]* n_v
@@ -3285,42 +3285,42 @@ def index_of_max(iterable):
3285
3285
# number of local permutations associated with current global
3286
3286
n_p = 0
3287
3287
ccf = cf
3288
- permutations_bar = {0 : copy (permutations [k ])}
3288
+ permutations_inv_bar = {0 : copy (permutations_inv [k ])}
3289
3289
# We look for the line with the maximal entry in the first
3290
3290
# subsymmetry block, i.e. we are allowed to swap elements
3291
3291
# between 0 and S(0)
3292
3292
for s in range (l , n_f ):
3293
3293
for j in range (1 , S [0 ]):
3294
- v = tuple (PM [(permutations_bar [n_p ][0 ]. inverse ()) (s + 1 )- 1 , (permutations_bar [n_p ][1 ]. inverse () )(j + 1 )- 1 ] for j in range (n_v ))
3294
+ v = tuple (PM [(permutations_inv_bar [n_p ][0 ]) (s + 1 )- 1 , (permutations_inv_bar [n_p ][1 ])(j + 1 )- 1 ] for j in range (n_v ))
3295
3295
if v [0 ] < v [j ]:
3296
- permutations_bar [n_p ][1 ] = PGE (S_v , 1 , j + 1 ) * permutations_bar [ n_p ][ 1 ]
3296
+ permutations_inv_bar [n_p ][1 ] = permutations_inv_bar [ n_p ][ 1 ] * PGE (S_v , 1 , j + 1 )
3297
3297
if ccf == 0 :
3298
- l_r [0 ] = PM [(permutations_bar [n_p ][0 ]. inverse ()) (s + 1 )- 1 , (permutations_bar [n_p ][1 ]. inverse () )(1 )- 1 ]
3299
- permutations_bar [n_p ][0 ] = PGE (S_f , l + 1 , s + 1 ) * permutations_bar [ n_p ][ 0 ]
3298
+ l_r [0 ] = PM [(permutations_inv_bar [n_p ][0 ]) (s + 1 )- 1 , (permutations_inv_bar [n_p ][1 ])(1 )- 1 ]
3299
+ permutations_inv_bar [n_p ][0 ] = permutations_inv_bar [ n_p ][ 0 ] * PGE (S_f , l + 1 , s + 1 )
3300
3300
n_p += 1
3301
3301
ccf = 1
3302
- permutations_bar [n_p ] = copy (permutations [k ])
3302
+ permutations_inv_bar [n_p ] = copy (permutations_inv [k ])
3303
3303
else :
3304
- d1 = PM [(permutations_bar [n_p ][0 ]. inverse ()) (s + 1 )- 1 , (permutations_bar [n_p ][1 ]. inverse () )(1 )- 1 ]
3304
+ d1 = PM [(permutations_inv_bar [n_p ][0 ]) (s + 1 )- 1 , (permutations_inv_bar [n_p ][1 ])(1 )- 1 ]
3305
3305
d = d1 - l_r [0 ]
3306
3306
if d < 0 :
3307
3307
# We move to the next line
3308
3308
continue
3309
3309
elif d == 0 :
3310
3310
# Maximal values agree, so possible symmetry
3311
- permutations_bar [n_p ][0 ] = PGE (S_f , l + 1 , s + 1 ) * permutations_bar [ n_p ][ 0 ]
3311
+ permutations_inv_bar [n_p ][0 ] = permutations_inv_bar [ n_p ][ 0 ] * PGE (S_f , l + 1 , s + 1 )
3312
3312
n_p += 1
3313
- permutations_bar [n_p ] = copy (permutations [k ])
3313
+ permutations_inv_bar [n_p ] = copy (permutations_inv [k ])
3314
3314
else :
3315
3315
# We found a greater maximal value for first entry.
3316
3316
# It becomes our new reference:
3317
3317
l_r [0 ] = d1
3318
- permutations_bar [n_p ][0 ] = PGE (S_f , l + 1 , s + 1 ) * permutations_bar [ n_p ][ 0 ]
3318
+ permutations_inv_bar [n_p ][0 ] = permutations_inv_bar [ n_p ][ 0 ] * PGE (S_f , l + 1 , s + 1 )
3319
3319
# Forget previous work done
3320
3320
cf = 0
3321
- permutations_bar = {0 :copy (permutations_bar [n_p ])}
3321
+ permutations_inv_bar = {0 :copy (permutations_inv_bar [n_p ])}
3322
3322
n_p = 1
3323
- permutations_bar [n_p ] = copy (permutations [k ])
3323
+ permutations_inv_bar [n_p ] = copy (permutations_inv [k ])
3324
3324
n_s = k + 1
3325
3325
# Check if the permutations found just now work
3326
3326
# with other elements
@@ -3337,20 +3337,20 @@ def index_of_max(iterable):
3337
3337
s -= 1
3338
3338
# Find the largest value in this symmetry block
3339
3339
for j in range (c + 1 , h ):
3340
- v = tuple (PM [(permutations_bar [s ][0 ]. inverse ()) (l + 1 )- 1 , (permutations_bar [s ][1 ]. inverse () )(j + 1 )- 1 ] for j in range (n_v ))
3340
+ v = tuple (PM [(permutations_inv_bar [s ][0 ]) (l + 1 )- 1 , (permutations_inv_bar [s ][1 ])(j + 1 )- 1 ] for j in range (n_v ))
3341
3341
if (v [c ] < v [j ]):
3342
- permutations_bar [s ][1 ] = PGE (S_v , c + 1 , j + 1 ) * permutations_bar [ s ][ 1 ]
3342
+ permutations_inv_bar [s ][1 ] = permutations_inv_bar [ s ][ 1 ] * PGE (S_v , c + 1 , j + 1 )
3343
3343
if ccf == 0 :
3344
3344
# Set reference and carry on to next permutation
3345
- l_r [c ] = PM [(permutations_bar [s ][0 ]. inverse ()) (l + 1 )- 1 , (permutations_bar [s ][1 ]. inverse () )(c + 1 )- 1 ]
3345
+ l_r [c ] = PM [(permutations_inv_bar [s ][0 ]) (l + 1 )- 1 , (permutations_inv_bar [s ][1 ])(c + 1 )- 1 ]
3346
3346
ccf = 1
3347
3347
else :
3348
- d1 = PM [(permutations_bar [s ][0 ]. inverse ()) (l + 1 )- 1 , (permutations_bar [s ][1 ]. inverse () )(c + 1 )- 1 ]
3348
+ d1 = PM [(permutations_inv_bar [s ][0 ]) (l + 1 )- 1 , (permutations_inv_bar [s ][1 ])(c + 1 )- 1 ]
3349
3349
d = d1 - l_r [c ]
3350
3350
if d < 0 :
3351
3351
n_p -= 1
3352
3352
if s < n_p :
3353
- permutations_bar [s ] = copy (permutations_bar [n_p ])
3353
+ permutations_inv_bar [s ] = copy (permutations_inv_bar [n_p ])
3354
3354
elif d > 0 :
3355
3355
# The current case leads to a smaller matrix,
3356
3356
# hence this case becomes our new reference
@@ -3360,21 +3360,21 @@ def index_of_max(iterable):
3360
3360
n_s = k + 1
3361
3361
# Update permutations
3362
3362
if (n_s - 1 ) > k :
3363
- permutations [k ] = copy (permutations [n_s - 1 ])
3363
+ permutations_inv [k ] = copy (permutations_inv [n_s - 1 ])
3364
3364
n_s -= 1
3365
3365
for s in range (n_p ):
3366
- permutations [n_s ] = copy (permutations_bar [s ])
3366
+ permutations_inv [n_s ] = copy (permutations_inv_bar [s ])
3367
3367
n_s += 1
3368
3368
cf = n_s
3369
- permutations = {k : permutations [k ] for k in permutations if k < n_s }
3369
+ permutations_inv = {k : permutations_inv [k ] for k in permutations_inv if k < n_s }
3370
3370
# If the automorphisms are not already completely restricted,
3371
3371
# update them
3372
3372
if S != list (range (1 , n_v + 1 )):
3373
3373
# Take the old automorphisms and update by
3374
3374
# the restrictions the last worked out
3375
3375
# row imposes.
3376
3376
c = 0
3377
- M = tuple (PM [(permutations [0 ][0 ]. inverse ()) (l + 1 )- 1 , (permutations [0 ][1 ]. inverse () )(j + 1 )- 1 ] for j in range (n_v ))
3377
+ M = tuple (PM [(permutations_inv [0 ][0 ]) (l + 1 )- 1 , (permutations_inv [0 ][1 ])(j + 1 )- 1 ] for j in range (n_v ))
3378
3378
while c < n_v :
3379
3379
s = S [c ] + 1
3380
3380
S [c ] = c + 1
@@ -3387,9 +3387,12 @@ def index_of_max(iterable):
3387
3387
S [c ] = c + 1
3388
3388
c += 1
3389
3389
# Now we have the perms, we construct PM_max using one of them
3390
- PM_max = PM .with_permuted_rows_and_columns (* permutations [0 ])
3390
+ PM_max = PM .with_permuted_rows_and_columns (permutations_inv [0 ][ 0 ]. inverse (), permutations_inv [ 0 ][ 1 ]. inverse () )
3391
3391
if check :
3392
- return (PM_max , permutations )
3392
+ for p in permutations_inv .keys ():
3393
+ permutaiton_inv [p ][0 ] = permutaiton_inv [p ][0 ].inverse ()
3394
+ permutaiton_inv [p ][1 ] = permutaiton_inv [p ][1 ].inverse ()
3395
+ return (PM_max , permutations_inv )
3393
3396
else :
3394
3397
return PM_max
3395
3398
0 commit comments