Skip to content

Commit fe1791f

Browse files
committed
remove PGE and some listcomp
1 parent d61792b commit fe1791f

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

src/sage/geometry/lattice_polytope.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,11 +3188,6 @@ def _palp_PM_max(self, check=False):
31883188
sage: all(results) # long time
31893189
True
31903190
"""
3191-
def PGE(S, u, v):
3192-
if u == v:
3193-
return S.one()
3194-
return S((u, v), check=False)
3195-
31963191
PM = self.vertex_facet_pairing_matrix()
31973192
n_v = PM.ncols()
31983193
n_f = PM.nrows()
@@ -3202,27 +3197,23 @@ def PGE(S, u, v):
32023197
# and find all the ways of making the first row of PM_max
32033198
def index_of_max(iterable):
32043199
# 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]
32103201

32113202
n_s = 1
32123203
permutations = {0: [S_f.one(), S_v.one()]}
32133204
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))
32153206
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]
32173208
first_row = list(PM[0])
32183209

32193210
# Arrange other rows one by one and compare with first row
32203211
for k in range(1, n_f):
32213212
# Error for k == 1 already!
32223213
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))
32243215
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]
32263217
d = (PM[k, permutations[n_s][1](1) - 1]
32273218
- permutations[0][1](first_row)[0])
32283219
if d < 0:
@@ -3231,9 +3222,9 @@ def index_of_max(iterable):
32313222
continue
32323223
# otherwise:
32333224
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))
32353226
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) \
32373228
* permutations[n_s][1]
32383229
if d == 0:
32393230
d = (PM[k, permutations[n_s][1](i+1) - 1]
@@ -3244,7 +3235,7 @@ def index_of_max(iterable):
32443235
# This row is smaller than 1st row, so nothing to do
32453236
del permutations[n_s]
32463237
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]
32483239
if d == 0:
32493240
# This row is the same, so we have a symmetry!
32503241
n_s += 1
@@ -3293,10 +3284,11 @@ def index_of_max(iterable):
32933284
v0 = PM[permutations_bar[n_p][0](s+1) - 1, permutations_bar[n_p][1](1) - 1]
32943285
vj = PM[permutations_bar[n_p][0](s+1) - 1, permutations_bar[n_p][1](j+1) - 1]
32953286
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]
32973288
if ccf == 0:
32983289
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]
33003292
n_p += 1
33013293
ccf = 1
33023294
permutations_bar[n_p] = copy(permutations[k])
@@ -3308,14 +3300,16 @@ def index_of_max(iterable):
33083300
continue
33093301
elif d==0:
33103302
# 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]
33123305
n_p += 1
33133306
permutations_bar[n_p] = copy(permutations[k])
33143307
else:
33153308
# We found a greater maximal value for first entry.
33163309
# It becomes our new reference:
33173310
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]
33193313
# Forget previous work done
33203314
cf = 0
33213315
permutations_bar = {0:copy(permutations_bar[n_p])}
@@ -3340,7 +3334,7 @@ def index_of_max(iterable):
33403334
vc = PM[(permutations_bar[s][0])(l+1) - 1, (permutations_bar[s][1])(c+1) - 1]
33413335
vj = PM[(permutations_bar[s][0])(l+1) - 1, (permutations_bar[s][1])(j+1) - 1]
33423336
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]
33443338
if ccf == 0:
33453339
# Set reference and carry on to next permutation
33463340
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):
51885182
in 2-d lattice M, (1,3,2,4))
51895183
"""
51905184
n_v = PM_max.ncols()
5191-
n_f = PM_max.nrows()
51925185
S_v = SymmetricGroup(n_v)
51935186
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)
51965189
for i in range(n_v):
51975190
k = i
51985191
for j in range(i + 1, n_v):

0 commit comments

Comments
 (0)