Skip to content

Commit

Permalink
Trac #34783: various details in combinat/
Browse files Browse the repository at this point in the history
about E271 and E272 pycodestyle warnings

URL: https://trac.sagemath.org/34783
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Dec 22, 2022
2 parents 33fa871 + b6d91e4 commit 75bedf9
Show file tree
Hide file tree
Showing 22 changed files with 182 additions and 189 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=03fa7a341ddf380aa4fe54a85b0c41debd2ffe7e
md5=6fdfcb62364de0e8c8d57f5d3a38c909
cksum=3919137984
sha1=88ae976578786fa200bf86cf01ecfdb8432005e1
md5=586346fa566bd96e98f1e7d972c41699
cksum=3389588783
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7819a59980b78950a0eb4aa18c529efa380d687b
d5aad9b8b0fe53109085c2a490e487386e430670
4 changes: 2 additions & 2 deletions src/sage/combinat/cluster_algebra_quiver/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ def __init__(self, data, frozen=None, user_labels=None):
else:
self.__init__( mutation_type.standard_quiver() )
elif len(data) == 3 and isinstance(data[0], str):
if (data[0] == 'F' and data[1] == 4 and data[2] == [2,1]) or (data[0] == 'G' and data[1] == 2 and data[2] == [3,1]):
if (data[0] == 'F' and data[1] == 4 and data[2] == [2,1]) or (data[0] == 'G' and data[1] == 2 and data[2] == [3,1]):
quiv = ClusterQuiver( QuiverMutationType_Irreducible( data[0], data[1], tuple(data[2]) )._digraph )
quiv._mutation_type = mutation_type
self.__init__( quiv )
elif (data[0] == 'F' and data[1] == 4 and data[2] == (2,1) ) or (data[0] == 'G' and data[1] == 2 and data[2] == (3,1) ):
elif (data[0] == 'F' and data[1] == 4 and data[2] == (2,1) ) or (data[0] == 'G' and data[1] == 2 and data[2] == (3,1) ):
quiv = ClusterQuiver( QuiverMutationType_Irreducible( data[0], data[1], data[2] )._digraph )
quiv._mutation_type = mutation_type
self.__init__( quiv )
Expand Down
78 changes: 40 additions & 38 deletions src/sage/combinat/composition_tableau.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
- Chris Berg, Jeff Ferreira (2012-9): Initial version
"""

from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets
from sage.sets.non_negative_integers import NonNegativeIntegers
from sage.sets.family import Family
Expand Down Expand Up @@ -101,21 +100,21 @@ def __init__(self, parent, t):

# Verify rows weakly decrease from left to right
for row in t:
if any(row[i] < row[i+1] for i in range(len(row)-1)):
if any(row[i] < row[i + 1] for i in range(len(row) - 1)):
raise ValueError("rows must weakly decrease from left to right")

# Verify leftmost column strictly increases from top to bottom
first_col = [row[0] for row in t if t!=[[]]]
if any(first_col[i] >= first_col[i+1] for i in range(len(t)-1)):
first_col = [row[0] for row in t if t != [[]]]
if any(first_col[i] >= first_col[i + 1] for i in range(len(t) - 1)):
raise ValueError("leftmost column must strictly increase from top to bottom")

# Verify triple condition
l = len(t)
m = max([len(r) for r in t] + [0])
TT = [row+[0]*(m-len(row)) for row in t]
for i in range(l):
for j in range(i+1,l):
for k in range(1,m):
for j in range(i+1, l):
for k in range(1, m):
if TT[j][k] and TT[i][k] <= TT[j][k] <= TT[i][k-1]:
raise ValueError("triple condition must be satisfied")

Expand Down Expand Up @@ -214,10 +213,9 @@ def descent_set(self):
"""
cols = {}
for row in self:
for (col,i) in enumerate(row):
for col, i in enumerate(row):
cols[i] = col
des_set = sorted([i for i in cols if i+1 in cols and cols[i+1] >= cols[i]])
return des_set
return sorted(i for i in cols if i + 1 in cols and cols[i + 1] >= cols[i])

def descent_composition(self):
r"""
Expand Down Expand Up @@ -256,7 +254,7 @@ def shape_partition(self):
sage: CompositionTableau([[2,1],[3],[4]]).shape_partition()
[2, 1, 1]
"""
return Partition(sorted([len(row) for row in self], reverse=True))
return Partition(sorted((len(row) for row in self), reverse=True))

def is_standard(self):
r"""
Expand All @@ -270,9 +268,10 @@ def is_standard(self):
sage: CompositionTableau([[2,1],[3],[4]]).is_standard()
True
"""
entries = sum(self,[])
entries = sum(self, [])
return sorted(entries) == list(range(1, self.size() + 1))


class CompositionTableaux(UniqueRepresentation, Parent):
r"""
Composition tableaux.
Expand Down Expand Up @@ -513,12 +512,13 @@ def __contains__(self, T):
m = max([len(r) for r in T] + [0])
TT = [row+[0]*(m-len(row)) for row in T]
for i in range(l):
for j in range(i+1,l):
for k in range(1,m):
for j in range(i+1, l):
for k in range(1, m):
if TT[j][k] != 0 and TT[j][k] >= TT[i][k] and TT[j][k] <= TT[i][k-1]:
return False
return True


class CompositionTableaux_all(CompositionTableaux, DisjointUnionEnumeratedSets):
r"""
All composition tableaux.
Expand All @@ -535,8 +535,8 @@ def __init__(self, max_entry=None):
self.max_entry = max_entry
CT_n = lambda n: CompositionTableaux_size(n, max_entry)
DisjointUnionEnumeratedSets.__init__(self,
Family(NonNegativeIntegers(), CT_n),
facade=True, keepkey = False)
Family(NonNegativeIntegers(), CT_n),
facade=True, keepkey=False)

def _repr_(self):
r"""
Expand All @@ -549,7 +549,7 @@ def _repr_(self):
Composition Tableaux
"""
if self.max_entry is not None:
return "Composition tableaux with maximum entry %s"%str(self.max_entry)
return f"Composition tableaux with maximum entry {self.max_entry}"
return "Composition Tableaux"

def an_element(self):
Expand All @@ -564,6 +564,7 @@ def an_element(self):
"""
return self.element_class(self, [[1, 1], [2]])


class CompositionTableaux_size(CompositionTableaux):
r"""
Composition tableaux of a fixed size `n`.
Expand Down Expand Up @@ -601,7 +602,7 @@ def __contains__(self, x):
sage: [[1],[2,2]] in CompositionTableaux(4)
False
"""
return CompositionTableaux.__contains__(self, x) and sum(map(len,x)) == self.size
return CompositionTableaux.__contains__(self, x) and sum(map(len, x)) == self.size

def __iter__(self):
r"""
Expand Down Expand Up @@ -632,7 +633,7 @@ def __iter__(self):
True
"""
for comp in Compositions(self.size):
for T in CompositionTableaux_shape(comp,self.max_entry):
for T in CompositionTableaux_shape(comp, self.max_entry):
yield self.element_class(self, T)

def _repr_(self):
Expand Down Expand Up @@ -661,9 +662,9 @@ def _an_element_(self):
if self.size == 0:
return self.element_class(self, [])
if self.size == 1:
return self.element_class(self,[[1]])
return self.element_class(self, [[1]])
return self.element_class(self, [[1] * (self.size - 1), [2]])

return self.element_class(self, [[1]*(self.size-1),[2]])

class CompositionTableaux_shape(CompositionTableaux):
r"""
Expand All @@ -675,7 +676,7 @@ class CompositionTableaux_shape(CompositionTableaux):
- ``max_entry`` -- a nonnegative integer. This keyword argument defaults
to the size of ``comp``.
"""
def __init__(self, comp, max_entry=None):
def __init__(self, comp, max_entry=None):
"""
Initialize ``self``.
Expand Down Expand Up @@ -753,7 +754,7 @@ def an_element(self):
"""
if self.shape == []:
return self.element_class(self, [])
t = [[i]*len for (i,len) in enumerate(self.shape,start=1)]
t = [[i] * len for i, len in enumerate(self.shape, start=1)]
return self.element_class(self, t)


Expand All @@ -774,14 +775,14 @@ def __init__(self, shape, max_entry=None):
"""
self._shape = shape
self._n = sum(shape)
self._initial_data = [ [None]*s for s in shape ]
self._initial_data = [[None] * s for s in shape]
if max_entry is None:
max_entry=sum(shape)
self.max_entry=max_entry
max_entry = sum(shape)
self.max_entry = max_entry

# The ending position will be at the lowest box which is farthest right
ending_row = len(shape)-1
ending_col = shape[-1]-1
ending_row = len(shape) - 1
ending_col = shape[-1] - 1
self._ending_position = (ending_row, ending_col)

# Get the highest box that is farthest left
Expand Down Expand Up @@ -819,26 +820,27 @@ def _rec(self, obj, state):
new_state = self.get_next_pos(i, j)
yld = bool(new_state is None)

for k in range(1,self.max_entry +1):
#We check to make sure that k does not violate the rule weak decrease in rows
if j!=0 and obj[i][j-1] < k:
for k in range(1, self.max_entry + 1):
# We check to make sure that k does not violate the rule weak decrease in rows
if j != 0 and obj[i][j - 1] < k:
continue

#We check to make sure that k does not violate strict increase in first column
if j == 0 and i != 0 and k <= obj[i-1][j]:
# We check to make sure that k does not violate strict increase in first column
if j == 0 and i != 0 and k <= obj[i - 1][j]:
continue

#We check to make sure that k does not violate the Triple Rule
# We check to make sure that k does not violate the Triple Rule
if j != 0 and i != 0 and any(k == obj_copy[m][j] for m in range(i)):
continue
if j != 0 and i != 0 and any(obj_copy[m][j] < k and k <= obj_copy[m][j-1] for m in range(i)):
if j != 0 and i != 0 and any(obj_copy[m][j] < k and k <= obj_copy[m][j - 1]
for m in range(i)):
continue

#Fill in the in the i,j box with k
# Fill in the in the i,j box with k
obj[i][j] = k
obj_copy[i][j] = k

#Yield the object
# Yield the object
yield copy.deepcopy(obj), new_state, yld

def get_next_pos(self, ii, jj):
Expand All @@ -854,8 +856,8 @@ def get_next_pos(self, ii, jj):
if (ii, jj) == self._ending_position:
return None

for j in range(jj+1, self._shape[ii]):
for j in range(jj + 1, self._shape[ii]):
if self._shape[ii] >= j:
return ii, j

return ii+1, 0
return ii + 1, 0
20 changes: 9 additions & 11 deletions src/sage/combinat/crystals/alcove_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def _latex_(self):
sage: C([1,2])._latex_()
[(\alpha_{1} + \alpha_{2}, 0), (\alpha_{1}, 0)]
"""
return [ (latex(i.root),i.height) for i in self.value ]
return [(latex(i.root), i.height) for i in self.value]

@cached_in_parent_method
def integer_sequence(self):
Expand Down Expand Up @@ -830,13 +830,12 @@ def _folding_data(self, i):
else:
# NOTE: we assume J is sorted by order on Element of RootsWithHeight

for k in range(max_height_Beta):
for k in range(max_height_Beta):
x = R(Beta, k)
if x <= J[0]:
signs[x] = self._sign(Beta)

for j in range( len(J) ):

for j in range(len(J)):
Beta = Beta.reflection(J[j].root)
sign_Beta = self._sign(Beta)
max_height_Beta = weight.scalar(
Expand Down Expand Up @@ -914,22 +913,21 @@ def e(self, i):
if ( (not finite_cartan_type or i!=0) and m_index < len(gi)-1 # alpha_i is a simple root
) or KR_test:


J.remove(positions[m_index])
if m_index+1 < len(positions): # if m_index+1 != 'infinity'
# i.e. positions[m_index+1] makes sense
J.append(positions[m_index+1])
return_value = Parent ( tuple( sorted(J) ) )
J.append(positions[m_index + 1])
return_value = Parent(tuple(sorted(J)))

# we attach to each admissible sequence a list
# which encodes a path (via root operators) from the () generator
# to the admissible sequence
# this is useful for investing the crystal

try:
return_value.i_string = self.i_string + [['e',i]]
return_value.i_string = self.i_string + [['e', i]]
except AttributeError:
return_value.i_string = [['e',i]]
return_value.i_string = [['e', i]]

return return_value
else:
Expand Down Expand Up @@ -1053,9 +1051,9 @@ def f(self, i):
# which encodes a path (via root operators) from the generator ()

try:
return_value.i_string = self.i_string + [['f',i]]
return_value.i_string = self.i_string + [['f', i]]
except AttributeError:
return_value.i_string = [['f',i]]
return_value.i_string = [['f', i]]

return return_value
else:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/designs/bibd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ def _get_r_s_t_u(v):
s = r//150
x = r%150

if x == 0:
if x == 0:
t,u = 30*s-5, 25
elif x == 1:
t,u = 30*s-5, 26
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/designs/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@ def QDM_57_9_1_1_8():
M = [[B[x] for x in R] for R in M] # replacing [0,..,8] by the elements of B
M.append([0]*9)

return G(57), M
return G(57), M

# Quasi-difference matrices
#
Expand Down
3 changes: 1 addition & 2 deletions src/sage/combinat/designs/incidence_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ def __init__(self, points=None, blocks=None, incidence_matrix=None,
assert blocks is None, "'blocks' cannot be defined when 'points' is a matrix"
incidence_matrix = points
points = blocks = None
elif (points is not None and
blocks is None):
elif points is not None and blocks is None:
blocks = points
points = set().union(*blocks)
if points:
Expand Down
Loading

0 comments on commit 75bedf9

Please sign in to comment.